Guest User

Untitled

a guest
Nov 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. PVector p1;
  2. PVector p2;
  3. PVector V1 = new PVector(0,0);
  4. PVector V2 = new PVector(0,0);
  5. int S = 20;
  6.  
  7. void setup(){
  8. size(800,800,P3D);//<===This is using the 3D renderer
  9.  
  10. //noStroke(); //the sphere looks awful with stroke turned on.
  11. p1 = new PVector(width/2, height/2, 0);
  12. p2 = new PVector(width/2, height/2, 0);
  13. V1.add(PVector.random2D());
  14. V2.add(PVector.random2D());
  15. }
  16. void mouseWheel(MouseEvent e) {
  17. int size = 2;
  18. S += (e.getCount()* size);
  19. if (S < 0) {
  20. S = 5;
  21. }
  22. }
  23. void Limit() {
  24. if (p1.x > 800-S) {
  25. V1.mult(-1);
  26. } else if (p1.x < 0+S) {
  27. V1.mult(-1);
  28. } else if (p1.y < 0+S) {
  29. V1.mult(-1);
  30. } else if (p1.y > 800-S) {
  31. V1.mult(-1);
  32. } else if (p2.x > 800-S) {
  33. V2.mult(-1);
  34. } else if (p2.x < 0+S) {
  35. V2.mult(-1);
  36. } else if (p2.y < 0+S) {
  37. V2.mult(-1);
  38. } else if (p2.y > 800-S) {
  39. V2.mult(-1);
  40. }
  41. }
  42. void draw(){
  43. background(100);
  44. mouseWheel();
  45. Limit();
  46. /*
  47. p1.x = mouseX;
  48. p2.x = mouseX;
  49. p1.y = mouseY;
  50. p2.y = mouseY;
  51. */
  52. p1.z = S;
  53. p2.z = S;
  54. //the sphere is drawn at the origin so we need to move the origin to the location we want.
  55.  
  56. p1.add(V1);
  57. p2.add(V2);
  58. println(p1.z, p2.z);
  59.  
  60. pushMatrix();
  61. translate(p1.x, p1.y, p1.z);//move the origin to where we hant the sphere
  62. 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));
  63. sphere(50);
  64. popMatrix();
  65.  
  66. pushMatrix();
  67. translate(p2.x, p2.y, p2.z);
  68. 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));
  69. sphere(50);
  70. popMatrix();
  71.  
  72.  
  73.  
  74. }
Add Comment
Please, Sign In to add comment