On this page:
star
flash
sun
flower
cloud
polygon
circle
gear
radial_  pict
Radial
radial
star_  radial
flash_  radial
sun_  radial
flower_  radial
cloud_  radial
polygon_  radial
circle_  radial
gear_  radial
Radial.pict
Radial.path
radials_  pict
evenly_  spaced
jitter_  spaced
Bounding  Box  Mode
8.12.0.9

7 Pict Radial Shapes🔗

 import: pict/radial package: rhombus-prototype

function

fun star(~points: n :: PosInt = 5, ....) :: Pict

 

function

fun flash(~bumps: n :: PosInt = 10, ....) :: Pict

 

function

fun sun(~rays: n :: PosInt = 10, ....) :: Pict

 

function

fun flower(~petals: n :: PosInt = 6, ....) :: Pict

 

function

fun cloud(~bumps: n :: PosInt = 6, ....) :: Pict

 

function

fun polygon(~sides: n :: PosInt = 10, ....) :: Pict

 

function

fun circle(~sides: n :: PosInt = 10, ....) :: Pict

 

function

fun gear(~arms: n :: PosInt = 10, ....,

         ~hole: hole :: Real = 0.5) :: Pict

The same as radial_pict, but with defaults for arguments so that the result looks like a flower, cloud, etc., and sometimes with an different keyword like ~petals instead of ~points. The gear function has an extra hole argument, which specifies a relative side for a hole in the middle of the gear.

> star(~fill: "gold")

image

> flash(~fill: "red")

image

> flower(~fill: "purple")

image

> cloud(~fill: "gray")

image

> polygon(~fill: "blue")

image

> circle(~fill: "forestgreen")

image

> gear(~fill: "brown")

image

function

fun radial_pict(

  ~points: n :: PosInt = 6,

  ~width: width :: Real = 64,

  ~height: height :: Real = width,

  ~rotate: rotate :: Real = 0,

  ~angle_at: angle_at :: Function.of_arity(2) = evenly_spaced,

  ~inner_radius: inner :: Real = 0.5,

  ~outer_radius: outer :: Real = 1,

  ~inner_pause: inner_pause :: Real = 0,

  ~outer_pause: outer_pause :: Real = 0,

  ~flat_inner_edge: flat_inner_edge = #false,

  ~flat_outer_edge: flat_outer_edge = #false,

  ~outer_pull: outer_pull :: Real = 0,

  ~inner_pull: inner_pull :: Real = 0,

  ~fill: fill :: MaybeColor = #false,

  ~line: line :: MaybeColor = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~bound: bound :: BoundingBoxMode = #'unit

) :: Pict

A general function for creating shapes like stars, flowers, polygons and gears—shapes that have a radial symmetry involving “points” that extend to an outer radius from a smaller base radius. Functions like star, flower, and polygon have the same arguments as radial, but with defaults that produce the shapes suggested by the names.

Various arguments have expected ranges, but none of the ranges are enforced, and interesting images can be created by using values outside the normal ranges:

inner

 

0 to outer

inner_pause

 

0 to 1

outer_pause

 

0 to 1

inner_pull

 

0 to 1

outer_pull

 

0 to 1

The result of radial is squashed to ellipse form if height is not the same as width. The rotate argument determines an amount of rotation (in radians counter-clockwise) applied to the imagine before it is squashed. The bounding box for the resulting pict corresponds to a square around the original circle, and it is not affected by rotate. (It is affected by bound, however, as described further below.)

Points radiating from the inner to outer radius are evenly spaced by default, but angle_at is called for each point’s index to get a location for each point, and it can choose a different spacing (e.g., with some “jitter” from even spacing in the case of cloud).

The points extend from a base of radius inner to an edge at radius outer. By default, the connection from a point at the inner radius to a point at outer radius uses up half the radial space allocated to the point. If inner_pause is creater than 0, it represents a fraction of half the space between points that stays at the inner radius before extending out. Similarly, outer_pause is a fraction allocated to staying at the out radius. When staying at the inner or outer radius, flat_inner_edge and flat_outer_edge determine whether the start and end points are connected by a straight line or an arc at the radius.

When the inner_pull and outer_pull arguments are 0, then the inner and outer points are straight corners. Otherwise, they determine an amount of curvature. Each of outer_pull and inner_pull represent an amount of curvature touward a rounder “petal.”

The line, line_width, and fill arguments are the same as for functions like rectangle.

The bound argument can be #'unit, #'unit, #'shrink, or #'stretch. The default, #'unit, gives the resulting pict a bounding box that corresponds to the outer radius of the image. If bound is #'shrink, then the bounding box is instead one that encloses the inner and outer points of the figure, and so the resulting pict may have bounds smaller than width and height. The #'stretch mode is similar to #'shrink, but the pict is scaled and stretched to ensure that its bounding box has dimentions width and height.

