Star[] stars = new Star[800]; float speed; int count = 10; float[] posX = new float[count]; float[] posY = new float[count]; float[] speedX = new float[count]; float[] speedY = new float[count]; float[] sizeW = new float[count]; float[] sizeH = new float[count]; int[] colors = new int[count]; float[] scale = new float[count]; float[] stroke = new float[count]; float[] rotate= new float[count]; void setup () { size (600, 600); //credit to codetrain star challenge for (int i=0; i < stars.length; i++) { stars[i] = new Star (); //colorful stars for (int j=0; j < posX.length; j++) { posX[j] = width/2; posY[j] = height/2; speedX[j] = random(-5, 5); speedY[j] = random(-5, 5); sizeW[j] = random(20, 25); sizeH[j] = random(20, 100); colors[j] = int(random(0, 255)); } } } void draw () { speed = map(mouseX, 2, width, 0, 20); background(0); for (int i = 0; i < stars.length; i++) { stars[i].update(); stars[i].show(); //fill(0, 26, 26); //rect(40, 40, width-100, height-100); for (int j = 0; j < posX.length; j++) { //update all positions posX[j] += speedX[j]; posY[j] += speedY[j]; sizeW[j] = random(-10,10); scale[j] += speedX[j]; colors[j] += color (random(50,100), random(0,10), random(0,50)); stroke[j] = color(random(250), random(0),random(50)); //draw all balls fill(colors[j]); ellipse(posX[j], posY[j], sizeW[j], sizeW[j]); if (posX[j] < 40+sizeW[j]/2 || posX[j] > (width-40)-sizeW[j]/2 ) { speedX[j] = -speedX[j]; } if (posY[j] < 40+sizeW[j]/2 || posY[j] > (height-40)-sizeW[j]/2) { speedY[j] = -speedY[j]; } } } if (frameCount < 300) { saveFrame("saveframe/ex4-######.png"); } else { exit(); } } class Star { float x; float y; float z; Star() { x = random(-width, width); y = random(-height, height); z = random(width); } void update () { z = z - 8; if (z < 1) { z = width; } } void show() { fill(255); noStroke(); float sx = map(x / z, 0, 1, 0, width); float sy = map(y / z, 0, 1, 0, height); float r = map(z, 0, width, 16, 0); ellipse(sx, sy, r, r); } }