Creative coding with tiles
Created: 2021-05-17. Modified: 2021-05-22.
#
IntroductionIn this article, we will create the following visualisation by Roni Kaufman.
This visualisation is a combination of 8 different tiles (with random orientations). The 8 tiles are:
#
1. Set up a gridIn the following, we will use the basic_rules
setting which switches
off the R support. We do that because only one function from R is needed
(the seq
function). In this case, the prefix R::
is used to call the
function without loading the entire library.
Notes
CENTER
is a variable from the p5.js library.imageMode
andrectMode
adjust the coordinates setting such that images and rectangles are drawn centering at the coordinates provided (rather than from the top-left corner).- Further detail of the commands can be found at the p5 reference page.
#
Result#
2. Add tilesOnce a grid is created, what’s left is to add more tiles and lay them on
the grid. The tiles are created using the two primitive functions,
circle
and rect
(and coloured using background
, fill
and
stroke
). For example, for the first tile, two circles are placed at
each of the four corners, and a circle is placed in the middle. The
other tiles can be created in a similar way. Here is the full listing of
the code.
Notes
- The
random
function samples an element from an array of objects. HALF_PI
andPI
are variables from p5.js- We have converted the call
image(..., x, y)
into two calls -translate(x, y)
followed byimage(..., 0, 0)
- to include the random rotation. The extra work is needed because styling commands from p5.js affect all subsequent operations, so they must follow a strict order. For the same reason, the functionspush
andpop
are used to add a scope to the styling commands. - (If you wonder why the commands for drawing the tiles are not
abstracted out, it is because these commands must live inside the
draw
andsetup
functions to work.)
#
Result#
Credits / ReferenceAll credits go to Roni Kaufman. The original visualisation is hosted here.