xxxxxxxxxx
71
let max_planets = 2612;
let planets = [];
let bg; let fg; let star;
var fR = 30;
function Planet(x, y, vx, vy, sz, c) {
star =loadImage('illust3.png');
this.x = x;
this.y = y;
this.vx = vx; this.vy = vy;
this.sz = sz;
this.c = c;
this.move = function() { this.x += this.vx;
this.y += this.vy;
if (this.x<0 || this.x>windowWidth) this.x = windowWidth/2;
if (this.y<0 || this.y>windowHeight) this.y = windowHeight;
if (mouseIsPressed) {
var xdif = abs(this.x-mouseX);
var ydif = abs(this.y-mouseY);
if (xdif < 30 + random(-100, 100)) {
if (ydif < 30 + random(-100, 100)){
this.x=-30; this.y=-30;
}
}
image(star, mouseX+5, mouseY+5, star.width/3, star.height/3);
}
}
this.render = function() {
noStroke(); fill(this.c);
ellipse(this.x, this.y, this.sz, this.sz);
}
}
function setup() {
var move = random(-1.5,1.5);
createCanvas(windowWidth, windowHeight);
for (let i=0; i<max_planets; i++) {
planets[i] = new Planet(
random(0, windowWidth), random(0, windowHeight),
random(-2,2), random(-2,2), random(0.1,3,2), color(random(184, 255), 250));
}
bg = loadImage('illust1.png');
fg = loadImage('illust2.png');
}
function keyPressed(){
if(keyCode === LEFT_ARROW){
fR-=5;
print(fR);
}else if (keyCode === RIGHT_ARROW){
fR+=5;
print(fR);
} else if (keyCode === DOWN_ARROW) {
save('b612space.png');}
}
function draw() {
background(bg);
for (let i=0; i<max_planets; i++) { planets[i].move();
planets[i].render();
}
image(fg,0,windowHeight/5, fg.width/(1920/windowWidth), fg.height/(1080/height));
if (fR>5){
frameRate(fR);
}
}