Guest User

colored_gears

a guest
Aug 14th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | Source Code | 0 0
  1. // TiTi - 17 Aug 2021
  2. int phase=0;
  3. float time=0, hue_step=256/float(14);
  4.  
  5. void setup() {
  6.   size(800, 800);
  7.   strokeWeight(10);
  8.   frameRate(60);
  9.   noFill();
  10.   strokeCap(ROUND);
  11.   colorMode(HSB);
  12. }
  13.  
  14. void draw() {
  15.   background(176);
  16.   translate(width/2, height/2);
  17.   noFill();
  18.   stroke(160);
  19.   ellipse(0, 0, 650, 650);
  20.   if (phase>=14) rotate(TAU/3*ease((time+phase-14)*.5)-TAU/3);
  21.   else rotate(TAU/3*phase);
  22.  
  23.   pushMatrix();
  24.   fill(190);
  25.   noStroke();
  26.   for (int i=0; i<3; i++) {
  27.     center_part(i);
  28.     rotate(TAU/3);
  29.   }
  30.   popMatrix();
  31.   noFill();
  32.   stroke(176);
  33.  
  34.   for (int i=2; i>=0; i--) {
  35.     pushMatrix();
  36.     translate(0, -150);
  37.     if (phase<14 && i==0) rotate(-ease(time)*TAU/6);
  38.     rotate(PI-PI/6);
  39.     for (int j=0; j<6; j++) {
  40.       if (!(j==0&&i==1 || j==5&&i!=0)) {
  41.         pushMatrix();
  42.         int offset=min(phase, 14)*9;
  43.         if (i==0) offset++;
  44.         if (j==5&&i==0) fill(176);
  45.         else fill(((j+i*5+offset)*hue_step)%256, 70, 220);
  46.         peas();
  47.         popMatrix();
  48.       }
  49.       rotate(-TAU/6);
  50.     }
  51.     popMatrix();
  52.     rotate(TAU/3);
  53.   }
  54.  
  55.   time();
  56.   //if(frameCount<=50*16) saveFrame("frames2/####.png");
  57. }
  58.  
  59. void center_part(int a) {
  60.   //ellipse(0, -150, 280, 280);
  61.   pushMatrix();
  62.   translate(0, -150);
  63.   if (phase<14 && a==2) rotate(-ease(time)*TAU/6);
  64.   beginShape();
  65.   for (int i=0; i<6; i++) {
  66.     //offset of circle
  67.     float x_offset=cos(TAU/6*i)*280;
  68.     float y_offset=sin(TAU/6*i)*280;
  69.     for (int j=5; j>=-6; j--) {
  70.       //each "i" part takes 1/6 of the hexagon
  71.       float x = x_offset+cos(PI+float(j)/5*PI/12+PI/3*i)*190;
  72.       float y = y_offset+sin(PI+float(j)/5*PI/12+PI/3*i)*190;
  73.       vertex(x,y);
  74.       //point(x,y);
  75.     }
  76.   }
  77.   endShape(CLOSE);
  78.   popMatrix();
  79. }
  80.  
  81. void peas() {
  82.   beginShape();
  83.   float frac=PI/30;
  84.   for (int i=-5; i<=5; i++) vertex(cos(-HALF_PI+i*frac)*150, sin(-HALF_PI+i*frac)*150);
  85.   for (int i=-4; i<=4; i++) vertex(cos(HALF_PI+i*frac)*150, sin(HALF_PI+i*frac)*150-260);
  86.   endShape(CLOSE);
  87.   //ellipse(0, -120, 145, 40);
  88. }
  89.  
  90. void time() {
  91.   time += float(1)/50;
  92.   if (time>=1) {
  93.     time-=1;
  94.     phase++;
  95.     if (phase>=16) phase-=16;
  96.   }
  97. }
  98.  
  99. float ease(float x) {
  100.   if (x<.5) return pow(x, 3)*4;
  101.   return pow(x-1, 3)*4+1;
  102. }
Add Comment
Please, Sign In to add comment