-
Notifications
You must be signed in to change notification settings - Fork 1
/
Contents.swift
31 lines (25 loc) · 1.16 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)
//: # Taste the rainbow
//: Your boss has dug out some old code that was supposed to draw a rainbow by stroking the outlines of concentric circles. Sadly, it looks like the data got corrupted somehow, because three of its values don't seem right.
//:
//: - Experiment: Your designer has produced a sketch showing how it *should* look. Can you adjust the code to help make it work correctly?
import UIKit
let rect = CGRect(x: 0, y: 0, width: 1000, height: 1000)
let renderer = UIGraphicsImageRenderer(bounds: rect)
let rendered = renderer.image { ctx in
ctx.cgContext.setLineWidth(50)
let colors: [UIColor] = [.red, .orange, .yellow, .green, .blue, .purple]
var xPos = 0
var yPos = 500
var size = 1000
for color in colors {
xPos += 50
yPos += 50
size -= 100
let rect = CGRect(x: xPos, y: yPos, width: size, height: size)
color.setStroke()
ctx.cgContext.strokeEllipse(in: rect)
}
}
showOutput(rendered)
//: [< Previous](@previous) [Home](Introduction) [Next >](@next)