Last active
September 23, 2017 06:31
-
-
Save shabbychef/a76debaae6816af7f75cd3076f9b0c7b to your computer and use it in GitHub Desktop.
hexagonal maze generator in logo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;; | |
; | |
; hexagonal maze generator | |
; Created: 2017.09.22 | |
; Copyright: Steven E. Pav, 2017 | |
; Author: Steven E. Pav | |
;;;;;;;;;;;;;;;;;;;;;; | |
; move forward length * segs | |
To fwdit :length :segs | |
forward :length*:segs | |
end | |
; same, but draw as well | |
To draw_fwdit :length :segs | |
pendown | |
fwdit :length :segs | |
penup | |
end | |
; go back | |
To bckit :length :segs | |
back :length*:segs | |
end | |
; make a line with segs segments, where one is not drawn. | |
; a hole | |
; then go back | |
To holey_line :length :segs | |
local "whicho | |
make "whicho (random 1 :segs) | |
draw_fwdit :length (:whicho - 1) | |
fwdit :length 1 | |
draw_fwdit :length (:segs - :whicho) | |
bckit :length :segs | |
end | |
; just make a line | |
; then go back | |
To noholey_line :length :segs | |
draw_fwdit :length :segs | |
bckit :length :segs | |
end | |
; maybe one, maybe the yother | |
To maybe_holey_line :length :segs :sernum :noholenum | |
ifelse (:sernum = :noholenum) | |
[ noholey_line :length :segs ] | |
[ holey_line :length :segs ] | |
end | |
To holey_y :length :segs | |
local "coinflip | |
make "coinflip (random 1 2) | |
left 60 | |
maybe_holey_line :length :segs 1 :coinflip | |
right 120 | |
maybe_holey_line :length :segs 2 :coinflip | |
left 60 | |
end | |
; make a bone shape with a hole in the middle | |
To hole_bone :length :segs | |
fwdit (:length/2) :segs | |
repeat 2 [ | |
holey_y :length :segs | |
right 180 | |
fwdit :length :segs | |
] | |
right 180 | |
holey_line :length :segs | |
fwdit (:length/2) :segs | |
right 180 | |
end | |
; make a bone shape with no hole in the middle | |
To nohole_bone :length :segs | |
local "pyraflip | |
make "pyraflip (random 1 4) | |
fwdit (:length/2) :segs | |
for [iii 0 1] [ | |
left 60 | |
maybe_holey_line :length :segs (1+(2*:iii)) :pyraflip | |
right 120 | |
maybe_holey_line :length :segs (2+(2*:iii)) :pyraflip | |
left 60 | |
right 180 | |
fwdit :length :segs | |
] | |
right 180 | |
noholey_line :length :segs | |
fwdit (:length/2) :segs | |
right 180 | |
end | |
; make a bone | |
To maybehole_bone :length :segs | |
local "myflip | |
make "myflip (random 1 2) | |
ifelse (:myflip=1) [ | |
hole_bone :length :segs | |
] [ | |
nohole_bone :length :segs | |
] | |
end | |
To recurso :depth :length | |
local "myseg | |
make "myseg (power 2 :depth) | |
make "magirat ((sqrt 3) / 4.0) | |
right 90 | |
fwdit (:length * :magirat) :myseg | |
left 90 | |
maybehole_bone :length (:myseg/2) | |
left 90 | |
fwdit (:length * :magirat) :myseg | |
right 90 | |
if (:depth > 1) [ | |
recurso (:depth - 1) :length | |
fwdit :length :myseg | |
right 120 | |
repeat 3 | |
[ | |
fwdit (:length/2) :myseg | |
recurso (:depth - 1) :length | |
fwdit (:length/2) :myseg | |
right 60 | |
] | |
right 60 | |
fwdit :length :myseg | |
] | |
end | |
To hexo :depth :length | |
local "myseg | |
make "myseg (power 2 :depth) | |
repeat 2 [ | |
recurso :depth :length | |
right 180 | |
] | |
fwdit :length :myseg | |
right 60 | |
repeat 2 | |
[ | |
right 60 | |
holey_line :length :myseg | |
fwdit :length :myseg | |
repeat 2 [ | |
right 60 | |
noholey_line :length :myseg | |
fwdit :length :myseg | |
] | |
] | |
right 120 | |
holey_line :length (2*:myseg) | |
end | |
To clearall | |
clearscreen | |
cleartext | |
hideturtle | |
end | |
clearall | |
penup | |
forward 20 | |
right 30 | |
rerandom | |
hexo 4 13 | |
;for vim modeline: (do not edit) | |
; vim:ts=2:sw=2:tw=79:fdm=marker:fmr=FOLDUP,UNFOLD:cms=;%s:tags=.tags;:syn=logo:ft=logo:ai:si:nocin:nu:fo=cro:cino=p0t0c5(0: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment