Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Processing3 - 回る正弦関数
//sin() と tan()の動き
//スペースキーで止まるよ
//r:Φ初期角度 a:ω角速度?
float r = 0;
float a = 0.01;
boolean isStop = false;
void setup() {
size(700,700);
frameRate(100);
}
void keyPressed() {
if(keyCode==32) {
if(isStop) {
isStop = false;
} else {
isStop = true;
}
}else if(keyCode==UP) {
a = a + 0.001;
}else if(keyCode==DOWN) {
a = a - 0.001;
}
}
void draw() {
if(isStop) return;
fill(200,200,200);
quad(0,0,700,0,700,700,0,700);
fill( 255, 255, 255 );
stroke(0,0,0);
ellipse(350,350,503,503);
line(350,50,350,650);
line(50,350,650,350);
line(600,0,600,700);
quad(0,655,300,655,300,700,0,700);
fill(255,0,0);
text("θ = " + r ,100,680);
text("a = " + a ,100,690);
stroke(255,0,0);
float x = 250*cos(r)+350;
float y = -250*sin(r)+350;
line(350,350,x,y);
line(x,y,x,350);
stroke(0,0,255);
if(cos(r)>0) {
line(x,y,600,tan(r)*-250+350);
}else if(cos(r)<0) {
line(350,350,600,tan(r)*-250+350);
}
r = r + a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment