// // // // // // applet size variables int xSize = 400; int ySize = 400; int xMid = xSize/2; int yMid = ySize/2; // gravity variables int xGrav = 0; int yGrav = 0; int zGrav = 0; float gxv; float gyv; float gzv; float gravity = 0.1; // camera variables float xMouse, yMouse; float rotationVar; float elevation, azimuth, twist, distance; int totalParticles = 0; int maxParticles = 720; Particle[] particle; BImage myField; boolean gravLines = false; boolean connections = false; boolean orbs = true; boolean axis = false; int counter = 0; void setup(){ size(xSize, ySize); //smooth(); background(255); colorMode(RGB,255); elevation = radians(15.0f); azimuth = radians(0.0f); distance = 150.0f; myField = loadImage("field.gif"); brightToAlpha(myField); particle = new Particle[maxParticles]; } void loop(){ background(205,212,215); doCamera(); if (mousePressed && counter == 0 && totalParticles < maxParticles - 1){ particle[totalParticles] = new Particle(mouseX - xMid, mouseY - yMid, sin(totalParticles/4.0) * 20.0, totalParticles, 1.0); totalParticles ++; counter ++; } if (mouseX != pmouseX && mouseY != pmouseY){ counter = 0; } for (int i=0; i PI) angle -= TWO_PI; if (angle < -PI) angle += TWO_PI; return angle; } void move(){ x += xv; y += yv; z += zv; } void render(){ mySize -= (mySize - (totalConnections + (255 - zDepth)/20.0)) * .2; push(); translate(x, y, z); zDepth = ((screenZ(0,0,0) * 100.0) - 99.0) * 500.0; rotateZ(azimuth); rotateX(-elevation); rotateY(twist); tint(zDepth * .4,zDepth * .9,zDepth * 1.0); //println(tempColor); image(myField, 0 - mySize/2.0, 0 - mySize/2.0, mySize, mySize); pop(); } } // create alpha for a bitmap by analyzing brightness (code by Ryan Alexander of Motion Theory) void brightToAlpha(BImage b){ b.format = RGBA; for(int i=0; i < b.pixels.length; i++) { b.pixels[i] = color(255,255,255,255 - brightness(b.pixels[i])); } } // find distance between 2 points in 2D space 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; } // find distance between 2 points in 3D space float findDistance(float x1, float y1, float z1, float x2, float y2, float z2){ float xd = x1 - x2; float yd = y1 - y2; float zd = z1 - z2; float xyd = sqrt(xd * xd + yd * yd); float td = sqrt(zd * zd + xyd * xyd); return td; } // find angle in radians between 2 points in 2D space float findAngle(float x1, float y1, float x2, float y2){ float xd = x1 - x2; float yd = y1 - y2; float t = atan2(yd,xd); return t; } //