Makie to Simulate Turing Machine Tape

Julia Makie supports recording of animated gif, etc. I wish to utilize this feature to create an animation of a Turing machine’s tape. I’d like the tape to appear such as follows (created using HTML) …

My attempt at this in Julia appears below …

using CairoMakie
function mainFunction()
  figure = Figure()
  colgap!( figure.layout, 0 )
  Textbox( figure[1,1], placeholder = "☐", bordercolor = :black, cornerradius = 0, borderwidth = 2 )
  Textbox( figure[1,2], placeholder = "A", bordercolor = :black, cornerradius = 0, borderwidth = 2 )
  Textbox( figure[1,3], placeholder = "B", bordercolor = :black, cornerradius = 0, borderwidth = 2 )
  Textbox( figure[1,4], placeholder = "C", bordercolor = :black, cornerradius = 0, borderwidth = 2 )
  Textbox( figure[1,5], placeholder = "☐", bordercolor = :black, cornerradius = 0, borderwidth = 2 )
  save( "Turing_machine_tape.png", figure )
end # function mainFunction
mainFunction()

The above Julia program creates an image that suffers from the following “deficiencies” …

  • has tape cells farther apart than I would like (as I wish to display as many cells as possible horizontally)
  • does not have uniform cell-width (A, B, C cells seem narrower than :white_medium_square: cells)
  • does not have cell contents in black (as A, B, C, and :white_medium_square: appear to be grey)

How may I correct these “deficiencies” in the Julia-generated image?

Here’s one way you can do this. I wouldn’t use Textbox etc. because those block objects are relatively heavy and not nice for animation. Much easier to handle this with plain plot objects.

using CairoMakie

f = Figure()
ax = Axis(f[1, 1], autolimitaspect = 1)
hidedecorations!(ax)
hidespines!(ax)

letters = string.('A':'Z')

cellsize = (20, 25)
xs = cumsum(fill(cellsize[1], length(letters)))
poly!(
    ax, [Rect2f((x, 0) .- 0.5 .* cellsize, cellsize) for x in xs],
    color = [i == 10 ? :rosybrown1 : :gray95 for i in eachindex(letters)],
    strokecolor = :black,
    strokewidth = 1
)
text!(
    ax, xs, zeros(length(letters)),
    text = letters,
    align = (:center, :center),
    markerspace = :data
)
scatter!(ax, xs[10], cellsize[2] / 2 + 10, marker = :dtriangle, color = :red)
f

3 Likes

Thank you for this information.