int num=1600; // number of stars Star[] stars = new Star[num]; void setup() { noStroke(); size(360, 360); ellipseMode(CENTER_RADIUS); for (int i = 0; i < num; i++){ stars[i] = new Star(random(width), random(height)); } } void loop() { background(0); for(int i = 0; i < num; i ++){ stars[i].update(); stars[i].paint(); } } class Star { float x, y; float starcolorr = random(0, 255); float starcolorg = random(0, 255); Star(float _xpos, float _ypos) { x = _xpos; y = _ypos; } void update() { float distance; float dx = mouseX - x; float dy = mouseY - y; distance = (float)Math.sqrt(dx*dx + dy*dy); // if (mousePressed){ if(distance<50) { if(distance<1){distance = 1;} x = x - (dx/distance)*2 + random(-2, 2); y = y - (dy/distance) + random (-2, 2); } // } x = x + random(-2, 2); y = y + random(-2, 2); if (x > width) {x = 0;} if (x < 0) {x = width;} if (y > height) {y = 0;} if (y < 0) {y = height;} } void paint() { stroke(starcolorr, starcolorg, 0); point(x, y); } }