Simple turtle graphics: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: factored out some common code for the 3D version)
m (syntax highlighting fixup automation)
Line 16: Line 16:
=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "D2:TURTLE.ACT" ;from the Action! Tool Kit
<syntaxhighlight lang="action!">INCLUDE "D2:TURTLE.ACT" ;from the Action! Tool Kit


PROC Rectangle(INT w,h)
PROC Rectangle(INT w,h)
Line 104: Line 104:
DO UNTIL CH#$FF OD
DO UNTIL CH#$FF OD
CH=$FF
CH=$FF
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Simple_turtle_graphics.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Simple_turtle_graphics.png Screenshot from Atari 8-bit computer]


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>
<syntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters; use Ada.Characters;
with Ada.Characters; use Ada.Characters;
Line 279: Line 279:
New_Line;
New_Line;
end main;
end main;
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==
Line 285: Line 285:


Prerequisites (requires a network connection or, for a non-networked system, significant technical savvy), and assumes user is running the a recent version of J's qtide (perhaps J 9.3):
Prerequisites (requires a network connection or, for a non-networked system, significant technical savvy), and assumes user is running the a recent version of J's qtide (perhaps J 9.3):
<lang J> ;install each cut 'gl2 gles github:zerowords/tgsjo'</lang>
<syntaxhighlight lang="j"> ;install each cut 'gl2 gles github:zerowords/tgsjo'</syntaxhighlight>


Implementation (note that this is meant to be copied and pasted to a file which J will load, rather than being typed in line by line -- manual typing would work if no errors were made, but that would be a painstaking approach):
Implementation (note that this is meant to be copied and pasted to a file which J will load, rather than being typed in line by line -- manual typing would work if no errors were made, but that would be a painstaking approach):


<lang J>load'zerowords/tgsjo'
<syntaxhighlight lang="j">load'zerowords/tgsjo'
rotR 0 0 _90
rotR 0 0 _90
translate 0 0 _40
translate 0 0 _40
Line 346: Line 346:
forward 10
forward 10
left 270
left 270
pen 1</lang>
pen 1</syntaxhighlight>


Opens a window with the indicated content. House is red, barchart is blue.
Opens a window with the indicated content. House is red, barchart is blue.
Line 355: Line 355:
{{trans|Wren}}
{{trans|Wren}}
Outputs a PNG file.
Outputs a PNG file.
<lang julia>using Luxor, Colors
<syntaxhighlight lang="julia">using Luxor, Colors


function house(🐢, x, y, siz)
function house(🐢, x, y, siz)
Line 415: Line 415:


testturtle()
testturtle()
</syntaxhighlight>
</lang>


=={{header|Logo}}==
=={{header|Logo}}==
Line 421: Line 421:
{{trans|Quackery}}
{{trans|Quackery}}


<lang Logo>to rectangle :width :height
<syntaxhighlight lang="logo">to rectangle :width :height
repeat 2 [
repeat 2 [
forward :height
forward :height
Line 471: Line 471:
pendown
pendown
barchart [ 0.5 0.33333 2 1.3 0.5 ] 200
barchart [ 0.5 0.33333 2 1.3 0.5 ] 200
left 90 back 10 right 90</lang>
left 90 back 10 right 90</syntaxhighlight>


{{out}}
{{out}}
Line 479: Line 479:
=={{header|Perl}}==
=={{header|Perl}}==
Added octangle window to house attic.
Added octangle window to house attic.
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl


use strict; # https://rosettacode.org/wiki/Simple_turtle_graphics
use strict; # https://rosettacode.org/wiki/Simple_turtle_graphics
Line 615: Line 615:
pendown;
pendown;
graph( 400, 2,7,4,5,1,8,6 );
graph( 400, 2,7,4,5,1,8,6 );
}</lang>
}</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Line 622: Line 622:
You can run this online [http://phix.x10.mx/p2js/simpleturtlegraphics.htm here].<br>
You can run this online [http://phix.x10.mx/p2js/simpleturtlegraphics.htm here].<br>
I factored out some common code for the 2D and 3D versions (or started to, distributed version contains some additional diag aids)
I factored out some common code for the 2D and 3D versions (or started to, distributed version contains some additional diag aids)
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\turtle.e</span>
<span style="color: #000080;font-style:italic;">-- demo\rosetta\turtle.e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 637: Line 637:
<span style="color: #000000;">pen_down</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #000000;">pen_down</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Simple_turtle_graphics.exw
-- demo\rosetta\Simple_turtle_graphics.exw
Line 789: Line 789:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Python}}==
=={{header|Python}}==
{{trans|Quackery}}
{{trans|Quackery}}


<lang Python>from turtle import *
<syntaxhighlight lang="python">from turtle import *


def rectangle(width, height):
def rectangle(width, height):
Line 838: Line 838:
penup()
penup()
back(10)
back(10)
pendown()</lang>
pendown()</syntaxhighlight>


{{out}}
{{out}}
Line 846: Line 846:
=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ $ "turtleduck.qky" loadfile ] now!
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!


[ behead do
[ behead do
Line 897: Line 897:
10 1 fly
10 1 fly
' [ [ 1 2 ] [ 1 3 ] [ 2 1 ] [ 13 10 ] [ 1 2 ] ] 200 1 barchart
' [ [ 1 2 ] [ 1 3 ] [ 2 1 ] [ 13 10 ] [ 1 2 ] ] 200 1 barchart
-10 1 fly</lang>
-10 1 fly</syntaxhighlight>


{{output}}
{{output}}
Line 906: Line 906:
{{libheader|DOME}}
{{libheader|DOME}}
{{libheader|Wren-turtle}}
{{libheader|Wren-turtle}}
<lang ecmascript>import "dome" for Window
<syntaxhighlight lang="ecmascript">import "dome" for Window
import "graphics" for Canvas, Color
import "graphics" for Canvas, Color
import "./turtle" for Turtle
import "./turtle" for Turtle
Line 991: Line 991:
}
}


var Game = Main.new(600, 600)</lang>
var Game = Main.new(600, 600)</syntaxhighlight>


{{out}}
{{out}}
Line 1,000: Line 1,000:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
{{trans|Python}}
{{trans|Python}}
<lang Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Simple_turtle_graphics
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Simple_turtle_graphics
// Adapted from Python to Yabasic by Galileo, 01/2022
// Adapted from Python to Yabasic by Galileo, 01/2022


Line 1,067: Line 1,067:
move(10)
move(10)
pen(true)
pen(true)
barchart("0.5 0.333 2 1.3 0.5", 200)</lang>
barchart("0.5 0.333 2 1.3 0.5", 200)</syntaxhighlight>