Skip to content

Instantly share code, notes, and snippets.

@TonyMooori
Created May 4, 2016 13:27
Show Gist options
  • Select an option

  • Save TonyMooori/19e4ea20fa427e8933685830d727255b to your computer and use it in GitHub Desktop.

Select an option

Save TonyMooori/19e4ea20fa427e8933685830d727255b to your computer and use it in GitHub Desktop.
Draw hypocycloid by Processing.
float r = 80; // 大きさ
int N = 8; // 点の個数
int p = 5; // 分母
int q = 2; // 分子
float theta = 0.0;
float d_theta = PI / 60;
float k = float(p)/float(q);
void setup() {
size(640, 480);
background(0);
}
void draw() {
fill(0, 0, 0, 5);
rect(0,0,width,height);
fill(0, 255, 0);
stroke(0, 255, 0);
translate(width/2, height/2);
// 基本的にこのWikipediaを見れば大丈夫
// https://en.wikipedia.org/wiki/Hypocycloid
theta += d_theta;
for (int i = 0; i < N; i++ ) {
// 位相にqを掛けて周期を合わせてる
float phi = theta + i * 2 * PI / N * q;
float x = r*(k-1)*cos(phi) + r * cos(phi*(k-1));
float y = r*(k-1)*sin(phi) - r * sin(phi*(k-1));
ellipse(x, y, 20, 20);
}
//saveFrame("frame/###.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment