配列を使って沢山の図形を動かす
float [] x = new float[500]; float [] y = new float[500]; float [] vx = new float[500]; float [] vy = new float[500]; void setup() { size(400, 400); colorMode(HSB, 360, 100, 100, 100); for (int i = 0; i < x.length; i++) { x[i] = random(width); y[i] = random(height); vx[i] = random(1, 3); vy[i] = random(1, 3); } } void draw() { background(255); for (int i = 0; i < x.length; i++) { rect(x[i], y[i], 10, 10); } } void keyPressed(){ if(keyCode == ENTER){ saveFrame("image-####.png"); } }
Copy