Documentation ¶
Index ¶
Constants ¶
const ( // Degrees mode. East is 0, North is 90, West is 180, South is 270 DegreesMode AngleMode = "Degrees Angle Mode" // Radians mode. East is 0, North is pi/2, West is pi, South is 3/2*pi RadiansMode AngleMode = "Radians Angle Mode" // Compass mode. North is 0 degrees, and East is 90, South is 180, West is 270. CompassMode AngleMode = "Compass Angle Mode" // The max pen speed. No delay will be used. MaxSpeed float64 = 1.0e12 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas interface { CreateNewSprite() Sprite SetCartesianPixel(x, y int, c color.Color) // Cartesian (x,y). Center in the middle of the window SetPixel(x, y int, c color.Color) // Computer graphics (x,y). So x=0, y=0 is the top-left of the window, positive down-right. Fill(x, y int, c color.Color) // Cartesian (x,y). Center in the middle of the window ClearScreen(c color.Color) GetScreenshot() image.Image GetWidth() int GetHeight() int PressedUserInput() *UserInput SubscribeToJustPressedUserInput() chan *UserInput UnSubscribeToJustPressedUserInput(in chan *UserInput) Exit() }
The Canvas interface. A pen that is given this interface should be able to create a working implementation of Turtle Graphics.
type KeysStruct ¶
type KeysStruct struct { LeftArrow bool RightArrow bool UpArrow bool DownArrow bool A bool B bool C bool D bool E bool F bool G bool H bool I bool J bool K bool L bool M bool N bool O bool P bool Q bool R bool S bool T bool U bool V bool W bool X bool Y bool Z bool Number0 bool Number1 bool Number2 bool Number3 bool Number4 bool Number5 bool Number6 bool Number7 bool Number8 bool Number9 bool F1 bool F2 bool F3 bool F4 bool F5 bool F6 bool F7 bool F8 bool F9 bool F10 bool F11 bool F12 bool Space bool Backspace bool Tab bool LeftShift bool RightShift bool LeftCtrl bool RightCtrl bool LeftAlt bool RightAlt bool Enter bool Insert bool Delete bool Home bool End bool PageUp bool PageDown bool Escape bool Backquote bool Minus bool Equal bool Comma bool Period bool SemiColon bool Apostrophe bool ForwardSlash bool BackSlash bool OpenSquareBracket bool CloseSquareBracket bool }
All the currently supported keys.
type MouseStruct ¶
type MouseStruct struct { Left bool Right bool Center bool MouseX int MouseY int MouseScroll float64 }
All the currently supported mouse inputs.
type Sprite ¶
type Sprite interface { SetSpriteImage(image.Image) SetSpriteImageTurtle() SetSpriteImageArrow() SetRotation(radianAngle float64) SetPosition(cartX, cartY float64) // Cartesian (x,y). Center in the middle of the window SetVisible(visible bool) SetScale(scale float64) Set(visible bool, cartX, cartY, radianAngle float64) // Cartesian (x,y). Center in the middle of the window Get() SpriteInfo }
A sprite is a image that can be place on the screen. The x/y location, rotation, size, and visibility are all controllable.
type SpriteInfo ¶
type Turtle ¶
type Turtle interface { Forward(distance float64) F(distance float64) // Forward alias Backward(distance float64) B(distance float64) // Backward alias PanRightward(distance float64) PanR(distance float64) // PanRightward alias PanLeftward(distance float64) PanL(distance float64) // PanLeftward alias GoTo(x, y float64) // Cartesian (x,y). Center in the middle of the window GetPos() (x, y float64) // Cartesian (x,y). Center in the middle of the window // instantly move to a position. // Cartesian (x,y). Center in the middle of the window Teleport(x, y float64) Left(angle float64) L(angle float64) // Turn Left alias Right(angle float64) R(angle float64) // Turn Right alias Angle(angle float64) GetAngle() float64 PointToward(x, y float64) DegreesMode() // Default is degrees mode. RadiansMode() CompassMode() // Make it so North is 0 degrees, East is 90... GetAngleMode() AngleMode Speed(PixelsPerSecond float64) GetSpeed() float64 PenUp() PU() // Pen Up alias Off() // Pen Up alias PenDown() PD() // Pen Down alias On() // Pen Down alias IsPenDown() bool Color(c color.Color) GetColor() color.Color Size(size float64) GetSize() float64 Dot(size float64) Fill(c color.Color) // Draw a circle with given radius. The center is radius units left of the turtle; angleAmountToDraw determines // which part of the circle is drawn. If angleAmountToDraw is not a full circle, one endpoint of the arc is // the current pen position. Draw the arc in counterclockwise direction if radius is positive, // otherwise in clockwise direction. Finally the direction of the turtle is changed by the amount of angleAmountToDraw. // // As the circle is approximated by an inscribed regular polygon, steps determines the number of steps to use. // May be used to draw regular polygons. Circle(radius, angleAmountToDraw float64, steps int) ShowTurtle() HideTurtle() // Default ShapeAsTurtle() // Default ShapeAsArrow() ShapeAsImage(in image.Image) ShapeScale(scale float64) // Default = 0.35 Clone() Turtle // Create a clone of the turtle }
The turtle interface. Every turtle created for the user of this package can do this exact list of actions. This mirrors the python turtle graphics command set. Each turtle is completely independent, and can be commanded in the same go routine or in different go routines.
type UserInput ¶
type UserInput struct { AnyPressed bool Keys KeysStruct Mouse MouseStruct }
Used for currently pressed and for the just pressed functionality.
func (*UserInput) IsPressedByName ¶
Check if a key is pressed by its name. Some of the keys have multiple names, such as:: case "space", " ":