Skip to content

Shapes

Every example on this page runs after these two lines, and ends by sending a color to the Output node:

from pyzed import shading
g = shading.Graph("demo")

Shapes are signed distances (SDF): each pixel gets its distance to the edge of the shape, negative inside and positive outside. A distance is not a picture yet: Fill, Stroke and Glow turn it into a mask from 0 to 1. Distances can be combined (union, subtract, intersect) before drawing, even with a smooth seam.

circle · Shapes · g.circle(...)

The signed distance to a circle (negative inside). Use Fill or Stroke to draw it.

The Circle node as it looks in the Shader view, with its preview

A circle around center with a radius (in units of the height). Draw it with Fill, Stroke or Glow.

Input Type Default
p vec2 Centered (context)
center vec2 (0, 0)
radius float 0.3
Output Type
distance float
Example
d = g.circle(radius=0.3)
g.output(g.rgba(g.fill(d), 1.0))

box · Shapes · g.box(...)

The signed distance to a rectangle of size (rounded by radius).

The Box node as it looks in the Shader view, with its preview

A rectangle of size, with corners rounded by radius: cards, buttons, panels.

Input Type Default
p vec2 Centered (context)
center vec2 (0, 0)
size vec2 (0.6, 0.4)
radius float 0.05
Output Type
distance float
Example
d = g.box(size=[0.8, 0.5], radius=0.08)
g.output(g.rgba(g.fill(d), 1.0))

ring · Shapes · g.ring(...)

The signed distance to a ring of radius and thickness.

The Ring node as it looks in the Shader view, with its preview

A ring (a donut outline) of radius and thickness: loaders, targets, halos.

Input Type Default
p vec2 Centered (context)
center vec2 (0, 0)
radius float 0.3
thickness float 0.05
Output Type
distance float
Example
d = g.ring(radius=0.3, thickness=0.04)
g.output(g.rgba(g.fill(d), 1.0))

segment · Shapes · g.segment(...)

The signed distance to a line from a to b, thickness wide.

The Segment node as it looks in the Shader view, with its preview

A line from a to b with round ends and a thickness.

Input Type Default
p vec2 Centered (context)
a vec2 (-0.3, 0)
b vec2 (0.3, 0)
thickness float 0.04
Output Type
distance float
Example
d = g.segment(a=[-0.4, -0.2], b=[0.4, 0.2], thickness=0.05)
g.output(g.rgba(g.fill(d), 1.0))

polygon · Shapes · g.polygon(...)

The signed distance to a regular polygon (sides corners, radius to them).

The Polygon node as it looks in the Shader view, with its preview

A regular polygon with sides corners: triangles, hexagons, octagons.

Input Type Default
p vec2 Centered (context)
center vec2 (0, 0)
radius float 0.3
sides float 6
rotation float 0
Output Type
distance float
Example
d = g.polygon(radius=0.35, sides=6.0)
g.output(g.rgba(g.fill(d), 1.0))

star · Shapes · g.star(...)

The signed distance to a star (inner is how deep its valleys are, 0 to 1).

The Star node as it looks in the Shader view, with its preview

A star with points tips; inner is how deep the valleys between tips are.

Input Type Default
p vec2 Centered (context)
center vec2 (0, 0)
radius float 0.35
points float 5
inner float 0.45
rotation float 0
Output Type
distance float
Example
d = g.star(radius=0.4, points=5.0, inner=0.45)
g.output(g.rgba(g.fill(d), 1.0))

sdf_op · Shapes · g.sdf_op(...)

Joins two shapes (union), cuts b out of a (subtract) or keeps where they overlap (intersect); smooth melts the seam.

The Combine shapes node as it looks in the Shader view, with its preview

Combines two shapes before drawing them: Union joins them, Subtract shape cuts b out of a, Intersect keeps the overlap. smooth above 0 melts the seam, like two drops of water merging.

Input Type Default
a float 1
b float 1
smooth float 0
Output Type
distance float
Setting Values Default
op union, subtract, intersect union

Sidebar entries

Entry What it does In Python
Union Joins two shapes; smooth melts them together. g.union(...)
Subtract shape Cuts shape b out of shape a. g.subtract_shape(...)
Intersect Keeps where two shapes overlap. g.intersect(...)
Example
a = g.circle(center=[-0.15, 0.0], radius=0.25)
b = g.circle(center=[0.15, 0.0], radius=0.25)
d = g.union(a, b, smooth=0.1)
g.output(g.rgba(g.fill(d), 1.0))

fill · Shapes · g.fill(...)

Draws a shape: 1 inside, 0 outside, with an antialiased edge softness pixels wide.

The Fill node as it looks in the Shader view, with its preview

Draws a shape solid: 1 inside, 0 outside, with an antialiased edge softness pixels wide. Raise softness for a blurry edge.

Input Type Default
distance float 0
softness float 1
Output Type
mask float
Example
d = g.box(size=[0.6, 0.6], radius=0.1)
g.output(g.rgba(g.fill(d, softness=8.0), 1.0))

stroke · Shapes · g.stroke(...)

Draws the outline of a shape, width wide (in the shape’s units).

The Stroke node as it looks in the Shader view, with its preview

Draws only the outline of a shape, width wide.

Input Type Default
distance float 0
width float 0.02
softness float 1
Output Type
mask float
Example
d = g.star(radius=0.4)
g.output(g.rgba(g.stroke(d, width=0.02), 1.0))

glow · Shapes · g.glow(...)

A soft light around a shape that fades over radius.

The Glow node as it looks in the Shader view, with its preview

A soft light around a shape that fades over radius: neon signs and halos. Add it to a Fill for a solid shape with a glow.

Input Type Default
distance float 0
radius float 0.08
intensity float 1
Output Type
value float
Example
d = g.ring(radius=0.3, thickness=0.01)
light = g.glow(d, radius=0.1)
g.output(g.rgba(g.compose(0.1, 0.8, 1.0) * light, 1.0))

See also: Getting started · The Shader view · Recipes · Shader graphs in Python