Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PVector p1;
- PVector p2;
- PVector V1 = new PVector(0,0);
- PVector V2 = new PVector(0,0);
- int S = 20;
- void setup(){
- size(800,800,P3D);//<===This is using the 3D renderer
- //noStroke(); //the sphere looks awful with stroke turned on.
- p1 = new PVector(width/2, height/2, 0);
- p2 = new PVector(width/2, height/2, 0);
- V1.add(PVector.random2D());
- V2.add(PVector.random2D());
- }
- void mouseWheel(MouseEvent e) {
- int size = 2;
- S += (e.getCount()* size);
- if (S < 0) {
- S = 5;
- }
- }
- void Limit() {
- if (p1.x > 800-S) {
- V1.mult(-1);
- } else if (p1.x < 0+S) {
- V1.mult(-1);
- } else if (p1.y < 0+S) {
- V1.mult(-1);
- } else if (p1.y > 800-S) {
- V1.mult(-1);
- } else if (p2.x > 800-S) {
- V2.mult(-1);
- } else if (p2.x < 0+S) {
- V2.mult(-1);
- } else if (p2.y < 0+S) {
- V2.mult(-1);
- } else if (p2.y > 800-S) {
- V2.mult(-1);
- }
- }
- void draw(){
- background(100);
- mouseWheel();
- Limit();
- /*
- p1.x = mouseX;
- p2.x = mouseX;
- p1.y = mouseY;
- p2.y = mouseY;
- */
- p1.z = S;
- p2.z = S;
- //the sphere is drawn at the origin so we need to move the origin to the location we want.
- p1.add(V1);
- p2.add(V2);
- println(p1.z, p2.z);
- pushMatrix();
- translate(p1.x, p1.y, p1.z);//move the origin to where we hant the sphere
- fill(78+ 177*sin((float)frameCount*PI/frameRate) ,128 + 127*sin((float)frameCount*PI/frameRate), 128 + 127*sin((float)frameCount*PI/30),28 + 227*sin((float)frameCount*PI/frameRate));
- sphere(50);
- popMatrix();
- pushMatrix();
- translate(p2.x, p2.y, p2.z);
- fill(78+ 177*sin((float)frameCount*PI/frameRate) ,128 + 127*sin((float)frameCount*PI/frameRate), 128 + 127*sin((float)frameCount*PI/30),28 + 227*sin((float)frameCount*PI/frameRate));
- sphere(50);
- popMatrix();
- }
Add Comment
Please, Sign In to add comment