Simple turtle graphics: Difference between revisions

Added XPL0 example.
(Simple turtle graphics in FreeBASIC)
(Added XPL0 example.)
Line 1,195:
Similar to Quackery image except that the house has a door and a single window.
</pre>
 
=={{header|XPL0}}==
[[File:TurtleXPL0.gif|right]]
<syntaxhighlight lang "XPL0">
def ScrW=320, ScrH=200;
def Pi = 3.141592654;
def D2R = Pi/180.0;
real Dir, PosX, PosY;
int Pen;
def \Pen\ Up, Down;
 
proc Turn(Ang);
real Ang;
Dir:= Dir + Ang*D2R;
 
proc MoveTo(Dist);
real Dist;
[PosX:= PosX + Dist*Cos(Dir);
PosY:= PosY + Dist*Sin(Dir);
if Pen = Down then
Line(ScrW/2+fix(PosX), ScrH/2-fix(PosY), $0F \white\)
else
Move(ScrW/2+fix(PosX), ScrH/2-fix(PosY));
];
 
proc Rectangle(Width, Height);
real Width, Height;
int N;
[for N:= 1 to 2 do
[MoveTo(Width);
Turn(90.0);
MoveTo(Height);
Turn(90.0);
];
];
 
proc BarGraph(List, Len, Size);
real List; int Len; real Size;
real PosX0;
int N;
def BarWidth = 0.4;
[PosX0:= PosX;
for N:= 0 to Len-1 do
[Rectangle(Size*BarWidth, List(N)*Size);
MoveTo(Size*BarWidth);
];
PosX:= PosX0;
];
 
proc Triangle(Size);
real Size;
int N;
[for N:= 1 to 3 do
[MoveTo(Size);
Turn(-120.0);
];
];
 
proc Square(Size);
real Size;
Rectangle(Size, Size);
 
proc House(Size);
real Size;
[Turn(180.0);
Square(Size);
Triangle(Size);
Turn(180.0);
];
 
[SetVid($13); \set VGA graphics
Move(ScrW/2, ScrH/2); \start Line at center
Dir:= 0.0; PosX:= 0.0; PosY:= 0.0; Pen:= Down;
House(80.0);
Pen:= Up; MoveTo(10.0); Pen:= Down;
BarGraph([0.5, 1.0/3.0, 2.0, 1.3, 0.5], 5, 50.0);
]</syntaxhighlight>
 
=={{header|Yabasic}}==
291

edits