int xSize = 400; int ySize = 400; float xGrav = xSize/2; float yGrav = ySize/2; float gravity = 0.1; int totalParticles = 0; int maxParticles = 360; Particle[] particle; BImage myField; int counter = 0; void setup(){ size(xSize, ySize); background(255); //smooth(); ellipseMode(CENTER_DIAMETER); colorMode(RGB,255); myField = loadImage("field.gif"); brightToAlpha(myField); particle = new Particle[maxParticles]; } void loop(){ if (mousePressed && counter == 0 && totalParticles < maxParticles - 1){ particle[totalParticles] = new Particle(mouseX, mouseY, totalParticles, 10.0); totalParticles ++; counter ++; } if (mouseX != pmouseX && mouseY != pmouseY){ counter = 0; } background(255); //if (totalParticles > 1){ for (int i=0; i0; i--){ x[i] = x[i-1]; y[i] = y[i-1]; } x[0] += xv; y[0] += yv; myVel = findDistance(x[0], y[0], x[1], y[1]); myAngle = findAngle(x[0], y[0], x[1], y[1]); myDist = findDistance(x[0], y[0], mouseX, mouseY); } void applyGravity(){ gAngle = -radians(findAngle(x[0],y[0],xGrav,yGrav)); gxv = cos(gAngle) * gravity; gyv = sin(gAngle) * gravity; xv += gxv; yv += gyv; } void render(){ float mySize = abs(Q) * 20.0; image(myField, x[0] - mySize/2.0, y[0] - mySize/2.0, mySize, mySize); } } void brightToAlpha(BImage b){ b.format = RGBA; for(int i=0; i < b.pixels.length; i++) { b.pixels[i] = color(0,0,0,255 - brightness(b.pixels[i])); } } float findDistance(float x1, float y1, float x2, float y2){ float xd = x1 - x2; float yd = y1 - y2; float td = sqrt(xd * xd + yd * yd); return td; } float findAngle(float x1, float y1, float x2, float y2){ float xd = x1 - x2; float yd = y1 - y2; float t = atan2(yd,xd); float a = (180 + (-(180 * t) / PI)); return a; } //