Skip to content

Instantly share code, notes, and snippets.

@pLabarta
Created April 18, 2021 14:18
Show Gist options
  • Save pLabarta/287e8b34d4c353dcc29f1a96faab5af0 to your computer and use it in GitHub Desktop.
Save pLabarta/287e8b34d4c353dcc29f1a96faab5af0 to your computer and use it in GitHub Desktop.
Clase 2
float clock = 0;
int moonCount = 20;
Moon [] moonList = new Moon[moonCount];
void setup() {
size(1600,900);
background(0);
frameRate(60);
for (int i = 0; i < moonCount; i++) {
moonList[i] = new Moon(random(1000), random(1)*4);
}
}
// Moon class
class Moon {
float offset, orbit;
Moon (float offsetnumber, float orbitnumber){
offset = offsetnumber;
orbit = orbitnumber;
}
}
// setup moons
void drawMoon(float clock, float offset, float orbit) {
// update moon position
float circleX = width/2;
float circleY = height/2;
float circleSize = 50;
circleSize = circleSize * (sin(clock + offset) + 1) + 50;
circleX = circleX + cos(clock + offset) * width/orbit/3 ;
circleY = circleY + sin(clock + offset) * height/orbit/3 ;
// draw moon
fill(100,60,(cos(clock) +1) * 100 +50 ,30);
noStroke();
ellipse(circleX, circleY,circleSize,circleSize);
}
void draw() {
// clear bg
fill(0,0,(cos(clock) +1) * 10 ,3);
rect(0,0,width,height);
//// draw earth
//fill(100,100,250);
//ellipse(width/2, height/2, 400,400);
// draw moons
for (Moon moon : moonList) {
drawMoon(clock,moon.offset,moon.orbit);
}
// update clock
clock = clock + 0.02;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment