diagrams-contrib-0.6.0.4: Collection of user contributions to diagrams EDSL

MaintainerMichael Sloan <mgsloan at gmail>, Deepak Jois <deepak.jois@gmail.com>
Safe HaskellNone

Diagrams.TwoD.Path.Turtle.Internal

Contents

Description

Authors : Michael Sloan at gmail, Deepak Jois deepak.jois@gmail.com

A module consisting of core types and functions to represent and operate on a "turtle".

More info about turtle graphics: http://en.wikipedia.org/wiki/Turtle_graphics

Synopsis

Turtle data types and accessors

data Turtle Source

Core turtle data type. A turtle needs to keep track of its current position, like its position, heading etc., and all the paths that it has traversed so far.

We need to record a new path, everytime an attribute like style, pen position etc changes, so that we can separately track styles for each portion of the eventual path that the turtle took.

Constructors

Turtle 

Fields

isPenDown :: Bool

State of the pen. False means that turtle movements will not draw anything

penPos :: P2

Current position. This is updated everytime the turtle moves

heading :: Deg

Orientation of the turtle in 2D space, given in degrees

currTrail :: (P2, Trail R2)

Path traversed by the turtle so far, without any style or pen attributes changing

currPenStyle :: PenStyle

Current style of the pen

paths :: [TurtlePath]

List of paths along with style information, traversed by the turtle previously

Instances

data TurtlePath Source

Turtle path type that captures a list of paths and the style attributes associated with them

Constructors

TurtlePath 

Fields

penStyle :: PenStyle

Style

turtleTrail :: (P2, Trail R2)

Path

Instances

data PenStyle Source

Style attributes associated with the turtle pen

Constructors

PenStyle 

Fields

penWidth :: Double

Width of pen. Default is 1.0

penColor :: Colour Double

Color of pen. Default is black

Instances

Motion commands

forwardSource

Arguments

:: Double

Distance to move

-> Turtle

Turtle to move

-> Turtle

Resulting turtle

Move the turtle forward by x units

backwardSource

Arguments

:: Double

Distance to move

-> Turtle

Turtle to move

-> Turtle

Resulting turtle

Move the turtle backward by x units

leftSource

Arguments

:: Double

Degree of turn

-> Turtle

Turtle to turn

-> Turtle

Resulting turtle

Turn the turtle anti-clockwise (left)

rightSource

Arguments

:: Double

Degree of turn

-> Turtle

Turtle to turn

-> Turtle

Resulting turtle

Turn the turtle clockwise (right)

Pen style commands

setPenColorSource

Arguments

:: Colour Double

Width of Pen

-> Turtle

Turtle to change

-> Turtle

Resulting Turtle

alias of setPenColour

setPenColourSource

Arguments

:: Colour Double

Width of Pen

-> Turtle

Turtle to change

-> Turtle

Resulting Turtle

Set a new pen color for turtle.

If pen is down, this adds the current trail to paths and starts a new empty trail.

setPenWidthSource

Arguments

:: Double

Width of Pen

-> Turtle

Turtle to change

-> Turtle

Resulting Turtle

Set a new pen width for turtle.

If pen is down, this adds the current trail to paths and starts a new empty trail.

State setters

startTurtle :: TurtleSource

The initial state of turtle. The turtle is located at the origin, at an orientation of 0 degrees with its pen position down. The pen style is defaultPenStyle.

setHeadingSource

Arguments

:: Double

Degree of orientation

-> Turtle

Turtle to orient

-> Turtle

Resulting turtle

Turn the turtle to the given orientation, in degrees

towardsSource

Arguments

:: P2

Point to orient turtle towards

-> Turtle

Turtle to orient

-> Turtle

Resulting turtle

Sets the turtle orientation towards a given location.

setPenPosSource

Arguments

:: P2

Position to place true

-> Turtle

Turtle to position

-> Turtle

Resulting turtle

Set the turtle X/Y position.

If pen is down and the current trail is non-empty, this will also add the current trail to the paths field.

Drawing control

penUpSource

Arguments

:: Turtle

Turtle to modify

-> Turtle

Resulting turtle

Puts the turtle pen in “Up” mode. Turtle movements will not draw anything

Does nothing if the pen was already up. Otherwise, it creates a turtle with the current trail added to paths.

penDownSource

Arguments

:: Turtle

Turtle to modify

-> Turtle

Resulting turtle

Puts the turtle pen in “Down” mode. Turtle movements will cause drawing to happen

Does nothing if the pen was already down. Otherwise, starts a new trail starting at the current position.

Debugging

traceTurtle :: Turtle -> TurtleSource

Prints out turtle representation and returns it. Use for debugging

Diagram related

getTurtleDiagram :: Renderable (Path R2) b => Turtle -> Diagram b R2Source

Creates a diagram from a turtle

Applies the styles to each trails in paths separately and combines them into a single diagram