Upper-semicircle formula code in Processing
This code draws the upper-semicircle that is a half part of the wave in Tae-Geuk symbol.
The trace of variables follows the formula: y2= sqrt(r2 – x2)
float px, py;
float angle;
float radius = 100;
float frequency = 10;
float frequency2 = 2;
float x, x2;
PFont myFont;
void setup(){
size(400, 200);
background (127);
myFont = createFont("verdana", 12);
textFont(myFont);
frameRate(10);
}
void draw(){
background (127);
noStroke();
fill(255);
float px = 0;
while(px < 100) {
px = px+1;
}
float py = 0;
while(py < 75){
py = py+1;
}
px = width/8 - cos(radians(angle))*(radius/2);
py = 75 + sin(radians(angle))*(radius/2);
rectMode(CENTER);
fill(0);
noStroke();
ellipse(px, py, 5, 5);
angle -= frequency;
while(angle < -180){
angle = 10;
}
text("y = sin x", 35, 185);
text("px = " + px, 105, 185);
text("py = " + py, 215, 185);
loop();
}
No comments:
Post a Comment