FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   width - from inside an object
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: width - from inside an object  (Read 306 times)
kevin

WWW
width - from inside an object
« on: Sep 10th, 2003, 12:33pm »

Hi,
 
How can an object find out the width? Do I need to specificy the root object for it to work (and if so, how)
 
Here's what I'm doing.
 
Code:
testClass myClass = new testClass();
 
// Setup Stuff
void setup() {
  size(200,200);
  background(255);
  fill(255,234,78);
  ellipseMode(CENTER_RADIUS);
}
 
// Main Loop
void draw() {
  myClass.display();
}
 
class testClass {
  int x, y;
   
   // constructor class
   testClass() {
 print (width);
 x = (int)random(width);
 y = (int)random(height);
   }
   
   //move class
   void display() {
     ellipse(x,y,10,10);
   }
}

 
The print statement prints out width as 0, and the ellpise is drawn at 0,0.
 
thanks a lot
 
toxi

WWW
Re: width - from inside an object
« Reply #1 on: Sep 10th, 2003, 1:28pm »

if you look closely at your code, you should be able to answer this yourself
 
the constructor of your test class is called before the setup() method is executed, hence the "width" variable is  still at its default value (0)...
 
let me point you to another thread (and specifically my 2nd post) about related problems...
 

http://toxi.co.uk/
kevin

WWW
Re: width - from inside an object
« Reply #2 on: Sep 11th, 2003, 11:33am »

Ah yes, that makes sense, I'm not thinking very logically. I wish there was a book on processing, so I have a better idea of the overall picture.
 
Cheers toxi, you're a wealth of information, so I'm getting there slowly.
 
 
Pages: 1 

« Previous topic | Next topic »