OOP Constructor without variables?
in
Programming Questions
•
1 year ago
I want to declare the vine class without parameters but I am getting errors and wondering if maybe this is not possible??
My error is actually "unexpected token: {" in the part below in red but I don't see a problem with how I declared it.
New to OOP. Thanks for the help.
My error is actually "unexpected token: {" in the part below in red but I don't see a problem with how I declared it.
New to OOP. Thanks for the help.
- Vine vine;
void setup() {
size(400, 400);
background(206, 198, 198);
vine = new Vine();
noLoop();
}
void draw() {
vine.grow(width/2, height/2, 400, 300);
if (mousePressed == true) {
vine.leaf(mouseX, mouseY, 1);
}
}
- class Vine {
float startX, startY, endX, endY, direction;
int lfSize;
{
Vine() {
startX = sX;
startY = sY;
endX = eX;
endY = eY;
direction = dir;
lfSize = lfSize;
}
void grow(sX, sY, eX, eY) {
line(sX, sY, eX, eY);
}
void leaf(sX, sY, lfSize) {
float angle = radians(40);
pushMatrix();
translate(sX, sY); //Global position x, y becomes local position 0,0
rotate(angle);
scale(lfSize);
beginShape();
vertex(0, 0);
bezierVertex(50, -60, 100, -30, 150, -50);
bezierVertex(100, 30, 50, 30, 0, 0);
endShape();
}
}
}
1