Ball & Beam example

edited March 2015 in Share Your Work

Hello everyone

I share my project of differential equations.

It has a small problem when the mouse moves very fast and mouseY are not synchronized with the line.

float t, rad, grados;

float x1, x2, x1k, x2k;

float g = 9.81;

void setup(){

size (600, 600);

mouseY=300;

}

void draw(){

rad=radians(mouseY-300);

grados=(180*rad)/PI;

x1k=x1+(x2k*0.05);

x2k=x2+(g*sin(rad)*0.05);

if(x1k<300 && x1k>-300){

x2=x2k;

x1=x1k;

}

if(x1k>300){

x2=0;

x1=300;

}

if(x1k<-300){ x2=0; </p>

x1=-300;

}

fill(255,255,0);

background (0);

textSize(20);

text(" Ball & Beam",10,20);

translate (width/2,height/2);

triangle(0,2,20,100,-20,100);

if(mouseY<370 && mouseY>230){

rotate(radians(mouseY-300)); }

if(mouseY>370){

<

p> rotate(radians(370-300));

}

if(mouseY<230){

rotate(radians(230-300));

}

ellipse (x1,-4,12,12);

strokeWeight (2);

stroke (0,255,0);

line(305,1,-305,5);

noStroke();

}

Sign In or Register to comment.