Swiftpack.co - Package - temoki/TortoiseGraphics

Swift Carthage compatible Version License Platform

A turtle graphics (a key feature of the Logo engine written in Swift.

The commands were implemented with reference to the turtle in Python 3 standard libraries.

Example

// Turtle Star!
🐢.beginFill()
🐢.repeat(36) {
    🐢.forward(200)
    🐢.left(170)
}
🐢.endFill()

Result

Usage

// Instantiate a `Tortoise`
let 🐢 = Tortoise()

// Instantiate `ImageCanvas` and add the tortoise
let canvas = ImageCanvas(size: Vec2D(300, 300))
canvas.add(🐢)

// Command 🐢
🐢.right(90)
🐢.forward(100)

// Get drawn `CGImage`
let cgImage = canvas.cgImage

Playgrounds

On Xcode

  1. Open TortoiseGraphics.xcworkspace in Xcode.
  2. Build TortoiseGraphics scheme for iOS Simulator.
  3. Select Playground in project navigator.
  4. Let's play!

On Swift Playgrounds (iPad app)

Subscription

  1. Launch Safari on your iPad and browse this page.
  2. Tap the following link to subscribe.
  3. You can get Tortoise Graphics playground book on Swift Playgrounds app.

Download

  1. Download TortoiseGraphics.playgroundbook.zip from here.
  2. Unarchive the downloaded zip file.
  3. Send the unarchvied TortoiseGraphics.playgroundbook file to your iPad by AirDrop.
  4. Open it with Swift Playgrounds app.
  5. Let's play!

Classes

  • Tortoise
  • ImageCanvas
  • Shape
  • Color
  • Vec2D

Enums

  • ColorPalette
  • Speed

Tortoise Commands

Motion

Move and Draw

  • forward(), fd()
  • backword(), back(), bk()
  • right(), rt()
  • left(), lt()
  • setPosition(), setPos(), goto()
  • setX()
  • setY()
  • setHeading(), setH()
  • home()
  • circle()
  • repeat() {}

Tell tortoise's state

  • position, pos
  • towards()
  • xcor
  • ycor
  • heading
  • distance()
  • random()

Pen Control

Drawing state

  • penDown(), pd(), down()
  • penUp(), pu(), up()
  • penSize()
  • width()
  • isDown
  • penSize
  • width

Color control

  • penColor()
  • penColor
  • fillColor()
  • fillColor

Filling

  • filling
  • beginFill()
  • endFill()

More drawing control

  • reset()
  • clear()

Tortoise state

Visiblity

  • showTortoise(), st()
  • hideTortoise(), ht()
  • isVisible
  • shape()
  • shape

for Playground

  • PlaygroundCanvas
  • PlaygroundCanvasLiveView

for Swift Playgrounds

  • SwiftPlaygroundCanvas
  • LiveViewController

Requirements

  • Swift 5 (Xcode 10)
  • iOS 12.0 or later

Installation

Carthage

github "temoki/TortoiseGraphics"

Cocoapods

pod 'TortoiseGraphics'

Remaining Work

License

TortoiseGraphics is released under the MIT license. See LICENSE for details.