Essay record

P5 Python: Create a Color with hexadecimal

Record
Essay / / 1 min read / 105 words
Tags
p5p5pypython
On this page2 sections / +

DISCLOSURE: Some links may be affiliate links. Details

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

Built with CloudSeed Rust