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.xcworkspace
in Xcode. - Build
TortoiseGraphics
scheme for iOS Simulator. - Select
Playground
in 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.zip
from here. - Unarchive the downloaded zip file.
- Send the unarchvied
TortoiseGraphics.playgroundbook
file to your iPad by AirDrop. - Open it with Swift Playgrounds app.
- Let's play!
Tortoise
ImageCanvas
Shape
Color
Vec2D
Speed
forward()
,fd()
backword()
,back()
,bk()
right()
,rt()
left()
,lt()
setPosition()
,setPos()
,goto()
setX()
setY()
setHeading()
,setH()
home()
circle()
position
,pos
towards()
xcor
ycor
heading
distance()
penDown()
,pd()
,down()
penUp()
,pu()
,up()
penSize()
width()
isDown
penSize
width
penColor()
penColor
fillColor()
fillColor
filling
beginFill()
endFill()
reset()
clear()
showTortoise()
,st()
hideTortoise()
,ht()
isVisible
shape()
shape
Int.timesRepeat() {}
random()
degrees()
radians()
colorMode()
,colorMode
PlaygroundCanvas
PlaygroundCanvasLiveView
SwiftPlaygroundCanvas
LiveViewController
- 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.