Final Code
// I got this code from open processing which was called rotate and was created by Jared Counts
PImage img;
/* Particle count. */ int particleCount = 5000; //can change the particle size to 9000 Particle[] particles = new Particle[particleCount+1];
float x =0; float y = 0; float fade=10; void setup() {
size(800, 600); smooth(); stroke(255); //noCursor();
fill(85, 255, 195, 50); noStroke(); img = loadImage("galaxy.jpg"); //image(img, 0, 0);
/* The particles are created. */ for (int x = particleCount; x >= 0; x--) { /* We call the particle function inside its class to set up a new particle. Each is positioned randomly. */ particles[x] = new Particle(); } background(0); } //background(102);
void draw() { //image(img, 0, 0); noStroke(); fill(0); rect(0, 0, width, height);
stroke(255); for (int i = particleCount; i >= 0; i--) { Particle particle = (Particle) particles[i]; particle.update(); particle.changeColour(); particle.drawMe(); //delete the draw me line } }
void keyPressed() {
if (key == 'r') {
img = loadImage("galaxy.jpg"); image(img, 0, 0); } //|| (key == 'R')) }
class Particle { float x; float y; float vx; float vy; float r, g, b; Particle() { x = random(10,width-10); y = random(10,height-10); r = random(10, 75); g = random(0, 200); b = random(200, 255); }
void update() { if (mousePressed) { int rx = mouseX; int ry = mouseY; float radius = dist(x,y,rx,ry); if (radius < 150) { float angle = atan2(y-ry,x-rx); vx -= (150 - radius) * 0.01 * cos(angle + (0.7 + 0.0005 * (150 - radius))); vy -= (150 - radius) * 0.01 * sin(angle + (0.7 + 0.0005 * (150 - radius))); } } /* x and y are increased by our velocities. This completes our formula c + r * cos(a) or sin(a), with vx/vy being the r * cos(a) or sin(a) */ x += vx; y += vy; /* The velocities are decreased by 3% to simulate friction. */ vx *= 0.97; vy *= 0.97; /* Boundary collision is calculated here. If the particle is beyond the boundary, its velocity is reversed and the particle is moved back into the main area. */ if (x > width-10) { vx *= -1; x = width-11; } if (x < 10) { vx *= -1; x = 11; } if (y > height-10) { vy *= -1; y = height-11; } if (y < 10) { vy *= -1; y = 11; } /* The particle is drawn. (int) is used because decimals for some reason makes the particle not draw for a lot of the time, resulting in a flicker. */ //point((int)x,(int)y); //highlight the top line } void changeColour() { b = 255*sin(vx); } void drawMe() { stroke(r, g, b); //point((int)x,(int)y); rect(x-2, y-2, 2, 2); //ellipse(x, y, 3, 3); } }














