/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.FWd4dJ3j$C3/rev.188
*
* authors:
* David Merino
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
float y, y0;
float v;
float a;
int i;
float t, t0;
float A = 200;
float T = 4;
float phi = PI;
boolean update;
void setup()
{
size(600, 600);
frameRate(70);
background(0);
y=height/2;
i = 0;
t0=millis()/1000.;
update = true;
}
void draw()
{
if(update){
t = (millis()/1000.)-t0;
y = height/2+A*sin(2*PI*t/T + phi);
v = A*cos(2*PI*t/T+phi);
a = -A*sin(2*PI*t/T+phi);
background(0);
fill(255);
stroke(0);
ellipse(width/2, y, 10, 10);
stroke(0,150,50);
line(width/2, y, width/2, y+v);
line(width/2 + 10, height/2, width/2 + 10, height/2 + v);
stroke(0,0,255);
line(width/2, y, width/2, y+a);
line(width/2 + 20, height/2, width/2 + 20, height/2 + a);
fill(0,150,50);
stroke(0,150,50);
if(v>=0)
{
triangle(width/2, y+v, width/2-5, y+v-10, width/2+5, y+v-10);
triangle(width/2+10, height/2+v, width/2-5+10, height/2+v-10, width/2+5+10, height/2+v-10);
}
else
{
triangle(width/2, y+v, width/2-5, y+v+10, width/2+5, y+v+10);
triangle(width/2+10, height/2+v, width/2-5+10, height/2+v+10, width/2+5+10, height/2+v+10);
}
stroke(0,0,255);
fill(0,0,255);
if(a>=0)
{
triangle(width/2, y+a, width/2-5, y+a-10, width/2+5, y+a-10);
triangle(width/2+20, height/2+a, width/2-5+20, height/2+a-10, width/2+5+20, height/2+a-10);
}
else
{
triangle(width/2, y+a, width/2-5, y+a+10, width/2+5, y+a+10);
triangle(width/2+20, height/2+a, width/2-5+20, height/2+a+10, width/2+5+20, height/2+a+10);
}
i++;
}
}
void mouseClicked() {
update = !update;
if(update)
{
t0=millis()/1000. -t;
}
}