// Variance int numBall = 20; Ball[] maru = new Ball[numBall]; int[][] iro = new int[numBall][3]; float[][] spd = new float[numBall][3]; float[][] pos = new float[numBall][3]; void setup() { size(400, 400); //window background(0, 0, 0); //black noStroke(); //lineless for (int i = 0; i < numBall; i++) { for (int j=0; j<3; j++ ) { iro[i][j] = (int)(random(1)*255); spd[i][j] = random(-1,1); pos[i][j] = 180*random(-1,1)+200; } maru[i] = new Ball(pos[i][0], pos[i][1], 20, spd[i][0], spd[i][1], iro[i]); } } void draw(){ fill(0,0,0); //clear color rect(0, 0, width, height); for (int i = 0; i < numBall; i++) { maru[i].move(width, height); maru[i].display(); } } class Ball { float px, py; //position float vx, vy; //velocity float dia; //diameter int[] col = {}; Ball(float x, float y, float d) { px = x; py = y; dia = d; } Ball(float x, float y, float d, int[] c) { px = x; py = y; dia = d; col = c; } Ball(float x, float y, float d, float sx, float sy, int[] c) { px = x; py = y; dia = d; vx = sx; vy = sy; col = c; } void display() { fill(col[0], col[1], col[2]); ellipse(px, py, dia, dia); } void display(int[] col) { fill(col[0], col[1], col[2]); ellipse(px, py, dia, dia); } void move(int w, int h) { int fx = 1; int fy = 1; if (px <= dia/2 || px >= w-dia/2 ) { fx *= -1; } if (py <= dia/2 || py >= h-dia/2 ) { fy *= -1; } vx *= fx; vy *= fy; px += vx; py += vy; } }