#TODO: ( code modified you now pass sketcher to a new Turtle instance ) but theory below is very similar.
demo project: https://github.com/nanjizal/cornerContourWebGLTurtle
Sometimes it can be easier to draw using simple turtle graphics. Turtle style graphics allows you to define drawing as if your controlling a turtle, with rotation and movement commands, these commands can be chained together as a sequence:
public function turtleTest(){
var s = new Sketcher( pen2D, Fine, both );
s.setPosition( 100, 100 )
.penSize( 7 )
.forward( 30 )
.right( 45 )
.forward( 30 )
.arc( 50, 120 );
}
Specific turtle related commands provided from Sketcher class, these are designed to be easily chained. There is a simple repeat that allows non nested multiple repeat of commands.
- penUp() or penup() or up()
- penDown() or pendown() or down()
- movePen( x, y );
s.penUp();
s.penDow();
s.movePen(100,100);
- left( degrees ) or lt( degrees )
- right( degrees ) or turn( degrees ) or rt( degrees )
- north()
- south()
- east()
- west()
- setAngle( degrees )
s.left( 45 );
s.right( 45 );
s.north();
s.south();
s.east();
s.west();
s.setAngle( 90 )
- forward( distance ) or fd( distance )
- backward( distance ) or bk( distance )
- setPosition( x, y ) or goto( x, y ) or setposition( x, y ) does not draw.
s.forward( 100 );
s.backward( 100 );
s.setPosition( 300, 300 );
- circle( radius ) normally draws 24 sides, but you can specify different number in second argument
- arc( radius, degrees ) normally draws 24 sides, but you can specify different number in second argument
s.circle( 100 );
var square = 4; // untested
s.circle( 100, square );
s.arc( 100, 45 );// quarter pie
- repeatBegin( repeatCount ) or loop( repeatCount ) or repeat( repeatCount )
- endRepeat() or loopEnd() or repeatEnd()
// pentagram or star?
s.repeatBegin( 7 ).forward( 300 ).right( 144 ).endRepeat();
- forwardChange( deltaDistance ) ie +=
- forwardFactor( factor ) ie *=
// can experiment with forward commands changing size in loop iteration
s.forward(300).right(144).repeatBegin( 6 ).forwardChange( -10 ).right( 144 ).endRepeat();
Curved Distance, similar to forward, but uses 'distance2' and 'radius' to define a third point relative to the current vector.
- archBezier( distance, distance2, radius ) ends up same place as forward but arches using quad bezier
- triangleArch( distance, distance2, radius ) ends up same place as forward but triangles from the line
- penSize( width ) or pensize( width )
- penColor( r, g, b ) or pencolor( r, g, b )
- penColorChange( r, g, b )
s.penSize( 50 ); //very thick line
s.penColor( 1, 0, 0 ); // red pen
s.circle( 100 );
- black()
- blue()
- green()
- cyan()
- red()
- magenta()
- yellow()
- white()
- brown()
- lightBrown()
- darkGreen()
- darkishBlue()
- tan()
- plum()
- grey()
s.plum(); // plum colored circle
s.circle();
- penColorB( r, g, b )
- penColorC( r, g, b )
- penColorChangeB( r, g, b )
- penColorChangeC( r, g, b )
Limited support for fill, mostly useful for filling circle, but limited use with curve / triangle related commands
- fillOn() or fillon()
- fillOff() or filloff()
s.fillOn();
s.circle( 100 ); // dot
s.fillOff();
- toRadians( degrees ) converts degrees to radians
- position() provides current position
- heading() provides current angle
- onTurtleHistory = true
- drawHistory( start, end ) // so you can setPosition and setAngle and draw again somewhere else or perhaps save to disc in future.