Skip to content

Instantly share code, notes, and snippets.

@martoo6
Created March 14, 2019 18:48
Show Gist options
  • Save martoo6/e43b684b87d67be8f974ec2e2fe27036 to your computer and use it in GitHub Desktop.
Save martoo6/e43b684b87d67be8f974ec2e2fe27036 to your computer and use it in GitHub Desktop.
final int frames = 30;
void setup(){
size(500,500,P3D);
background(0);
}
void draw(){
background(0);
final int fc = frameCount;
final float t = map(fc, 0, frames, 0, 1) % 1;
pushMatrix();
translate(width/2, height/2, -100);
drawBalls(t);
pushMatrix();
rotateY(PI/2);
drawBalls(t);
popMatrix();
pushMatrix();
rotateX(PI/2);
drawBalls(t);
popMatrix();
popMatrix();
}
void drawBalls(float t){
noStroke();
fill(255);
final int balls = 12;
final int radius = 200;
final float step = TWO_PI/balls;
for(int i=0;i<balls;i++){
final float phi = map(t, 0, 1, 0, step) + step*i;
final float x = sin(phi)*radius;
final float y = cos(phi)*radius;
pushMatrix();
translate(x, y, 0);
sphere(10);
popMatrix();
}
}
@martoo6
Copy link
Author

martoo6 commented Mar 18, 2019

int frames = 120;

void setup(){
  size(500,500,P3D);
}

final color[] colors = {
  #1B4A66,
  #0894A1,
  #47AB6C,
  #F2B134,
  #ED553B
};

void draw(){
  background(15);
  final int fc = frameCount;
  final float t = map(fc, 0, frames, 0, 1) % 1;
  
  println(t);
  
  pushMatrix();
  translate(width/2, height/2, -100);
  
  pushMatrix();
  rotateY(PI*2 * t);
  drawBalls(t, 100, 2);
  popMatrix();
  
  pushMatrix();
  rotateX((-PI*2) * t);
  drawBalls(t, 150, 3);
  popMatrix();
  pushMatrix();
  rotateY(PI*2 * t);
  drawBalls(t, 200, 4);
  popMatrix();
  pushMatrix();
  rotateX((PI*2) * t);
  drawBalls(t, 250, 5);
  popMatrix();
  
  popMatrix();
}

void drawBalls(float t, float radius, int detail){
  sphereDetail(detail);
  noFill();
  final int balls = round(radius*0.1);
  final float step = TWO_PI/balls;
  for(int i=0;i<balls;i++){
    final float phi = map(t, 0, 1, 0, step) + step*i; 
    final float x = sin(phi)*radius;
    final float y = cos(phi)*radius;
    pushMatrix();
    translate(x, y, 0);
    float offset = map(t, 0, 1, 0, colors.length);
    for(int e=1;e<colors.length;e++){
      final float ee = (e + offset) % colors.length;
      stroke(colors[e], map(ee, 0, colors.length, 255, 0));
      sphere(ee*6);
    }
    popMatrix();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment