Canvas Painter — Creative Web

Painting studio: 20 levels reproducing a target image with Canvas 2D: trig, recursion, Perlin noise and batik mandalas, scored by an SSIM comparator.

What the levels ask

  1. The Agustusan mural's first panel: the red and white flag as wide as the wall, red on the top half and white on the bottom half. fillRect(x, y, w, h) fills a rectangle from its top left corner, and the canvas y axis points down. The wall hands you its size as W and H; the flag must fit a wall of any size.
  2. Rara counts the little flags on the string: the wall hands you n, the number of flags, and each flag gets a width of W / n. The for loop draws one flag on each pass and works out its x from i. Paint every flag, edge to edge along the string.
  3. Bu Sari orders red lanterns for the vigil night: three rows, six lanterns in each row, spread evenly across the wall, and the lower half of each lantern gold. arc(x, y, r, start, end) takes radians, not degrees.
  4. Bagas puts up umbul-umbul banners along the road into the village: n cloths, their hue walking evenly round the colour wheel from red, so the last cloth is almost back at red. The colour is written as an hsl(...) string with 70% saturation and 50% lightness.
  5. Pak Tono asks for the bird scarer pinwheel on top of its pole, in the middle of the wall: six red blades, one every 60°, turning round the top of the pole. For each blade: save(), move the origin to the top of the pole, rotate, draw the blade pointing straight up, then bring the state back.
  6. Nenek Marni wants the terrace edges on her slope: a green edge waving exactly two full waves from the left end to the right end of the wall, starting at the middle of the wall's height and rising first, with a yellow plot below it.
  7. Bang Arka sets up the target board for the archery contest: six rings, red and white in turn, touching with no gaps, from the edge of the board to the middle. The radii are worked out from R, half the wall's shortest side minus 8.
  8. Mak Ijah gets the krupuk ready for the krupuk-eating race, its spiral and all: an Archimedean spiral r = 3t from the middle of the krupuk, turning clockwise for four and a half turns. A point of the spiral: x = centre + r·cos t, y = centre + r·sin t.
  9. Mbah Rimba wants the square's banyan on the mural: a trunk from the middle of the wall's foot, every branch splitting in two at 30° to the left and to the right and 0.72 times as long, until the tree has 256 twigs at its tips. The function cabang calls itself twice; the trunk is depth 0.
  10. Bang Jaya paints the ridge of the hills behind the village as a Koch curve: each segment is split in three and its middle third replaced by two sides of an equilateral triangle that bulge upward. That split is repeated three times, from x = 10 to 10 pixels before the wall's right edge.
  11. Pak Tono wants his paddy plots as seen from the hill, in Dina's colour sketch: 16-pixel plots that fill the whole wall, coloured from noise2D between green and yellow, with neighbouring plots in similar colours, changing slowly like a stretch of rice.
  12. Rara and Bagas fly forty paper kites over the fields. Where they sit is random, but it must be exactly Dina's sketch every time it is painted, on another evening with another wind too (another wall seed). The paper lets half the light through.

And more, 20 levels in all.