P5 Python: Create a Color with hexadecimal

Published: 2020-01-17 21:38:01 -0800 -0800

Reading time: 1 mins (92 words)

Tags: 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

About the Ham

Hi I'm Hamilton and I wrote / built this! I like doing lots of things, but mostly I like to build (and then share those buildings). Some things I'm currently building: art, software, and prose. To stay up-to-date with my latest buildings, subscribe to my email list or follow one of my many other accounts. #buildit #shipit #justhamit

comments powered by Disqus