I’m really confused as to how I can add millis() to animation I’ve already made. If you run the code I have below, it shows yellow stars on a blue background, moving from side to side. What I want to do is to change it is to have the stars move from side to side, and then scale up 20% after 3 seconds, and then return to normal, and keep looping. Does anyone know how I can achieve this with the code I already have?
int startTime;
int unit = 40;
int count;
Module[] mods;
void setup (){
size (500, 500);
noStroke();
int wideCount = width / unit;
int highCount = height / unit;
count = wideCount * highCount;
mods = new Module[count];
int index = 0;
for (int y = 0; y < highCount; y++) {
for (int x = 0; x < wideCount; x++) {
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
}
}
}
void draw () {
background (#122e50);
for (Module mod : mods) {
mod.update();
mod.display();
}
}
class Module {
int xOffset;
int yOffset;
float x, y;
int unit;
int xDirection = 1;
int yDirection = 1;
float speed;
float scale;
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
xOffset = xOffsetTemp;
yOffset = yOffsetTemp;
x = xTemp;
y = yTemp;
speed = speedTemp;
unit = tempUnit;
scale=width/20;
}
void update() {
x = x + (speed * xDirection);
if (x >= unit || x <= 0) {
xDirection *= -1;
x = x + (1 * xDirection);
y = y + (1 * yDirection);
}
if (y >= unit || y <= 0) {
yDirection *= -1;
y = y + (1 * yDirection);
}
}
void display() {
blendMode(EXCLUSION);
fill (#FFF6DE);
star (xOffset + x, yOffset +y, 4, 9, 5);
}
}
void star (float x, float y, float radius1, float radius2, int npoints) {
float angle = PI / npoints;
float halfAngle = angle/2.0;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius2;
float sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a+halfAngle) * radius1;
sy = y + sin(a+halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}
void keyPressed() {
if (keyCode == ENTER) {
saveFrame("####.tif"); }
}