ArrayList electron; void setup() { size(800, 800); background(255); //CREATE PARTICLES electron = new ArrayList(); } void draw() { background(0); //ARRAY GROWS for (int i = 0; i < electron.size ()-1; i++) { Electron e = (Electron) electron.get(i); //UPDATES & DISPLAYS PARTICLES e.update(); e.display(); } } void mousePressed() { electron.add(new Electron(mouseX, mouseY, random(55, 70))); electron.add(new Electron(mouseX, mouseY, random(65, 80))); } class Electron { float locX; float locY; int dirX = 1; int dirY = 1; float speedX = random(3, 6); float speedY = random(3, 6); float dia; Electron(float x, float y, float d) { locX = x; locY = y; dia = d; } void update() { locX += speedX*dirX; locY += speedY*dirY; //RIGHT if (locX > width-(dia/2)) { locX = width-(dia/2); speedX = random(3, 6); dirX = -1; } //LEFT if (locX < 0+(dia/2)) { locX = 0+(dia/2); speedX = random(3, 6); dirX = 1; } //BOTTOM if (locY > height-(dia/2)) { locY = height-(dia/2); speedY = random(3, 6); dirY = -1; } //TOP if (locY < 0+(dia/2)) { locY = 0+(dia/2); speedY = random(3, 6); dirY = 1; } if (dist(mouseX, mouseY, locX, locY) < 100) { dirX = -dirX; dirY = -dirY; } stroke(0,236,255); line(locX,locY,mouseX,mouseY); } void display() { //DRAW fill(255); stroke(0,236,255); ellipseMode(CENTER); ellipse(locX, locY, dia, dia); //DISPLAY CATALYST stroke(0); fill(0,236,255); //ellipseMode(CENTER); ellipse(mouseX,mouseY,80,80); //ELEMENT fill(0,100,100); textSize(15); text("ELEMENT",mouseX-27,mouseY); //ELECTRON fill(100,100,100); textSize(15); text("ELECTRON",locX-20,locY+10); } }