Swiftpack.co - Package - temoki/TortoiseGraphics

Swift Xcode Swift Playgrounds 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()
36.timesRepeat {
    🐢.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

  • 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()

Tell tortoise's state

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

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

Other Commands

  • Int.timesRepeat() {}
  • random()
  • degrees()
  • radians()
  • colorMode(),
  • colorMode

for Playground

  • PlaygroundCanvas
  • PlaygroundCanvasLiveView

for Swift Playgrounds

  • SwiftPlaygroundCanvas
  • LiveViewController

Requirements

  • Swift 5.1 (Xcode 11.1)
  • iOS/iPadOS 13.0 or later

Installation

Carthage

github "temoki/TortoiseGraphics"

Cocoapods

pod 'TortoiseGraphics'

Remaining Work

  • support SVG output
  • macOS support
  • Swift Package Manager support
  • Enrich tortoise commands
  • Enrich playground contents

Credits

  • Special thanks to @kiyoshifuwa, for the amazing art works.

License

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

Github

link
Stars: 74

Dependencies

Used By

Total: 0

Releases

v1.0.0-beta.3 - 2020-05-10 14:29:40

This is beta version.

v1.0.0-beta.2 - 2019-10-28 14:35:47

This is beta version.

v1.0.0-beta.1 - 2019-08-28 14:06:49

This is beta version.

v0.16.0 - 2019-06-10 14:48:16

Xcode 10.2 & Swift 5

v0.15.0 - 2018-11-25 12:24:02

Fix some issues #36, #37. (Contributed by @lcs-rgordon :tada:)

v0.14.0 - 2018-10-07 14:09:30

  • Swift 4.2 compatible

v0.13.2 - 2018-06-25 12:13:14

  • Fix swiftlint errors

v0.13.1 - 2018-01-29 11:50:05

  • Fix bug (penSize state are shared in tortoises)

v0.13.0 - 2018-01-27 14:39:51

  • Add Shape commands

v0.12.0 - 2017-12-30 16:25:25

  • Canvas color support

v0.11.0 - 2017-12-19 15:31:18

  • Drawing with multiple tortoises

v0.10.0 - 2017-12-17 02:24:27

  • Add Filling commands
  • Vec2D support
  • New canvas design

v0.9.2 - 2017-06-30 15:31:53

  • Playgroundbook minor update

v0.9.1 - 2017-06-12 13:29:01

  • Remove watchOS and tvOS from SUPPORTED_PLATFORMS.

v0.9.0 - 2017-06-11 15:30:35

  • Re-designed with reference to the turtle in Python 3 standard libraries.

v0.8.2 - 2017-05-12 15:45:51

  • Memory usage optimization on playground book

v0.8.1 - 2017-05-10 15:10:23

  • Fix bug : first line is not drawn
  • Improved Playground Book usability

v0.8.0 - 2017-05-09 16:00:59

  • Simple Playground book for Playgrounds iPad app

v0.7.0 - 2017-05-05 16:29:14

  • Add Playground book for Playgrounds iPad app
  • Bug fix

v0.6.0 - 2017-05-04 01:01:56

  • Resizable canvas
  • Fix dot command bug

v0.5.0 - 2017-05-02 08:36:12

  • Supports retina display!

v0.4.0 - 2017-04-30 13:40:26

  • Add tortoise icon

v0.3.0 - 2017-04-22 02:51:03

  • Add CanvasView for macOS and iOS
  • Add Playground for macOS

v0.2.1 - 2017-04-18 15:25:46

v0.1.0 - 2017-04-17 14:38:24