with-fill

with-stroke

with-fill

Arguments
[fill & body]
Docstring

Temporarily set the fill color for the body of this macro. The code outside of the with-fill form will have the previous fill color set.

A fill argument of nil disables the fill.

Examples:

(with-fill 255 ...)
(with-fill [10 80 98] ...)
(with-fill nil ...)
Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
; set fill to white and draw a square
(q/fill 255)
(q/rect 30 30 60 60)
; set fill to red and draw 2 squares
(q/with-fill [255 0 0]
  (q/rect 60 60 90 90)
  (q/rect 90 90 120 120))
; draw square, it'll use white color
(q/rect 120 120 150 150)
try example

with-stroke

Arguments
[stroke & body]
Docstring

Temporarily set the stroke color for the body of this macro. The code outside of the with-stroke form will have the previous stroke color set.

A stroke argument of nil disables the stroke.

Examples:

(with-stroke 255 ...)
(with-stroke [10 80 98] ...)
(with-stroke nil ...)
Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
; set fill to white, stroke to black and draw a square
(q/fill 255)
(q/stroke-weight 10)
(q/stroke 0)
(q/rect 30 30 60 60)
; set border to red and draw 2 squares
(q/with-stroke [255 0 0]
  (q/rect 60 60 90 90)
  (q/rect 90 90 120 120))
; draw another square, should have black borders
(q/rect 120 120 150 150)
try example