P5 Python: Create a Color with hexadecimal

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

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 / easiest way to support my work is by subscribing for future updates and sharing with your network.