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)
   Array of different shapes
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Array of different shapes  (Read 283 times)
Ride215

Ride215
Array of different shapes
« on: Apr 9th, 2004, 11:03am »

I was attempting to create an array of shapes for easier translation and such but I could not figure out which type of an array it need to be. I tried type Shape and I tried casting, niether which of worked. (Error: type "void" not valid..." Is there a simpler way to go about this?
        - Thanks, Josh
 
amoeba

WWW
Re: Array of different shapes
« Reply #1 on: Apr 9th, 2004, 3:25pm »

Hmm, array of "shapes"? You mean rects, ellipses etc? Those are not actual classes, they are only functions that draw.
 
To do what you want you'd probably be best off creating a class to contain shapes. Calling it Shape won't work, by the way, since it collides with java.awt.Shape. Let's call it MyShape. A sample program could look like this:
 
Code:
MyShape shape[];
static int RECT=0,ELLIPSE=1;  
 
void setup() {
  size(400,400);
  shape=new MyShape[100];  
 
  shape[0]=new MyShape(RECT, -50,0, 10);  
  shape[1]=new MyShape(ELLIPSE, 50,0, 10);  
}
 
void loop() {
  translate(random(width),random(height));
  fill(200,0,0);
  shape[0].draw();  
  fill(0,200,255);
  shape[1].draw();  
}
 
 
class MyShape {  
  int type;  
  float x,y,rad;  
 
  MyShape(int _type,float _x,float _y,float _rad) {  
    type=_type;  
    x=_x;  
    y=_y;  
    rad=_rad;  
  }  
 
  void draw() {  
    if(type==RECT) rect(x,y, rad,rad);  
    else if(type==ELLIPSE) ellipse(x,y, rad,rad);  
  }  
}
« Last Edit: Apr 9th, 2004, 3:31pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
Pages: 1 

« Previous topic | Next topic »