xxxxxxxxxx
let starObj;
let bgAlpha = 10;
let bgRot = 100;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
noStroke();
starObj = new starPoints();
}
function draw() {
blendMode(BLEND);
background(0, bgAlpha);
translate(width / 2, height / 2);
rotate(frameCount / bgRot);
for (let d = 0; d < 12; d++) {
rotate(radians(30));
fill(d * 30, 100, 100, 40);
blendMode(SCREEN);
drawStar(d, starObj);
}
let pads = navigator.getGamepads();
let pad0 = pads[0];
if (pad0) {
updateStatus(pad0, starObj);
} else {
starObj.x = mouseX - width / 2;
starObj.y = mouseY - height / 2;
}
}
function drawStar(d, obj) {
push();
translate(obj.x, obj.y);
let rotVec;
if (d % 2 !== 0) {
rotVec = 1;
} else {
rotVec = -1;
}
rotate(frameCount / obj.speed * rotVec);
scale(obj.scale);
beginShape();
for (let i = 0; i < obj.ptArr.length; i++) {
vertex(obj.ptArr[i].px, obj.ptArr[i].py);
}
endShape();
pop();
}
function updateStatus(pad, obj) {
obj.x = map(pad.axes[0], -0.9, 0.9, -width / 2, width / 2);
obj.y = map(pad.axes[1], -0.9, 0.9, -height / 2, height / 2);
obj.speed = map(pad.buttons[4].value, 0, 1, 80, 8);
obj.scale = map(pad.buttons[7].value, 0, 1, 1, 20);
bgAlpha = map(pad.buttons[0].value, 0, 1, 10, 0.1);
bgRot = map(pad.buttons[5].value, 0, 1, 100, 20);
return;
}
class starPoints {
constructor() {
this.x = 0;
this.y = 0;
this.rad = 15;
this.scale = 1;
this.speed = 1000;
this.ptArr = [];
let ptflg;
for (let i = 0; i < 360; i += 36) {
if (i % 72 !== 0) {
ptflg = .38;
} else {
ptflg = 1;
}
this.ptArr.push({
px: cos(radians(i)) * this.rad * ptflg,
py: sin(radians(i)) * this.rad * ptflg
})
}
}
}