The RoughCanvas give a nice hand-drawn style to your canvas!
from ipycanvas import RoughCanvas
The rough canvas gives a nice hand-drawn style to your canvas, note that it only works with direct draw calls, it does not work with paths created with begin_path
, those paths will be drawned normally.
canvas = RoughCanvas()
canvas.stroke_rect(100, 100, 100, 100)
canvas.fill_rect(50, 50, 100, 100)
canvas.stroke_circle(300, 300, 100)
canvas.fill_circle(350, 350, 100)
canvas.stroke_line(200, 200, 300, 300)
canvas
With the RoughCanvas, not only you can modify the fill color but you can also modify the fill styling, using one of the following values: 'hachure' (default), 'solid', 'zigzag', 'cross-hatch', 'dots', 'sunburst', 'dashed' or 'zigzag-line'
canvas = RoughCanvas(width=850, height=100)
canvas.fill_style = "blue"
canvas.line_width = 2.0
rough_fill_style_values = [
"hachure",
"solid",
"zigzag",
"cross-hatch",
"dots",
"sunburst",
"dashed",
"zigzag-line",
]
for i in range(len(rough_fill_style_values)):
canvas.rough_fill_style = rough_fill_style_values[i]
canvas.fill_rect(10 + i * 100, 10, 90, 80)
canvas
You can still change the stroke width using the line_width
attribute, just like with the normal Canvas class
canvas = RoughCanvas(width=600, height=300)
canvas.line_width = 3.0
canvas.stroke_rect(100, 100, 100, 100)
canvas.line_width = 10.0
canvas.stroke_rect(300, 100, 100, 100)
canvas
There are some options you can play with to change the style of your drawing
canvas = RoughCanvas(width=850, height=100)
canvas.fill_style = "green"
for i in range(8):
canvas.roughness = i
canvas.fill_rect(10 + i * 100, 10, 90, 80)
canvas
canvas = RoughCanvas(width=850, height=150)
canvas.fill_style = "green"
for i in range(8):
canvas.bowing = i * 3.0
canvas.stroke_rect(20 + i * 100, 20, 90, 110)
canvas
from math import pi
c = RoughCanvas(width=600, height=600)
c.fill_style = "green"
c.fill_arc(300, 300, 200, 0, 0.9 * pi)
c.fill_style = "red"
c.fill_arc(300, 300, 200, 0.9 * pi, pi + 0.2 * pi)
c.fill_style = "blue"
c.fill_arc(300, 300, 200, pi + 0.2 * pi, 2 * pi)
c.stroke_style = "black"
c.stroke_arc(300, 300, 200, 0, 2 * pi)
c
n_particles = 3_000
import numpy as np
x = np.array(np.random.rayleigh(250, n_particles), dtype=np.int32)
y = np.array(np.random.rayleigh(250, n_particles), dtype=np.int32)
size = np.random.randint(4, 8, n_particles)
canvas = RoughCanvas(width=800, height=500)
canvas
canvas.fill_rects(x, y, size)