P5 Python: Create a Color with hexadecimal

Date: 2020-01-17 | p5 | p5py | python |

DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)

problem

I'm using the P5 Python library and want to create a color with hexadecimal, how can I do this?

solution

To create a color with a hex code, you can do:

Color("#000000")

For example, if I wanted to create a big red circle, I could use the following sketch:

from p5 import *

def setup():
    size(640, 640)

def draw():
    hex_color: str = "#be403b"
    stroke(hex_color)
    fill(hex_color)
    circle((width / 2, height / 2), height/2)

run()

which would create a big circle like so:

A big red circle created using the above p5 sketchA big red circle created using the above p5 sketch

Want more like this?

The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.