Skip to content

Patterns

How to fill a shape with copies of another shape: dots, stripes, checks, flowers, or anything you can draw.


fill … with

fill ball with dot

Fills the first shape with copies of the second, in rows, side by side. The copies stay inside the shape's outline.

circle dot having radius 5, fill "navy"
draw circle ball at 150, 150 having radius 100, fill "yellow"
fill ball with dot

The shape you copy is usually made without draw, like dot here, so it doesn't show on its own. Any shape can be copied: a circle, a square, a line, a shape with parts, or your own recipe.

shape flower having petals "pink" {
  circle at 0, -6 having radius 5, fill petals
  circle at 6, 0 having radius 5, fill petals
  circle at 0, 6 having radius 5, fill petals
  circle at -6, 0 having radius 5, fill petals
  circle at 0, 0 having radius 4, fill "yellow"
}
flower f having petals "purple"
draw polygon dress from 160, 20 to 240, 20 to 320, 280 to 80, 280 having fill "white", thickness 3
fill dress with f having gap 4

Only shapes with an inside can be filled: a circle, an oval, a rectangle, a square, a triangle or a polygon.


gap

fill ball with dot having gap 6

The space between one copy and the next, across and down. Without it, the copies touch.

circle dot having radius 5, fill "navy"
draw circle a at 100, 150 having radius 80, fill "yellow"
draw circle b at 300, 150 having radius 80, fill "yellow"
fill a with dot
fill b with dot having gap 10

A level or upright line meets the next copy end to end, so the gap goes only between the lines. That makes stripes:

line stripe from 0, 0 to 20, 0 having color "red", thickness 10
draw square flag at 100, 50 having size 200, fill "white"
fill flag with stripe having gap 10

angle

fill flag with stripe having gap 10, angle 45

Turns the rows of copies, clockwise. The shape itself stays as it was.

line stripe from 0, 0 to 20, 0 having color "red", thickness 10
draw square flag at 100, 50 having size 200, fill "white"
fill flag with stripe having gap 10, angle 45

Turning the copied shape is different: dot.angle = 45 turns each copy where it sits, and the rows stay level.


backcolor

fill ball with dot having backcolor "pink"

The colour behind the copies. Without it, it's the colour the shape was filled with before. You can also write backcolour.


Changing a pattern

The pattern's gap, angle and backcolor are read and changed through the shape's fill, like any other property, at once or over time:

circle dot having radius 5, fill "navy"
draw circle ball at 200, 150 having radius 100, fill "yellow"
fill ball with dot having gap 4
forever {
  ball.fill.gap = 14 in 1 second
  ball.fill.gap = 4 in 1 second
}
line stripe from 0, 0 to 20, 0 having color "red", thickness 8
draw circle ball at 200, 150 having radius 100, fill "white"
fill ball with stripe having gap 8
together {
  ball.fill.angle = 180 in 4 seconds
  ball.fill.backcolor = "gold" in 4 seconds
}

Changing the copied shape changes every copy at once:

circle dot having radius 5, fill "navy"
draw circle ball at 200, 150 having radius 100, fill "yellow"
fill ball with dot having gap 6
dot.fill = "red" in 2 seconds

fill ball with star gives the ball a different shape to copy and keeps its gap, angle and backcolor. fill ball with … having gap 20 in 2 seconds changes the properties over the time you give.

Giving the fill a colour takes the pattern away: ball.fill = "red". So does fill ball with none, which leaves the backcolor. box.fill = ball.fill gives the box the ball's pattern.


Patterns inside patterns

A filled shape can be copied too. Here a row of dots fills a ball:

circle dot having radius 2, fill "red"
rectangle row having width 30, length 6, fill "white", thickness 0
fill row with dot
draw circle ball at 200, 150 having radius 100
fill ball with row having gap 4, angle 45

A shape can't be filled with copies of itself.