Created
May 4, 2016 13:27
-
-
Save TonyMooori/19e4ea20fa427e8933685830d727255b to your computer and use it in GitHub Desktop.
Draw hypocycloid by Processing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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