Advertisement
xeromino

yingYang

Mar 29th, 2017
2,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. // based on code by Keith Peters: https://bit101.github.io/lab/dailies/170329.html
  2.  
  3. float theta;
  4. int frms = 180;
  5.  
  6. void setup() {
  7.   size(540, 540, P2D);
  8.   smooth(8);
  9. }
  10.  
  11. void draw() {
  12.   background(243, 134, 48);
  13.   // moving the axis to the center
  14.   translate(width/2, height/2);
  15.   // rotating around the center of the image
  16.   rotate(theta);
  17.   // calculate the time, the y-location of both arcs and their radii
  18.   float t = map(sin(theta), -1, 1, 0.15, 0.85);
  19.   float y0 = -200 + 200 * t;
  20.   float r0 = 400 * t;
  21.   float y1 = 200 - 200 * (1 - t);
  22.   float r1 = 400 * (1 - t);
  23.   //background circle  
  24.   fill(238);
  25.   noStroke();
  26.   ellipse(0, 0, 400, 400);
  27.   // black part  
  28.   fill(34);
  29.   arc(0, 0, 400, 400, PI / 2, TWO_PI-PI / 2);
  30.   arc(0, y0, r0, r0, -PI / 2, PI / 2);
  31.   // white part
  32.   pushMatrix();
  33.   translate(0, 400-r1);
  34.   rotate(PI);
  35.   fill(238);
  36.   arc(0, y1, r1, r1, -PI / 2, PI / 2);
  37.   popMatrix();
  38.   // white dot in black part
  39.   fill(238);
  40.   ellipse(0, y0, r0 * 0.1, r0 * 0.1);
  41.   // black dot in white part
  42.   fill(34);
  43.   ellipse(0, y1, r1 * 0.1, r1 * 0.1);
  44.   // calculating the angle of rotation
  45.   theta += TWO_PI/frms;
  46.   //if (frameCount<frms) saveFrame("image-###.gif");
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement