Rainbow Labyrinths

Rainbow Labyrinths is a little demo by Mad Wizard Software, written in Logo, that shows a variety of curves defined by (a certain type of) Lindenmayer systems, drawn using turtle graphics with a 'chameleon turtle' adopting all the colours of the rainbow. All of these curves are self-avoiding, while most are also grid-filling with respect to either a square or hexagonal grid.

The program is heavily inspired by the book Brainfilling Curves by Jeffrey Ventrella, in which all of the curves shown can also be found.

Rainbow Labyrinths is free software published under a BSD license, and its users are encouraged to modify, and experiment with, the program.

Rainbow Labyrinths is small: the full program uses a mere 3924 bytes.

WARNING, the program is quite CPU-heavy when running on at least my machine, so make sure not to overheat your CPU!

Downloads

Rainbow Labyrinths 1.0 can be downloaded here (2609 bytes).

View the demo on Youtube

A full run of Rainbow Labyrinths can be watched here.

Screenshots

Below you can see the sixteen screens that appear in Rainbow Labyrinths:

Code listing

LICENSE

Copyright 2021 Joost Winter (a.k.a. Mad Wizard Software)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

rainbowlabyrinths.lg

; Rainbow Labyrinths 1.0
;
; a 2021 demo for/in Berkeley Logo by
;
; Mad Wizard Software (Joost Winter)
;
; Feel free to use, re-use, and modify!

; 1. Mathematical routines

to klein :x :y
if :x = "a [op :y]
if :y = "a [op :x]
if :x = :y [op "a]
if not or :x = "e :y = "e [op "e]
if not or :x = "o :y = "o [op "o]
op "u
end

to abs :x
op ifelse :x < 0 -:x :x
end

; 2. Core fractal routines

to transform :lst
(local "f "i "b "l)
if emptyp :lst [op []]
make "f first :lst
ifelse :f = uppercase :f [
	make "l :len * (sqrt first bf :lst)
	make "r transform bf bf :lst
][
	make "l :len
	make "r transform bf :lst
]
make "i ifelse memberp :f [b d] [
	(se "my.fd quoted :f :len)
][
	ifelse memberp :f [r l] [
		se "my.rt ifelse (memberp :trf [e o]) = (:f = "r) [
			-:ang
		][
			:ang
		]
	][
		(se "fractal quoted klein :trf lowercase :f :itr - 1 :l)
	]
]
if memberp :trf [o u] [op se :r :i]
op se :i :r
end

to fractal :trf :itr :len
run transform ifelse :itr = 0 [:bas] [:rec]
end

; 3. Counting routines

to my.count :lst :keylst
op ifelse emptyp :lst [
	0
][
	(my.count bf :lst :keylst) + (ifelse memberp first :lst :keylst
		1 0)
]
end

to compute :rec :fac :bas :itr
if :itr = 0 [op :bas]
op :rec + :fac * (compute :rec :fac :bas :itr - 1)
end

; 4. Rainbow routines

to getrgb
make "h 6 * :cnt / :max
make "x 100 * (1 - (abs (modulo :h 2) - 1))
if :h < 1 [op (se 100 :x 0)]
if :h < 2 [op (se :x 100 0)]
if :h < 3 [op (se 0 100 :x)]
if :h < 4 [op (se 0 :x 100)]
if :h < 5 [op (se :x 0 100)]
op (se 100 0 :x)
end

to init :x
make "cnt 0
make "max :x
make "dir 0
end

to my.fd :k :n
setpc 8 + (int 248 * :cnt / :max)
make "cnt :cnt + 1
ifelse :k = "b [
	rt :dir
][
	if :dir = 90 [rt 45 fd :n rt 45]
	if :dir = 270 [lt 45 fd :n lt 45]
	if :dir = 120 [rt 60 fd :n rt 60]
	if :dir = 240 [lt 60 fd :n lt 60]
	if or :dir = 60 :dir = 300 [rt :dir]
	if :dir = 0 [
		fd ifelse :ang = 60 [
			:n * 2
		][
			:n * (1 + 1 / sqrt 2)
		]
	]
]
make "dir 0
fd :n
end

to my.rt :x
make "dir modulo :dir + :x 360
end

; 5. Wrapper routines

to draw :bas :rec :ang :itr :len
init compute my.count :rec [d b] my.count :rec [a o e u A O E
	U] my.count :bas [d b] :itr
fractal "a :itr :len
end

to cast :bas :rec :ang :itr :len :x :y :h
pu
setxy :x :y
seth :h
pd
draw :bas :rec :ang :itr :len
end

; 6. Time for magick

make "spellbook [
	["d "rellur 45 13 3 -459 -205 90]
	["d "arralla 60 8 4 421 267 0]
	["d "lerarel 60 8 3 -387 -305 90]
	["d "rallorr 45 12 4 259 -75 90]
	["d "lurarole 90 7 3 -4 -302 45]
	["d "loararola 90 5 3 -15 323 0]
	[" "lodradardol 90 7 2 319 -294 0]
	["b "lO2rarrall 45 8 2 263 -56 -60]
	["b "llarrrA2lo 45 8 2 152 222 -120]
	["d "relluerrel 60 6 4 337 -166 -60]
	["d "lararalalar 90 5 4 268 14 45]
	["b "alollorarraarol 60 4 10 268 106 0]
	["d "uullellurrurree 60 4 6 -441 26 90]
	[" "adedardredadeldladeda 90 4 3 -290 -300 0]
	["b "lleurrurrurrrO3llllleu 30 4 6 -243 -114 90]
]

to screen :x
cs fs ht
window
ifelse :x < 16 [
	run se "cast item :x :spellbook
][
	xyzzy
]
wait 180
st
end

to demo
repeat 16 [screen #]
end

; 7. And now the dragons...

make "dragons reverse [
	[0 3 1 6] [-2 0 2 4] [2 -2 3 4]
	[1 3 1 6] [-2 1 2 4] [2 -3 3 4]
	[-1 4 1 6] [-2 -1 2 4] [2 -1 3 4]
	[-2 2 2 4] [2 -4 3 4]
	[-2 -2 2 4] [2 0 3 4]
	[-2 3 2 3] [0 -3 3 2]
	[0 -3 2 2] [2 1 3 3]
]

to xyzzy
repeat count :dragons [
	run se "summon item # dragons
]
end

to summon :k :l :n :r
pu home
rt 30 fd :k * 280.59223
rt 60 fd :l * 280.59223
rt (:n - 1) * 120 + 30
; adjustment
bk 6
pd
repeat :r [draw "d "arralla 60 5 6]
end

; 8. Initialization and startup message

make "caseignoredp "false
init 248
repeat 248 [
	setpalette :cnt + 8 getrgb
	make "cnt :cnt + 1
]

pr [] pr [Rainbow Labyrinths 1.0]
pr [Mad Wizard Software 2021]
pr [Type demo to show all screens,]
pr [or screen \[1-16\] for individual screens.]
pr [] pr [Shoutout to Jeffrey Ventrella, whose book Brainfilling Curves]
pr [has been a major inspiration for this demo!]