Simple turtle graphics: Difference between revisions

m
m (→‎{{header|Julia}}: orientation)
Line 20:
 
function house(🐢, x, y, siz)
oldorientation = 🐢.orientation
# house wall
Reposition(🐢, x, y)
Rectangle(🐢, siz, siz)
# roof
HueShift(🐢)
Reposition(🐢, x - siz / 2, y - siz / 2)
Turn(🐢, -60)
Line 32 ⟶ 34:
doorheight, doorwidth = siz / 2, siz / 4
Pencolor(🐢, 0, 0, 0)
HueShift(🐢)
Reposition(🐢, x, y + doorheight / 2)
Rectangle(🐢, doorwidth, doorheight)
# window
windowheight, windowwidth = siz /3, siz / 4
HueShift(🐢)
Reposition(🐢, x + siz / 4, y - siz / 4)
Rectangle(🐢, windowwidth, windowheight)
Reposition(🐢, x - siz / 4, y - siz / 4)
Rectangle(🐢, windowwidth, windowheight)
Orientation(🐢, oldorientation)
end
 
function barchart(🐢, data, x, y, siz)
oldorientation = 🐢.orientation
maxdata = maximum(data)
# scale to fit within a square with sides `siz` and draw bars of chart
Line 50 ⟶ 56:
for n in data # draw each bar in chart
barheight = n * siz / maxdata
HueShift(🐢)
Reposition(🐢, x, y - barheight / 2)
Rectangle(🐢, barwidth, barheight)
x += barwidth
end
Orientation(🐢, oldorientation)
end
 
4,102

edits