7 Pict Radial Shapes
import: pict/radial | package: rhombus-prototype |
function | ||
| ||
function | ||
| ||
function | ||
| ||
function | ||
| ||
function | ||
| ||
function | ||
| ||
function | ||
| ||
function | ||
> star(~fill: "gold")
> flash(~fill: "red")
> flower(~fill: "purple")
> cloud(~fill: "gray")
> polygon(~fill: "blue")
> circle(~fill: "forestgreen")
> gear(~fill: "brown")
function | |||||||||||||||||||
|
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()
> radial_pict(~fill: #'inherit).colorize("red")
> radial_pict(~width: 64, ~height: 32, ~rotate: math.pi * 1/2)
> radial_pict(~inner_pause: 0.5, ~outer_pause: 0.25, ~fill: "black")
> radial_pict(~outer_pull: 0.25, ~fill: "purple")
> radial_pict(~inner_pull: 0.25, ~fill: "forestgreen")
> radial_pict(~outer_pull: 0.25, ~inner_radius: -0.5, ~fill: "lightblue")
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)))
annotation | |||||||||||||||
| |||||||||||||||
function | |||||||||||||||
|
For example, gear uses radials_pict to combine gear arms with a hole when a non-zero hold is requested.
> r.pict(~fill: "blue")
> r.pict(~line: "blue", ~line_width: 3)
function |
|
function |
|
function |
|
function |
|
function |
|
function |
fun polygon_radial(~sides: n :: PosInt = 10, ....) :: Radial |
|
function |
|
function |
> flower_radial(~petals: 5).pict(~fill: "pink")
method | ||||||
| ||||||
| ||||||
method | ||||||
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")
> polygon_radial(~width: 64).path().bounding_box()
Rect(-30.433808521444913, -32.0, 60.86761704288982, 57.88854381999832)
function | |||||||
|
> radials_pict([polygon_radial(~width: 64),
gear_radial(~width: 52)],
~fill: "orange")
function |
|
function |
fun jitter_spaced(jitter :: Real) :: Function.of_arity(2) |
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))
annotation |