I recently came across a Truchet Tiling sketch by Jim Bumgardner where he created off screen images of the tiles and had a neat trick to avoid double nested loops when creating the grid. It seemed to me this was an ideal case to use the ruby-processing grid
method to generate the grid in JRubyArt:-
DIM = 24
attr_reader :tiles, :images
def make_image(dim, alternate = false)
create_graphics(dim, dim, P2D).tap do |g|
g.smooth(4)
g.begin_draw
g.background(255)
g.stroke(0)
g.stroke_weight(4)
g.no_fill
g.ellipse_mode(RADIUS)
if alternate
g.ellipse(0, dim, dim / 2, dim / 2)
g.ellipse(dim, 0, dim / 2, dim / 2)
else
g.ellipse(0, 0, dim / 2, dim / 2)
g.ellipse(dim, dim, dim / 2, dim / 2)
end
g.end_draw
end
def setup
sketch_title 'Truchet Tiling'
@images = [make_image(DIM), make_image(DIM, true)]
@tiles = []
grid(width, height, DIM, DIM) do |posx, posy|
tiles << Tile.new(Vec2D.new(posx, posy))
end
no_loop
end
def draw
background(255)
tiles.each(&:render)
end
def settings
size(576, 576, P2D)
smooth(4)
end
end
class Tile
include Processing::Proxy
attr_reader :vec, :img
def initialize(vec)
@vec = vec
@img = images.sample
end
def render
image(img, vec.x, vec.y, img.width, img.height)
end
end
Here is snapshot:-
So the there was diagonal variation:-
And a hybrid:-