Documentation
¶
Index ¶
- Constants
- Variables
- func Deg2rad(deg float64) float64
- func Rad2deg(rad float64) float64
- type CmdType
- type Instruction
- type Line
- type Pen
- type Turtle
- func (t *Turtle) Backward(dist float64)
- func (t *Turtle) DoInstruction(i Instruction)
- func (t *Turtle) Forward(dist float64)
- func (t *Turtle) Left(deg float64)
- func (t *Turtle) Right(deg float64)
- func (t *Turtle) SetHeading(deg float64)
- func (t *Turtle) SetPos(x, y float64)
- func (t *Turtle) String() string
- type TurtleDraw
- type World
Constants ¶
const ( East = 0.0 North = 90.0 West = 180.0 South = 270.0 )
Standard directions.
Variables ¶
var ( Black = color.RGBA{0, 0, 0, 255} SoftBlack = color.RGBA{10, 10, 10, 255} White = color.RGBA{255, 255, 255, 255} Red = color.RGBA{255, 0, 0, 255} Green = color.RGBA{0, 255, 0, 255} Blue = color.RGBA{0, 0, 255, 255} Cyan = color.RGBA{0, 255, 255, 255} Magenta = color.RGBA{255, 0, 255, 255} Yellow = color.RGBA{255, 255, 0, 255} // I just love this one DarkOrange = color.RGBA{150, 75, 0, 255} )
Standard colors.
Functions ¶
Types ¶
type Instruction ¶ added in v0.3.0
An action for the turtle.
type Pen ¶
type Pen struct { Color color.Color // Line color. Size int // Line width. On bool // State of the Pen. }
A simple Pen.
type Turtle ¶
A minimal Turtle agent, moving on a cartesian plane.
https://en.wikipedia.org/wiki/Turtle_graphics
func (*Turtle) DoInstruction ¶ added in v0.3.0
func (t *Turtle) DoInstruction(i Instruction)
Execute the received instruction.
type TurtleDraw ¶
type TurtleDraw struct { Turtle // Turtle agent to move around. Pen // Pen used when drawing. W *World // World to draw on. }
A drawing Turtle.
func NewTurtleDraw ¶
func NewTurtleDraw(w *World) *TurtleDraw
Create a new TurtleDraw, attached to the World w.
func (*TurtleDraw) Backward ¶
func (td *TurtleDraw) Backward(dist float64)
Move the turtle backward and draw the line if the Pen is On.
func (*TurtleDraw) DoInstruction ¶ added in v0.3.0
func (td *TurtleDraw) DoInstruction(i Instruction)
Execute the received instruction.
func (*TurtleDraw) Forward ¶
func (td *TurtleDraw) Forward(dist float64)
Move the turtle forward and draw the line if the Pen is On.
func (*TurtleDraw) SetPos ¶
func (td *TurtleDraw) SetPos(x, y float64)
Teleport the Turtle to (x, y) and draw the line if the Pen is On.
func (*TurtleDraw) String ¶
func (td *TurtleDraw) String() string
Write the TurtleDraw state.
Implements: fmt.Stringer
type World ¶
type World struct { Image *image.RGBA Width, Height int DrawLineCh chan Line // contains filtered or unexported fields }
A world to draw on.
func NewWorldWithColor ¶ added in v0.2.0
Create a new World of the requested size and background color.
func NewWorldWithImage ¶ added in v0.2.0
Create a new World attached to an image.
func (*World) Close ¶
func (w *World) Close()
Close the world channels, and stop the listen goroutine.
func (*World) ResetImage ¶ added in v0.2.0
func (w *World) ResetImage()
Reset the current image, keep the current size, default background color.
func (*World) ResetImageWithImage ¶ added in v0.2.0
Reset the current image to the provided one.
func (*World) ResetImageWithSize ¶ added in v0.2.0
Reset the current image, changing the size, default background color.
func (*World) ResetImageWithSizeColor ¶ added in v0.2.0
Reset the current image, changing the size and background color.