Latest 0.9.2
Homepage https://github.com/temoki/TortoiseGraphics
License MIT
Platforms ios 10.0, osx 10.10
Frameworks CoreGraphics

TortoiseGraphics 🐢

Swift
Swift Package Manager
Carthage compatible
Version
License
Platform

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

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

Example

func hexagon(_ side: Double) {
    🐢.repeat(6) {
        🐢.forward(side)
        🐢.right(60)
    }
}

var side: Double = 0
🐢.penColor(.blue)
🐢.repeat(24) {
    side += 3
    hexagon(side)
    🐢.right(15)
}

Drawn image

TortoiseGraphics

Drawing animation

TortoiseGraphics

Usage

Draw in view (macOS/iOS)

// Instantiate a Canvas that is a subclass of NSView/UIView.
let canvas = Canvas(frame: CGRect(x: 0, y: 0, width: 300, height: 300))

// Command 🐢 on canvas.
canvas.play { 🐢 in
    🐢.right(90)
    🐢.forward(100)
}

Make or Write image

// Instantiate 🐢.
let 🐢 = Tortoise()

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

// Make NSImage or UIImage
let size = CGSize(width: 300, height: 300)
let image = 🐢.makeImage(of: size)

// Write PNG/JPEG/GIF
🐢.writePNG(of: size, to: URL(fileURLWithPath: "./image.png"))
🐢.writeJPEG(of: size, to: URL(fileURLWithPath: "./image.jpeg"))
🐢.writeGIF(of: size, to: URL(fileURLWithPath: "./image.gif"))

Playgrounds

On Xcode

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

On Playgrounds iPad app

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

Commands

Motion

Move and Draw

  • forward(), fd()
  • backword(), back(), bk()
  • right(), rt()
  • left(), lt()
  • setPosition(), setPos(), goto()
  • setX()
  • setY()
  • setHeading(), setH()
  • home()
  • dot()
  • 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

More drawing control

  • reset()
  • clear()

Tortoise state

Visiblity

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

Make or Write image

  • makeImage()
  • writePNG()
  • writeJPEG()
  • writeGIF()

Requirements

  • Swift 3.1 (Xcode 8.3)
  • macOS 10.10 or later
  • iOS 10.0 or later

Installation

Swift Package Manager

dependencies: [
    .Package(url: "https://github.com/temoki/TortoiseGraphics.git", majorVersion: 0)
]

Carthage

github "temoki/TortoiseGraphics"

Cocoapods

pod 'TortoiseGraphics'

License

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

Latest podspec

{
    "name": "TortoiseGraphics",
    "version": "0.9.2",
    "summary": "A turtle graphics (a key feature of the Logo) engine written in Swift.",
    "description": "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.",
    "homepage": "https://github.com/temoki/TortoiseGraphics",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "temoki",
    "source": {
        "git": "https://github.com/temoki/TortoiseGraphics.git",
        "tag": "0.9.2"
    },
    "social_media_url": "https://twitter.com/temoki",
    "platforms": {
        "ios": "10.0",
        "osx": "10.10"
    },
    "source_files": "Sources/*",
    "frameworks": "CoreGraphics",
    "ios": {
        "frameworks": "UIKit"
    },
    "osx": {
        "frameworks": "AppKit"
    },
    "pushed_with_swift_version": "3.1"
}

Pin It on Pinterest

Share This