/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.oHXlITQTOa-/rev.1318
*
* authors:
* Pétrole
* Bernard
* Antoine
*
* Well.
* Bernard
* Grallius
* Ginette
*
* isabelle H.
*
* Yohan Farouz
* si
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
int oriX=150; //centre du tronc en X
int oriY=500; //centre du tronc en Y
float g=9.8; //constante gravitationnelle
float k=1; //elasticite
float m=1.5; //masse de l'oiseau
float l0=50; // longeur du ressort au repos
int birdX=oriX-20;
int birdY=oriY-20;
boolean released = false;
boolean bounce=false; // rebond
int birdX0=0; //coordonnee initiale du lache
int birdY0=0; //coordonnee initiale du lache
float t=0; //temps
float vSol=0;
float damping=0.5;
//couleur du tronc
color yellow= color(255, 255, 0);
//couleur de l'oiseau
color red= color(255, 0, 0);
//image de l'oiseau
PImage bird;
void setup (){
size (800, 600) ;
bird=loadImage("/static/uploaded_resources/p.2336/bird.png");
}
void draw()
{
//fond d'écran
background (52, 186, 231);
fill(yellow);
rect(oriX-10, oriY, 20, 100);
if (released && birdY<=560)
{
birdX= birdX0;
birdY= round ((1/2)*g*sq(t) -vSol*t+ birdY0);
t=t+0.1;
}
if (released && birdY>560)
{
vSol=sqrt(damping*(560-birdY0)*2*g);
birdX=birdX0;
birdY0=560;
birdY=birdY0;
t=0;
if(vSol<0.1)
{
vSol=0;
released=false;
birdX=oriX-20;
birdY=oriY-20;
}
}
image(bird, birdX, birdY, 40, 40);
}
void mouseReleased ()
{
released=true;
birdX0=mouseX-20;
birdY0=mouseY-20;
vSol=0;
}
void mouseDragged()
{
birdX=mouseX-20;
birdY=mouseY-20;
}