Tiny Woodlands

As I get closer to locking down the final set of features for the 1.0 release of Calyx, I’m starting to spend a bit more time thinking about how to document examples of what it can do.

One example that I’m quite happy with is tiny_woodland. It’s a generator that prints random emoji forest scenes, influenced by the constellation of brilliant little Twitter bots based on @tiny_star_field.

🌲 🌱🌱🌻  🌳🌱🌿 🌲🌿   🌲🌿
🌲🌿 🌿🌱🌱    🌲🌲🌳  🌱🌲🌿
🌳🌿     🌲  🌼  🌿🌳🌿
🌿 🌱  🌱 🌲   🌱🌲    🌲
🌿 🌿🌲🌲🌲 🌱    🌿🌲 🌳🌻
 🌲   🌿   🌳 🌿🌲🌿🌱 🌳🌿
🌿 🌱 🌳    🌻 🌳🌻🌿🌼🌿🌼🌱🌱
🌿 🌲🌿🌱🌻🌿🌿🌳🌿 🌱🌿🌱🌲 🌳🌲

The code for generating the scenes is very simple and readable. It spreads out a couple of ranges and loops over them to automate the repetition of setting up the grid of rows and points. It then uses weighted choices to distribute a selection of trees, foliage and flowers, with whitespace being selected 50% of the time to balance things out.

require "calyx"

tiny_woodland = Calyx::Grammar.new do
  start :field
  field (0..7).map { "{row}{br}" }.join
  row (0..18).map { "{point}" }.join
  point [:trees, 0.2], [:foliage, 0.25], [:flowers, 0.05], [:space, 0.5]
  trees "🌲", "🌳"
  foliage "🌿", "🌱"
  flowers "🌷", "🌻", "🌼"
  space " "
  br "\n"
end

puts tiny_woodland.generate

Hopefully this method of building generators with a grammar is reasonably approachable for beginners and artists who aren’t full-time coders to understand.

This would be a great starting point for building a Twitter bot (or other bots, or fun little toys in general).

🌿 🌻   🌲🌻🌼  🌿 🌿
🌿🌲 🌱🌲🌱🌳🌿  🌳 🌲 🌿🌱🌱 🌳
🌲🌷🌲      🌳  🌲 🌲 🌲 🌱
🌱🌿🌳 🌳   🌷🌱🌳🌱🌳 🌱 🌲🌿
🌿  🌱🌳🌲🌱🌳🌿🌳 🌻🌳🌳   🌱
🌳 🌿  🌳 🌻🌼🌲   🌿🌲🌲🌱
🌱 🌲🌱🌱  🌲🌿🌱  🌲🌲   🌿🌳
 🌿🌲🌱🌲   🌳 🌳  🌱 🌳🌳

Update: This is now a Twitter bot, periodically posting these little emoji scenes at @tiny_woodland.