> radial_pict()

image

> radial_pict(~fill: #'inherit).colorize("red")

image

> radial_pict(~width: 64, ~height: 32, ~rotate: math.pi * 1/2)

image

> radial_pict(~inner_pause: 0.5, ~outer_pause: 0.25, ~fill: "black")

image

> radial_pict(~outer_pull: 0.25, ~fill: "purple")

image

> radial_pict(~inner_pull: 0.25, ~fill: "forestgreen")

image

> radial_pict(~outer_pull: 0.25, ~inner_radius: -0.5, ~fill: "lightblue")

image

> beside(~sep: 16, ~vert: #'top,

         ellipse(~around: radial_pict(~points: 3)),

         rectangle(~around: radial_pict(~points: 3)),

         rectangle(~around: radial_pict(~points: 3, ~bound: #'shrink)),

         rectangle(~around: radial_pict(~points: 3, ~bound: #'stretch)))

image

annotation

Radial

 

function

fun radial(

  ~points: n :: PosInt = 6,

  ~width: width :: Real = 64,

  ~height: height :: Real = width,

  ~rotate: rotate :: Real = 0,

  ~angle_at: angle_at :: Function.of_arity(2) = evenly_spaced,

  ~inner_radius: inner :: Real = 0.5,

  ~outer_radius: outer :: Real = 1,

  ~inner_pause: inner_pause :: Real = 0,

  ~outer_pause: outer_pause :: Real = 0,

  ~flat_inner_edge: flat_inner_edge = #false,

  ~flat_outer_edge: flat_outer_edge = #false,

  ~outer_pull: outer_pull :: Real = 0,

  ~inner_pull: inner_pull :: Real = 0,

) :: Radial

Similar to radial_pict, but instead of a pict, produces a Radial. A single Radial can be converted to a pict with Radial.pict, but multiple radials can be combined using radials_pict.

For example, gear uses radials_pict to combine gear arms with a hole when a non-zero hold is requested.

> def r = radial(~points: 7)

> r.pict(~fill: "blue")

image

> r.pict(~line: "blue", ~line_width: 3)

image

function

fun star_radial(~points: n :: PosInt = 5, ....) :: Radial

 

function

fun flash_radial(~bumps: n :: PosInt = 10, ....) :: Radial

 

function

fun sun_radial(~rays: n :: PosInt = 10, ....) :: Radial

 

function

fun flower_radial(~petals: n :: PosInt = 6, ....) :: Radial

 

function

fun cloud_radial(~bumps: n :: PosInt = 6, ....) :: Radial

 

function

fun polygon_radial(~sides: n :: PosInt = 10, ....) :: Radial

 

function

fun circle_radial(~sides: n :: PosInt = 10, ....) :: Radial

 

function

fun gear_radial(~arms: n :: PosInt = 10, ....) :: Radial

The same as radial, but with defaults for arguments so that the result looks like a flower, cloud, etc., and sometimes with an different keyword like ~petals instead of ~points.

> flower_radial(~petals: 5).pict(~fill: "pink")

image

method

method (radial :: Radial).pict(

  ~fill: fill :: MaybeColor = #false,

  ~line: line :: MaybeColor = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~bound: bound :: BoundingBoxMode = #'unit

) :: Pict

 

method

method (radial :: Radial).path() :: Path

Converts a Radial to a pict or a DC path.

A DC path for a radial places the middle of the shape at the origin, so it extends up to half the shape’s width in each direction horizontally, and up to half the shape’s height in each direction vertically.

> polygon_radial().pict(~fill: "orange")

image

> polygon_radial(~width: 64).path().bounding_box()

Rect(-30.433808521444913, -32.0, 60.86761704288982, 57.88854381999832)

function

fun radials_pict(

  radial :: Radial, ...,

  ~fill: fill :: MaybeColor = #false,

  ~line: line :: MaybeColor = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~bound: bound :: BoundingBoxMode = #'unit

) :: Pict

Combines multiple Radials to a pict. Nested radials creates holes in the same way as #'odd_even polygon rendering.

> radials_pict([polygon_radial(~width: 64),

                gear_radial(~width: 52)],

               ~fill: "orange")

image

function

fun evenly_spaced(i :: Int, out_of_n :: Int) :: Real

 

function

fun jitter_spaced(jitter :: Real) :: Function.of_arity(2)

Functions useful for ~angle_at arguments to radial_pict.

The function returned by jitter_spaced takes the angle that it would otherwise return an adjust it based on a math.sin of the angle times jitter. The default ~angle_at argument for cloud is jitter_spaced(0.3).

> radial_pict(~points: 5, ~angle_at: jitter_spaced(0.2))

image

annotation

BoundingBoxMode

Satisfied by a bounding-box mode: #'unit, #'unit, #'shrink, or #'stretch.