Twinkle[] twinkle = new Twinkle[10]; void setup() { size(640, 360); background(0); fill(0,0,0,0); frameRate(30); for(int i = 0; i < 10; i++) { twinkle[i] = new Twinkle(); } } void draw() { for(int i = 0; i < 10; i++) { twinkle[i].update(); } background(0); for(int i = 0; i < 10; i++) { twinkle[i].draw(); } } class Twinkle { private float[] lastX = new float[4]; private float[] lastY = new float[4]; int[] colorVal = new int[3]; public Twinkle() { lastX[0] = 320; lastY[0] = 180; lastX[1] = 320; lastY[1] = 180; lastX[2] = 320; lastY[2] = 180; lastX[3] = 320; lastY[3] = 180; colorVal[0] = (int)random(0, 255); colorVal[1] = (int)random(0, 255); colorVal[2] = (int)random(0, 255); } public void update() { float newX = lastX[3]; float newY = lastY[3]; float differenceX = random(-width / 4, width / 4); float differenceY = random(-height / 4, height / 4); if(abs(differenceX) < 1) { differenceX = 0; } if(abs(differenceY) < 1) { differenceY = 0; } newX += differenceX; newY += differenceY; newX = constrain(newX, 0, width); newY = constrain(newY, 0, height); lastX[0] = lastX[1]; lastY[0] = lastY[1]; lastX[1] = lastX[2]; lastY[1] = lastY[2]; lastX[2] = lastX[3]; lastY[2] = lastY[3]; lastX[3] = newX; lastY[3] = newY; } public void draw() { stroke(colorVal[0], colorVal[1], colorVal[2]); curve(lastX[0], lastY[0], lastX[1], lastY[1], lastX[2], lastY[2], lastX[3], lastY[3]); } }