-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContents.swift
31 lines (24 loc) · 1.45 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
//: [< Previous](@previous) [Home](Introduction) [Next >](@next)
//: # Four circles
//: Now that you've mastered rectangles, ellipses ought to be easy. Like rectangles, ellipses are drawn by activating a color then specifying a rectangle. If the rectangle has the same width and height you'll get a circle, otherwise you'll get an ellipse.
//:
//: - Experiment: The code below draws one red circle in the top-left corner, but your designer wants you to create three more: a yellow circle in the top-right corner, a blue circle in the bottom-left corner, and a green circle in the bottom-right corner.
import UIKit
let rect = CGRect(x: 0, y: 0, width: 1000, height: 1000)
let renderer = UIGraphicsImageRenderer(bounds: rect)
let rendered = renderer.image { ctx in
UIColor.red.setFill()
let circle1 = CGRect(x: 0, y: 0, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle1)
UIColor.yellow.setFill()
let circle2 = CGRect(x: 500, y: 0, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle2)
UIColor.blue.setFill()
let circle3 = CGRect(x: 0, y: 500, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle3)
UIColor.green.setFill()
let circle4 = CGRect(x: 500, y: 500, width: 500, height: 500)
ctx.cgContext.fillEllipse(in: circle4)
}
showOutput(rendered)
//: [< Previous](@previous) [Home](Introduction) [Next >](@next)