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
- Open
TortoiseGraphics.xcworkspacein Xcode. - Build
TortoiseGraphicsscheme for iOS Simulator. - Select
Playgroundin project navigator. - Let's play!
On Swift Playgrounds (iPad app)
Subscription
- Launch Safari on your iPad and browse this page.
- Tap the following link to subscribe.
- You can get Tortoise Graphics playground book on Swift Playgrounds app.
Download
- Download
TortoiseGraphics.playgroundbook.zipfrom here. - Unarchive the downloaded zip file.
- Send the unarchvied
TortoiseGraphics.playgroundbookfile to your iPad by AirDrop. - Open it with Swift Playgrounds app.
- Let's play!
Classes
TortoiseImageCanvasShapeColorVec2D
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,postowards()xcorycorheadingdistance()
Pen Control
Drawing state
penDown(),pd(),down()penUp(),pu(),up()penSize()width()isDownpenSizewidth
Color control
penColor()penColorfillColor()fillColor
Filling
fillingbeginFill()endFill()
More drawing control
reset()clear()
Tortoise state
Visiblity
showTortoise(),st()hideTortoise(),ht()isVisibleshape()shape
Other Commands
Int.timesRepeat() {}random()degrees()radians()colorMode(),colorMode
for Playground
PlaygroundCanvasPlaygroundCanvasLiveView
for Swift Playgrounds
SwiftPlaygroundCanvasLiveViewController
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.


