How to fill objects

I draw figures (von Koch snowflakes). I want to fill them with color. I don’t know how to do it. The level of knowledge of openframeworks is a bit more than nothing.

void koch(Turtle *turtle, double len, int depth) {

if (depth == 0) {
    turtle->move(len);
} else {
    koch(turtle, len / 3, depth - 1);
    //Turn left 60 degrees.
    turtle->turn(-60);
    koch(turtle, len / 3, depth - 1);
    //Turn right 120 degrees.
    turtle->turn(120);
    koch(turtle, len / 3, depth - 1);
    //Turn left 60 degrees.
    turtle->turn(-60);
    koch(turtle, len / 3, depth - 1);
}

}

void loop() {

for(int i = 0; i < 12; i++) {
    turtle[i].draw();
    for (int j = 0; j < 3; j++) {
        koch(&turtle[i], 300, 3);
        turtle[i].turn(120);
    }
}

}

Turtle::Turtle() {
lines = new ofPolyline();
x = 0.0;
y = 0.0;
dir = 0.0;
}

void Turtle::moveTo(int tx, int ty) {
lines->addVertex(tx,ty);

you can use things like ofFill(); & ofNoFill(); - you can then have a color for each, but make sure each color is above each thing you want to color. same can be said of the fill/no fill thing.

if you have 1 no fill above them all. they all will have no fill etc

hope that helps :v:

1 Like

Thaks, but i dont draw complete “objects”. I draw just lines.

You can try using an ofPath object for each snowflake, this way you can fill them pretty easily.

1 Like

thank you so much! This is exactly what I needed.