Skip to content

Instantly share code, notes, and snippets.

@tomoyk
Last active May 1, 2017 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyk/88f7c91e3678c96f4f84762e8a3f320f to your computer and use it in GitHub Desktop.
Save tomoyk/88f7c91e3678c96f4f84762e8a3f320f to your computer and use it in GitHub Desktop.
Cycloidをprocessingで書く
void setup(){
size(1200,600);
}
void draw(){
//background(255);
version2();
}
float x,y;
float rad = PI/2;
int r = 50;
void version1(){
x = r * (rad - sin(rad));
y = r*(1 - cos(rad));
fill(0);
//point(x+50,-y+500);
ellipse(x+50,-y+500,2,2);
//delay(10);
rad+=0.1;
}
float Tx = r;
float Ty = 500;
float Px[] = new float[500];
float Py[] = new float[500];
int counter = 0;
void version2(){
stroke(0);
background(230);
line(0,500,width,500);
// 円
fill(255);
ellipse(Tx,Ty-r,r*2,r*2);
// 円の中心とサイクロイド曲線上の点を結ぶ線分
line(Tx,500-r,Tx + r*cos(rad),500-r + r*sin(rad));
// サイクロイド曲線上の点
Px[counter] = Tx + r*cos(rad);
Py[counter] = 500-r + r*sin(rad);
// サイクロイド曲線上の点の軌跡
noStroke();
for(int i = 0;i<=counter;i++) {
if(i==counter)
fill(255, 0, 0);
else
fill(0, 0, 255);
ellipse(Px[i], Py[i], 5, 5);
}
// 値の変化
Tx += 8;
float a = radians( counter * 10 );
//rad += 0.1;
rad = a;
counter++;
delay(30);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment