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