-
Notifications
You must be signed in to change notification settings - Fork 1
/
Contents.swift
32 lines (25 loc) · 1.58 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//: [< Previous](@previous) [Home](Introduction) [Next >](@next)
//: # The Poppyseed Bread Company
//: You have a new client! A local artisanal bakery always adds a finishing touch to its loaves by sprinkling poppy seeds on top, and they want you to make them a great poppy logo. Your designer has already sketched something, but it falls to you to figure out how to make it happen in code.
//:
//: - Experiment: Your designer has provided a sketch of what they want: four red circles, with a black circle in the middle. Can you make this happen using ellipses? They've drawn the first one for you, but it isn't quite right.
import UIKit
let rect = CGRect(x: 0, y: 0, width: 1000, height: 1000)
let renderer = UIGraphicsImageRenderer(bounds: rect)
let rendered = renderer.image { ctx in
// "This doesn't seem right…" – Designer
UIColor.red.setFill()
let circle1 = CGRect(x: 50, y: 50, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle1)
let circle2 = CGRect(x: 450, y: 50, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle2)
let circle3 = CGRect(x: 50, y: 450, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle3)
let circle4 = CGRect(x: 450, y: 450, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle4)
UIColor.black.setFill()
let circle5 = CGRect(x: 400, y: 400, width: 200, height: 200)
ctx.cgContext.fillEllipse(in: circle5)
}
showOutput(rendered)
//: [< Previous](@previous) [Home](Introduction) [Next >](@next)