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.
// Turtle Star!
π’.beginFill()
36.timesRepeat {
π’.forward(200)
π’.left(170)
}
π’.endFill()// 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- Open
TortoiseGraphics.xcworkspacein Xcode. - Build
TortoiseGraphicsscheme for iOS Simulator. - Select
Playgroundin project navigator. - Let's play!
- 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
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!
TortoiseImageCanvasShapeColorVec2D
Speed
forward(),fd()backword(),back(),bk()right(),rt()left(),lt()setPosition(),setPos(),goto()setX()setY()setHeading(),setH()home()circle()
position,postowards()xcorycorheadingdistance()
penDown(),pd(),down()penUp(),pu(),up()penSize()width()isDownpenSizewidth
penColor()penColorfillColor()fillColor
fillingbeginFill()endFill()
reset()clear()
showTortoise(),st()hideTortoise(),ht()isVisibleshape()shape
Int.timesRepeat() {}random()degrees()radians()colorMode(),colorMode
PlaygroundCanvasPlaygroundCanvasLiveView
SwiftPlaygroundCanvasLiveViewController
- Swift 5.1 (Xcode 11.1)
- iOS/iPadOS 13.0 or later
github "temoki/TortoiseGraphics"
pod 'TortoiseGraphics'- support SVG output
- macOS support
- Swift Package Manager support
- Enrich tortoise commands
- Enrich playground contents
- Special thanks to @kiyoshifuwa, for the amazing art works.
TortoiseGraphics is released under the MIT license. See LICENSE for details.


