Coding Academy home

Help & Lessons / Looks

Looks

Changing Color

Every shape has a color, and you can read or change it from its own code:

export function update(self) {
    self.color = "red";
}

Or use self.getColor() and self.setColor(...) instead — they do exactly the same thing, just written as verbs like getX()/setX() if that's easier to remember:

export function update(self) {
    self.setColor("#ff6b4f");
}

Colors can be a plain name ("red", "blue", "lime") or a hex code like "#4f8cff" — the same color codes the color picker in the properties panel uses.

A common pattern: change color when something happens, like getting hit:

export function update(self) {
    if (self.isTouching("hazard")) {
        self.setColor("red");
    }
}
You can also read or change another shape's color, not just your own — see "Reading and Changing Another Shape" in the next topic.