//: # With a tortoise 🐢
//: [👉 With 2 tortoises 🐢🐢](@next)
import PlaygroundSupport
import TortoiseGraphics
import CoreGraphics
let canvas = PlaygroundCanvas(frame: CGRect(x: 0, y: 0, width: 800, height: 800))
canvas.frameRate = 30
canvas.color = .white
PlaygroundPage.current.liveView = canvas
canvas.drawing { 🐢 in
🐢.penColor(.red)
🐢.penDown()
// draw a square
// 🐢.forward(100)
// 🐢.left(90)
// 🐢.forward(100)
// 🐢.left(90)
// 🐢.forward(100)
// 🐢.left(90)
// 🐢.forward(100)
// 🐢.left(90)
// look for repeats...
// for i in 1 ... 4 {
// 🐢.forward(100)
// 🐢.left(90)
// }
//make it a function
// func square() {
// for i in 1 ... 4 {
// 🐢.left(90)
// 🐢.forward(100)
// }
// }
// try it out
//square()
// make it an adjustable function
func adjustableSquare(size: Double) {
for i in 1 ... 4 {
🐢.left(90)
🐢.forward(size)
}
}
// let's make something out of those squares
for i in 1...90 {
adjustableSquare(size: 100)
🐢.left(4)
}
// Instantiate a ImageCanvas
let canvie = ImageCanvas(size: CGSize(width: 300, height: 300))
canvie.drawing { 🐢 in
for i in 1...90 {
adjustableSquare(size: 100)
🐢.left(4)
}
}
let cgImage = canvie.cgImage
let image = canvie.image
// docs say:
//canvas.writePNG(to: URL(fileURLWithPath: "./image.png")
// I think its missing the last ")" so I added it, still doesn't work
//canvie.writePNG(to: URL(fileURLWithPath: "./image.png"))
}