Simple turtle graphics: Difference between revisions

Added solution for Action!
(Simple implementation that draws shapes onto a two dimensional grid.)
(Added solution for Action!)
Line 13:
 
::* Both functions should return the turtle to the location it was at and facing in the same direction as it was immediately before the function was executed.
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "D2:TURTLE.ACT" ;from the Action! Tool Kit
 
PROC Rectangle(INT w,h)
BYTE i
 
FOR i=1 TO 2
DO
Forward(h)
Left(90)
Forward(w)
Left(90)
OD
RETURN
 
PROC Square(INT w)
Rectangle(w,w)
RETURN
 
PROC Triangle(INT w)
BYTE i
 
FOR i=1 TO 3
DO
Forward(w)
Right(120)
OD
RETURN
 
PROC House(INT w)
Left(90)
Square(w)
Triangle(w)
Right(90)
RETURN
 
INT FUNC GetMax(INT ARRAY a INT count)
INT i,max
 
max=0
FOR i=0 TO count-1
DO
IF a(i)>max THEN
max=a(i)
FI
OD
RETURN (max)
 
PROC BarChart(INT ARRAY a INT count,w)
INT max,st,i
 
IF count=0 THEN RETURN FI
max=GetMax(a,count)
st=w/count
Right(90)
FOR i=0 TO count-1
DO
Rectangle(a(i)*w/max,st)
Forward(st)
OD
Left(180)
Forward(w)
RETURN
 
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
INT ARRAY a=[50 33 200 130 50]
 
Graphics(8+16)
COLOR1=$0C
COLOR2=$02
 
Color=1
SetTurtle(150,110,90)
House(75)
Color=0
Right(90)
Forward(5)
Left(90)
 
Color=1
BarChart(a,5,100)
Right(90)
Forward(5)
Right(90)
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Simple_turtle_graphics.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
Line 186 ⟶ 280:
end main;
</lang>
 
 
=={{header|Julia}}==
Anonymous user