Advertisement
andrewb

threebodydemo2.pde

Dec 16th, 2018
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. // The window size
  2. int winW = 600;
  3. int winH = 600;
  4.  
  5. // Angle starting point
  6. int angle = 0;
  7.  
  8. void settings() {
  9.   size(winW, winH, P3D);
  10. }
  11.  
  12. void setup() {  
  13.   strokeWeight(0);
  14.   noStroke();
  15. }
  16.  
  17. void draw() {
  18.   background(#ffffff);
  19.  
  20.   // Big blue ball
  21.   int diameter = 200;
  22.   float xcoord = (float(winW) / 2);
  23.   float ycoord = (float(winH) / 2);
  24.   fill(0, 0, 255);
  25.   ellipse(xcoord, ycoord, diameter, diameter);
  26.  
  27.   // Male the bar red
  28.   fill(255, 0, 0);
  29.  
  30.   // Line 1
  31.   int a1 = angle + 10;
  32.   float xcoord2 = sin(radians(a1)) * (diameter * -1) + xcoord;
  33.   float ycoord2 = cos(radians(a1)) * (diameter * -1) + ycoord;
  34.   float xcoord3 = sin(radians(a1)) * (diameter) + xcoord;
  35.   float ycoord3 = cos(radians(a1)) * (diameter) + ycoord;  
  36.  
  37.   // Line 2
  38.   int a2 = angle - 10;
  39.   float xcoord4 = sin(radians(a2)) * (diameter * -1) + xcoord;
  40.   float ycoord4 = cos(radians(a2)) * (diameter * -1) + ycoord;
  41.   float xcoord5 = sin(radians(a2)) * (diameter) + xcoord;
  42.   float ycoord5 = cos(radians(a2)) * (diameter) + ycoord;  
  43.  
  44.   // Spinning bar
  45.   quad(xcoord2, ycoord2, xcoord4, ycoord4, xcoord3, ycoord3, xcoord5, ycoord5);
  46.    
  47.   // Keeps track of the angle
  48.   angle+=1;
  49.   if (angle >= 360) {
  50.     angle = 0;
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement