Thursday, February 10, 2011

modified clone of 'jump_ball'

This is the code which i changed to make it look different



// This sketch builds on a prior work, "jump_ball", created by JohnFisher
// http://studio.sketchpad.cc/sp/pad/view/ro.9hxUTjjyJyPrA/rev.374


// This sketch builds on a prior work created by Claudio Pinho
// http://studio.sketchpad.cc/sp/pad/view/Xa5LH0mNcc/rev.1074

//Teste 1
myCircle c1 = new myCircle(width/23, 1, 11);

float vy = 0.2;
float gravity = 0.888;


void setup(){
size(300, 600);
frameRate(40);
smooth();
}

void draw() {
background(323*PI,332,102*vy);
c1.update();
}

class myCircle {
float xpos, ypos, radius, mass, lypos;

myCircle (float x, float y, float r) {
xpos = x;
ypos = y;
radius = r+64;
mass = (PI * (radius*5));
}
void update(){
//calc of velocity
vy += mass / (mass-20 * gravity/54);

//position is updated
ypos += vy;

//basic bottom collision
if(ypos > height-radius) {
ypos = height - radius;
vy *= -.9;
}

//if last y position is equivalent to the actual y position
//then the program stops
if(lypos == ypos && lvy == vy) {
ypos = height - radius;
println("stoped");
noLoop();

}

ellipse(xpos, ypos, radius*3, radius*3);
strokeWeight(3);
line(xpos, ypos-53, radius*2+33, radius*2-20);
//record the last y position and y velocity
lypos = ypos;
lvy = vy;

No comments:

Post a Comment