Skip to content

Instantly share code, notes, and snippets.

@reuk
Created January 23, 2015 10:21
Show Gist options
  • Save reuk/49ad4a4df668d7d17b93 to your computer and use it in GitHub Desktop.
Save reuk/49ad4a4df668d7d17b93 to your computer and use it in GitHub Desktop.
void setup()
{
size(500, 500, P3D);
colorMode(RGB, 1);
frameRate(25);
logo = loadImage("logo.png");
logo.filter(INVERT);
}
void vertex(PVector p) {vertex(p.x, p.y, p.z);}
PImage logo;
final boolean RENDER = true;
final int ANIMATION_LENGTH = 80;
void draw()
{
final int FRAME = (frameCount - 1) % ANIMATION_LENGTH;
final float TIME = FRAME / float (ANIMATION_LENGTH);
drawAtTime (TIME);
camera();
image(logo, width - logo.width, height - logo.height);
if (RENDER)
{
saveFrame("###-out.png");
if (frameCount == ANIMATION_LENGTH)
exit();
}
}
PVector sphere_point(float offset, float rot)
{
float int_angle = atan(offset);
return new PVector(sin(rot) * cos(int_angle), sin(int_angle), cos(rot) * cos(int_angle));
}
void frac_point(int i, float RANGE, int NUM_POINTS)
{
vertex(PVector.mult(sphere_point(i * RANGE * 2 / NUM_POINTS - RANGE, i * radians(137.5)), width * 0.4));
}
void drawAtTime (float TIME)
{
background(0);
strokeWeight(2);
fill(0);
translate(width / 2, height / 2);
rotateX(-1);
rotateY(TIME * TWO_PI * 7 + (cos(TIME * TWO_PI) + 1) * 0.2);
stroke(0, 1, 1);
pushMatrix();
translate(0, -width * 0.4, 0);
rotateX(PI / 2);
ellipse(0, 0, 100, 100);
popMatrix();
final int INC = 3;
final int NUM_POINTS = 1000;
final float RANGE = 8;
for (int i = 0; i != NUM_POINTS; ++i)
{
beginShape(TRIANGLE_STRIP);
frac_point(i, RANGE, NUM_POINTS);
frac_point(i + 1, RANGE, NUM_POINTS);
frac_point(i + INC, RANGE, NUM_POINTS);
frac_point(i + INC + 1, RANGE, NUM_POINTS);
endShape();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment