Skip to content

Commit 53ee09c

Browse files
committed
Some code cleanup and bug fixes.
1 parent 63b6070 commit 53ee09c

File tree

31 files changed

+251
-433
lines changed

31 files changed

+251
-433
lines changed

.idea/runConfigurations/BookCore.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/LiveViewTestApp.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.swiftlint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ whitelist_rules:
77
- fatal_error_message
88
# - force_cast
99
- force_try
10-
- force_unwrapping
10+
# - force_unwrapping
1111
# - implicitly_unwrapped_optional
1212
- legacy_cggeometry_functions
1313
- legacy_constant
@@ -31,7 +31,7 @@ excluded:
3131
colon:
3232
apply_to_dictionaries: false
3333

34-
indentation: 2
34+
indentation: 4
3535

3636
custom_rules:
3737
no_objcMembers:

ArtOfAscii.xcodeproj/project.pbxproj

Lines changed: 54 additions & 175 deletions
Large diffs are not rendered by default.

ArtOfAscii/Chapters/01-ArtOfAscii.playgroundchapter/Pages/01-Introduction.playgroundpage/main.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ assessmentHelper.assessmentShowOnce({ true }, pass: nil)
1616
/*:
1717
# Art of ASCII — Introduction to Digital Image Processing
1818

19-
## What is an ASCII Art?
19+
## ASCII Arts?
2020

2121
**ASCII (American Standard Code for Information Interchange)** is a standard for electronic communication, which
22-
contains 128 characters.
22+
contains 128 characters including letters, numbers and some control characters.
2323

2424
**ASCII arts** are artworks created with ASCII characters, which can be seen in many places where only textual data can
25-
be transmitted, for example, within a terminal.
25+
be transmitted, for example, within a computer terminal.
2626

2727
* Experiment:
28-
Head to the panel beside, and *tap the **run** button*, have fun experiencing the ASCII effects I've created.
28+
*Tap the **run** button* on the side panel. Have fun experiencing ASCII effects I've created.
2929

30-
## What We'll Learn by Generating ASCII Arts?
30+
## What Will We Learn by Generating ASCII Arts?
3131

32-
Examining how to generate ASCII Arts is a great way to explore the world of image processing. You'll be introduced with
33-
**the RGB color model**, **histograms and equalization techniques** with piratical experiments, which can be a fun and
34-
delightful.
32+
Examining how to generate ASCII Arts is a great way to explore image processing. You'll be introduced with
33+
**the RGB color model, histograms and equalization techniques** with some piratical experiments, which are fun to play
34+
with.
3535

3636
[Let's get started! 🏃‍♂️](@next)
3737
*/

ArtOfAscii/Chapters/01-ArtOfAscii.playgroundchapter/Pages/02-HowImagesComposed.playgroundpage/main.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import UIKit
88
import PlaygroundSupport
99

1010
import BookCore
11-
import BookAPI
1211

1312
PlaygroundPage.current.needsIndefiniteExecution = true
1413

ArtOfAscii/Chapters/01-ArtOfAscii.playgroundchapter/Pages/03-GrayscaleHistogramEqualization.playgroundpage/main.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import UIKit
88
import PlaygroundSupport
99

1010
import BookCore
11-
import BookAPI
1211

1312
PlaygroundPage.current.needsIndefiniteExecution = true
1413

ArtOfAscii/Chapters/01-ArtOfAscii.playgroundchapter/Pages/04-Asciification.playgroundpage/main.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import UIKit
88
import PlaygroundSupport
99

1010
import BookCore
11-
import BookAPI
1211

1312
PlaygroundPage.current.needsIndefiniteExecution = true
1413

ArtOfAscii/Manifest.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<string>BookAPI</string>
2727
</array>
2828
<key>UserModuleMode</key>
29-
<string>Full</string>
29+
<string>Disabled</string>
3030
<key>ImageReference</key>
3131
<string>cover.png</string>
3232
<key>SupportsDarkMode</key>

ArtOfAscii/Modules/BookAPI.playgroundmodule/Sources/AssessmentHelper.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public class AssessmentHelper {
1717
}
1818

1919
public func assessmentShowOnce(_ assessmentFunc: AssessmentFunc, pass passMessage: String?) {
20-
guard !assessmentStatusShown else {
21-
return
22-
}
23-
if assessmentFunc() == true {
20+
if !assessmentStatusShown && assessmentFunc() == true {
2421
assessmentStatusShown = true
2522
PlaygroundPage.current.assessmentStatus = .pass(message: passMessage)
2623
}

ArtOfAscii/Modules/BookAPI.playgroundmodule/Sources/BookAPI.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

ArtOfAscii/Modules/BookCore.playgroundmodule/Sources/Core/FontResourceProvider.swift

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
import Foundation
77
import CoreText
88

9-
public struct FontResourceName {
9+
public struct FontFile {
1010
let name: String
1111
let extensionName: String
1212
}
1313

14-
public protocol Font {
14+
public protocol FontResource {
1515

16-
static var resourceNames: [FontResourceName] { get }
16+
static var resourceFiles: [FontFile] { get }
1717
static var characterAspectRatio: Double { get }
1818

1919
static func register()
2020

2121
}
2222

23-
public extension Font {
23+
public extension FontResource {
2424

2525
static func register() {
26-
for resourceName in resourceNames {
27-
if let fontURL = Bundle.main.url(forResource: resourceName.name, withExtension: resourceName.extensionName) {
26+
for fontFile in resourceFiles {
27+
if let fontURL = Bundle.main.url(forResource: fontFile.name, withExtension: fontFile.extensionName) {
2828
CTFontManagerRegisterFontsForURL(fontURL as CFURL, CTFontManagerScope.process, nil)
2929
}
3030
}
@@ -34,53 +34,43 @@ public extension Font {
3434

3535
public class FontResourceProvider {
3636

37-
public enum FiraCode: String, Font {
37+
public enum FiraCode: String, FontResource {
3838

3939
case light = "FiraCode-Light"
4040
case retina = "FiraCode-Light_Retina"
4141
case bold = "FiraCode-Light_Bold"
4242
case medium = "FiraCode-Light_Medium"
4343
case regular = "FiraCode-Light_Regular"
4444

45-
public static var resourceNames: [FontResourceName] {
46-
return [FontResourceName(name: "FiraCode-VF", extensionName: "ttf")]
47-
}
45+
public static var resourceFiles = [
46+
FontFile(name: "FiraCode-VF", extensionName: "ttf")
47+
]
4848

49-
public static var characterAspectRatio: Double {
50-
return 0.6
51-
}
49+
public static var characterAspectRatio = 0.6
5250

5351
}
5452

55-
public enum CourierPrime: String, Font {
53+
public enum CourierPrime: String, FontResource {
5654

5755
case regular = "CourierPrime"
5856
case bold = "CourierPrime-Bold"
5957

60-
public static var resourceNames: [FontResourceName] {
61-
return [
62-
FontResourceName(name: "Courier Prime", extensionName: "ttf"),
63-
FontResourceName(name: "Courier Prime Bold", extensionName: "ttf")
64-
]
65-
}
58+
public static var resourceFiles = [
59+
FontFile(name: "Courier Prime", extensionName: "ttf"),
60+
FontFile(name: "Courier Prime Bold", extensionName: "ttf")
61+
]
6662

67-
public static var characterAspectRatio: Double {
68-
return 0.6
69-
}
63+
public static var characterAspectRatio = 0.6
7064

7165
}
7266

73-
public enum Unscii16: String, Font {
74-
75-
public static var resourceNames: [FontResourceName] {
76-
return [FontResourceName(name: "unscii-16", extensionName: "ttf")]
77-
}
67+
public enum Unscii16: String, FontResource {
7868

7969
case regular = "unscii-16"
8070

81-
public static var characterAspectRatio: Double {
82-
return 0.5
83-
}
71+
public static var resourceFiles = [FontFile(name: "unscii-16", extensionName: "ttf")]
72+
73+
public static var characterAspectRatio = 0.5
8474

8575
}
8676

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Copyright © 2020 Bunny Wong
3+
// Created on 2020/2/11.
4+
//
5+
6+
import UIKit
7+
8+
extension UIColor {
9+
10+
struct States {
11+
12+
static let highlight = UIColor(red: 0.13, green: 0.53, blue: 1.00, alpha: 1.0)
13+
static let success = UIColor(red: 0.20, green: 0.82, blue: 0.35, alpha: 1.0)
14+
static var error = UIColor(red: 0.92, green: 0.29, blue: 0.35, alpha: 1.0)
15+
16+
}
17+
18+
}

ArtOfAscii/Modules/BookCore.playgroundmodule/Sources/LiveViewController.swift

Lines changed: 0 additions & 34 deletions
This file was deleted.

ArtOfAscii/Modules/BookCore.playgroundmodule/Sources/UserInterface/Chapters/01-ArtOfAscii/02-HowImagesComposed/HowImagesComposedLiveViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class HowImagesComposedViewController: BaseViewController {
3636
}
3737

3838
private func requestImageFiltering() {
39-
guard let sourceImage = self.sourceImage else {
39+
guard let sourceImage = sourceImage else {
4040
return
4141
}
4242
let payload = EventMessage.rgbFilterRequest(
@@ -49,7 +49,7 @@ public class HowImagesComposedViewController: BaseViewController {
4949
}
5050

5151
private func updateMagnificationCenter(centerInImageView: CGPoint) {
52-
if let centerInImage = self.showcaseImageView.pointInImageFor(point: centerInImageView) {
52+
if let centerInImage = showcaseImageView.pointInImageFor(point: centerInImageView) {
5353
magnifierContainerView.magnificationCenter = centerInImage
5454
}
5555
}
@@ -104,7 +104,7 @@ public class HowImagesComposedViewController: BaseViewController {
104104
extension HowImagesComposedViewController: MagnifierContainerViewDelegate {
105105

106106
func magnifierCenterPositionChanged(point: CGPoint, containerView: MagnifierContainerView) {
107-
let centerInImageView = self.showcaseImageView.convert(point, from: containerView)
107+
let centerInImageView = showcaseImageView.convert(point, from: containerView)
108108
updateMagnificationCenter(centerInImageView: centerInImageView)
109109
}
110110

ArtOfAscii/Modules/BookCore.playgroundmodule/Sources/UserInterface/Chapters/01-ArtOfAscii/02-HowImagesComposed/Views/MagnivierContainerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MagnifierContainerView: UIView {
7171

7272
}
7373

74-
protocol MagnifierContainerViewDelegate: AnyObject {
74+
@objc protocol MagnifierContainerViewDelegate: AnyObject {
7575

7676
func magnifierCenterPositionChanged(point: CGPoint, containerView: MagnifierContainerView)
7777

ArtOfAscii/Modules/BookCore.playgroundmodule/Sources/UserInterface/Chapters/01-ArtOfAscii/03-GrayscaleHistogramEqualization/Views/HistogramToolBarButtonView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class HistogramToolBarButtonView: ToolBarButtonView {
99

1010
var isRgbMode: Bool = false {
1111
didSet {
12-
updateAppearance()
12+
updateAppearanceForState()
1313
}
1414
}
1515

@@ -35,8 +35,8 @@ class HistogramToolBarButtonView: ToolBarButtonView {
3535
self.delegate?.toolBarButtonTapped(buttonView: self)
3636
}
3737

38-
override func updateAppearance() {
39-
super.updateAppearance()
38+
override func updateAppearanceForState() {
39+
super.updateAppearanceForState()
4040
if isRgbMode {
4141
self.button.setImage(UIImage(named: "toolbar/button-histogram-rgb"), for: .normal)
4242
} else {

0 commit comments

Comments
 (0)