Created
September 21, 2017 04:37
-
-
Save shabbychef/998ab3c21f35124dba6111dae33e696c to your computer and use it in GitHub Desktop.
make a maze in jslogo
This file contains 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
To fwdit :length :segs | |
forward :length*:segs | |
end | |
To bckit :length :segs | |
back :length*:segs | |
end | |
To holey_line :length :segs | |
local "whicho | |
make "whicho (random 1 :segs) | |
pendown | |
fwdit :length (:whicho - 1) | |
penup | |
fwdit :length 1 | |
pendown | |
fwdit :length (:segs - :whicho) | |
penup | |
bckit :length :segs | |
end | |
To noholey_line :length :segs | |
pendown | |
fwdit :length :segs | |
penup | |
bckit :length :segs | |
end | |
To maybe_holey_line :length :segs :sernum :noholenum | |
ifelse (:sernum = :noholenum) | |
[ noholey_line :length :segs ] | |
[ holey_line :length :segs] | |
end | |
To inner_maze :wid :hgt :length | |
if (and (:wid > 1) (:hgt > 1)) [ | |
local "rwid | |
local "bhgt | |
Local "lwid | |
local "thgt | |
local "holeser | |
make "rwid (random 1 (:wid - 1)) | |
make "bhgt (random 1 (:hgt - 1)) | |
make "lwid (:wid - :rwid) | |
make "thgt (:hgt - :bhgt) | |
make "holeser (random 1 4) | |
penup | |
fwdit :length :bhgt | |
right 90 | |
fwdit :length :lwid | |
left 90 | |
maybe_holey_line :length :thgt 1 :holeser | |
right 90 | |
maybe_holey_line :length :rwid 2 :holeser | |
right 90 | |
maybe_holey_line :length :bhgt 3 :holeser | |
right 90 | |
maybe_holey_line :length :lwid 4 :holeser | |
right 90 | |
left 90 | |
fwdit :length :lwid | |
left 90 | |
fwdit :length :bhgt | |
right 180 | |
inner_maze :lwid :bhgt :length | |
fwdit :length :bhgt | |
inner_maze :lwid :thgt :length | |
right 90 | |
fwdit :length :lwid | |
left 90 | |
inner_maze :rwid :thgt :length | |
bckit :length :bhgt | |
inner_maze :rwid :bhgt :length | |
left 90 | |
fwdit :length :lwid | |
right 90 | |
] | |
end | |
To outer_maze :wid :hgt :length | |
inner_maze :wid :hgt :length | |
repeat 2 [ | |
holey_line :length :hgt | |
fwdit :length :hgt | |
right 90 | |
noholey_line :length :wid | |
fwdit :length :wid | |
right 90 | |
] | |
end | |
clearscreen | |
cleartext | |
hideturtle | |
rerandom | |
setpos [ -700 -400 ] | |
outer_maze 72 36 18 |
And you will want to ditch the rerandom
otherwise you should get the same maze every time...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this in a logo interpreter, like jslogo.