OK, Here I´m once again, I wrote the program in a completely new structure. Lets say I brought order in it! It still does´t run as wished, I hope you can take a Look around. I would apreciate it a lot. And believe me, once I reach a better level I´ll be also helping the needed onces remembering times like this one
thats the class Walzen
class Walzen{
// screen var
float xpos, ypos, tempypos, rest_posy, v0, vel, acc, anker_ypos;
PImage img;
boolean over, velMax, velMin, fest, pressed, released;
// physical var
float mass, k, damp, accel, force;
int me;
Walzen (float x, float y, PImage i, float m, float d, float k, int id ){
xpos= x;
ypos= y;
img= i;
mass= m;
k= k;
damp= d;
me= id;
}
void setv0(){
v0= random(0.5, 1.5);
}
void setVel(){
if(!over && !velMax && !velMin){
vel=v0+acc;
}
if(vel>= 90){
velMax= true;
}
else{
velMax =false;
}
if(vel<= 1.4){
velMin= true;
}
else{
velMin=false;
}
}
void setAcc(){
if(over && otherOver()){
acc= random(1, 1.25);
}
else{
if(velMax && otherVelmax() && released){
acc= random(-0.5,-1);
}
}
}
boolean otherVelmax(){
for(int i=0; i<num; i++){
if(i!= me){
if( walzen[i].velMax){
return true;
}
}
}
return false;
}
boolean otherOver(){
for(int i=0; i<num; i++){
if(i!= me){
if( walzen[i].over){
return true;
}
}
}
return false;
}
float ankerPoint(){
return ((ypos/yU)%100)*yU;
}
void setYpos(){
if(!velMin && !over){
ypos+= vel;
}
if(velMin && !over)
{
tempypos=ypos;
rest_posy = ankerPoint();
force = -k * (tempypos - rest_posy); // f=-ky
accel = force / mass; // Set the acceleration, f=ma == a=f/m
vel = damp * (vel + accel); // Set the velocity
tempypos = tempypos + vel; // Updated position
ypos= tempypos;
if( vel==0 ) {
over = true;
}
else {
over = false;
}
}
}
void update(){
if(pressed){
if(over){
setv0();
}
setAcc();
setVel();
setYpos();
}
}
void draw(){
image(img, xpos, ypos);
}
}
//and here is the Principal program
PImage b;
int num = 3;
int N=11; //number of objects in the picture
float yU;
Walzen[] walzen = new Walzen[num];
float [] vel= new float [num];
boolean feder;
void setup()
{
b = loadImage("wKopie.jpg");
size(400,300);
smooth();
frameRate(30);
yU= b.height/N;
translate(0, (-762-yU));
walzen[0]= new Walzen(50, 5, b, 8.0, 0.98, 0.1, 0);
walzen[1]= new Walzen(150,5, b, 8.0, 0.98, 0.1, 1);
walzen[2]= new Walzen(250,5, b, 8.0, 0.98, 0.1, 2);
}
void draw()
{
background(#FFFFFF);
for(int i=0; i<=(num-1);i++){
walzen[i].update();
walzen[i].draw();
println(walzen[i].ypos+" FR "+frameRate+"yU"+ yU);
}
}
void mousePressed()
{
for(int i=0; i<num; i++) {
walzen[i].pressed=true;
}
}
void mouseReleased()
{
for(int i=0; i<num; i++) {
walzen[i].released=true;
}
}
Thanks in forward!
Gustavo