Hi,
I'm starting to learn about classes, and I'm having some frustration with some of the basic elements of class syntax. I've started with a simple line drawing. It runs as follows:
Quote:float x = 1.0;
float speed = .05;
void setup() {
size (900,900);
smooth ();
loop();
}
void draw () {
background (255);
translate (width/2,height/2);
for (int i =0; i <20; i++) {
rotate (PI/7);
strokeWeight (i);
line (0,0,x+55,0);
x= x+speed;
}
}
I'm trying to format this code as a class so it can be further manipulated copied, etc. However, I seem to not really understand how a constructor works, despite my efforts. What am I doing wrong in the following code, so that I'm not getting the same results as above?
Quote:Firework fw;
void setup() {
size (900,900);
smooth ();
loop();
fw = new Firework (0,0,0,0);
}
void draw () {
background (255);
fw.display();
}
class Firework {
float x,y;
Firework(float xpos,float ypos, float xpos, float ypos) {
x = xpos;
y = ypos;
}
void display () {
translate (width/2,height/2);
for (int i =0; i <20; i++) {
rotate (PI/7);
strokeWeight (i);
line (x,y,x+55,y);
}
}
}