Priedas1

From Kulki

http://media.vda.lt/st/bare/p5/kampas/

float vx,vy,x,y; float x1,x2,y1,y2,r,h,t; void setup(){

 size(200,400);
 vx=0;
 vy=0.9;
 x1=50;
 y1=300;
 x2=150;
 y2=250;
 r=10;
 x=100;
 y=50;
 framerate(60);

}

void draw(){

 background(200);
 line(x1,y1,x2,y2);
 fall();

}

void mouseReleased(){

 x=mouseX;
 y=mouseY;
 vy=0.9;
 vx=0;

}

void fall(){

 ellipse(x,y,r,r);
 x=x+vx;
 y=y+vy;
 if (y>height){
   y=50;
 }
 t = atan((y2-y1)/(x2-x1));
 float m = tan(t);
 float b = y2 - x2*m;
 float k = t/abs(t);
 if (x>=x1&&x<=x2){
 if ( abs(y+vy - m*(x+vx) - b) < 5 ){
   {
     float md = atan(-1/m);
     float t0 = atan2(-vy,-vx);
     float t1 = md + (md-t0);
     float v = sqrt(pow(vx,2)+pow(vy,2));
     vy = v*sin(t1);
     vx = v*cos(t1);
   }
 }
 }

}

Personal tools