We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › program not working in v0091
Page Index Toggle Pages: 1
program not working in v0091 (Read 863 times)
program not working in v0091
Jul 24th, 2005, 7:03pm
 
Just wanted to play with processing a bit again and noticed
that my little app doesn't work in the new version.

is there a document on how to convert your existing apps for the new version out there?

Code:

Ball[] ball;
int objectnumber = 30;

void setup (){

size (500,500);
framerate(30);
ball = new Ball[objectnumber];

for (int i= 0; i < objectnumber; i++){
ball[i] = new Ball(#940B35,random(50,500),random(10,400),random(1,7),random(1,5), 10, 30);
}

}

void draw (){
background(#280915);
//ball[].collide(){
for (int i = 0; i < objectnumber; i++){

ball[i].draw ();
ball[i].move ();

;

}}
}

class Ball{


float size= 10;
float xpos;
float ypos;
float xspeed;
float yspeed;
float diameter;
float diameter2;
color c;
int xdirection = 1;
int ydirection = 1;

Ball (color c_,float xp, float yp,float xs, float ys, float d, float d2){
c = c_;
xpos = xp;
ypos = yp;
xspeed = xs;
yspeed = ys;
diameter = d;
diameter2 = d2;

}

void draw(){
ellipseMode(CENTER_DIAMETER);
noStroke();
fill (c);
smooth();
ellipse(xpos,ypos,diameter,diameter);
if (diameter > 10){
diameter--;}
}

void move(){
xpos = xpos +(xspeed * xdirection);
ypos = ypos +(yspeed * ydirection);
if (xpos > width-diameter2*0.5 || xpos < diameter2*0.5){
xdirection *=-1;
diameter = diameter2;
}
if (ypos > height-diameter2*0.5 || ypos < diameter2*0.5){
ydirection *=-1;
diameter = diameter2;
}
/*}

void collide(){
if (xpos == xpos - diameter){
xdirection *=-1;
}
if (ypos == ypos - diameter){
ydirection *=-1;
}


}*/
}
Re: program not working in v0091
Reply #1 - Jul 24th, 2005, 7:16pm
 
well, you can start by changing the void loop() to void draw()...
Re: program not working in v0091
Reply #2 - Jul 25th, 2005, 1:59pm
 
thanks

any idea why class Ball is giving me an error?
do classes have to be defined differend in the new version?
Re: program not working in v0091
Reply #3 - Jul 25th, 2005, 7:17pm
 

Here's a quick working version. Your problems are syntactical. When you got an error it was because of a failure to encapsulate methods properly using {} curly braces.

Often happens when you comment out a conditional statement but forget the closing } further down the code.

Always worth checking before anything else! They must all add up.

Removed CENTER_DIAMETER from ellipseMode() as this is now CENTER, plus I ditched a spurious semi-colon ;

Code:

Ball[] ball;
int objectnumber = 30;

void setup (){

size (500,500);
framerate(30);
ball = new Ball[objectnumber];

for (int i= 0; i < objectnumber; i++){
ball[i] = new Ball(#940B35,random(50,500),random(10,400),random(1,7),random(1,5), 10, 30);
}

}

void draw (){
background(#280915);
//ball[].collide(){
for (int i = 0; i < objectnumber; i++){

ball[i].draw ();
ball[i].move ();

}


}

class Ball {


float size= 10;
float xpos;
float ypos;
float xspeed;
float yspeed;
float diameter;
float diameter2;
color c;
int xdirection = 1;
int ydirection = 1;

Ball (color c_,float xp, float yp,float xs, float ys, float d, float d2){
c = c_;
xpos = xp;
ypos = yp;
xspeed = xs;
yspeed = ys;
diameter = d;
diameter2 = d2;

}

void draw(){
ellipseMode(CENTER);
noStroke();
fill (c);
smooth();
ellipse(xpos,ypos,diameter,diameter);
if (diameter > 10){
diameter--;}
}

void move(){
xpos = xpos +(xspeed * xdirection);
ypos = ypos +(yspeed * ydirection);
if (xpos > width-diameter2*0.5 || xpos < diameter2*0.5){
xdirection *=-1;
diameter = diameter2;
}
if (ypos > height-diameter2*0.5 || ypos < diameter2*0.5){
ydirection *=-1;
diameter = diameter2;
}
/*}

void collide(){
if (xpos == xpos - diameter){
xdirection *=-1;
}
if (ypos == ypos - diameter){
ydirection *=-1;
}


}*/
}
}

Page Index Toggle Pages: 1