Repository navigation
Expand file tree
/
Copy pathNode.swift
More file actions
232 lines (232 loc) · 6.19 KB
/
Copy pathNode.swift
File metadata and controls
232 lines (232 loc) · 6.19 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
////
//// Node.swift
//// LSystem01
////
//// Created by Jeff Holtzkener on 4/4/16.
//// Copyright © 2016 Jeff Holtzkener. All rights reserved.
////
//
//import UIKit
//
//protocol L_SystemNode {
// var parent: L_SystemNode? { get set }
// var children: [L_SystemNode] { get set }
// var rootLocation: CGPoint? { get set }
// var orientation: CGFloat { get set }
// var location: CGPoint { get set }
// static var nodeColor: UIColor { get } // class
// static var angle: CGFloat { get } // class
// static var segmentLength: CGFloat { get } // class
//
//
// func spawn() -> [AbstractNode]
// func recursiveReposition()
//
//}
//
//extension L_SystemNode {
// var radius: CGFloat {
// return CGFloat(2)
// }
//
// func calcOrientation() -> CGFloat {
// print(Self.angle)
// if let parent = parent {
// return Self.angle + parent.orientation
// } else {
// return 0
// }
// }
//
// func calcLocation() -> CGPoint {
//
// if let parent = parent {
// let location = CGPoint(x: parent.location.x + Self.segmentLength * cos(self.orientation), y: parent.location.y + Self.segmentLength * sin(self.orientation))
// return location
// } else {
// return rootLocation!
// }
// }
//
//
//
//
//}
//
//class AbstractNode: UIView, L_SystemNode {
// var myColor: UIColor!
// var parent: L_SystemNode?
// var children = [L_SystemNode]()
// var orientation: CGFloat = 0
// var location: CGPoint = CGPoint.zero
// class var nodeColor: UIColor { // override
// return UIColor.clearColor()
// }
// class var angle: CGFloat {
// print("abstract node's")
// return 0
// }
//
// class var segmentLength: CGFloat {
// return 0
// }
//
// var rootLocation: CGPoint?
// override init(frame: CGRect) {
// super.init(frame: frame)
// }
//
// init(frame: CGRect, parent: L_SystemNode?, rootLocation: CGPoint?) {
// super.init(frame: frame)
// backgroundColor = UIColor.clearColor()
// if let parent = parent {
// self.parent = parent
//
// } else {
// self.rootLocation = rootLocation
// orientation = CGFloat( M_PI)
// }
// }
//
//
//
// required init?(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
// override func drawRect(rect: CGRect) {
// print("typeA drawRect")
// let rect = CGRect(x: location.x - radius, y: location.y - radius, width: radius * 2, height: radius * 2)
//
// let node = UIBezierPath(ovalInRect: rect)
// myColor.setFill()
// node.fill()
//
// if let parent = parent {
// let edge = UIBezierPath()
// edge.moveToPoint(parent.location)
// edge.addLineToPoint(location)
//
// UIColor.blackColor().colorWithAlphaComponent(0.5).setStroke()
// edge.lineWidth = 2
// edge.stroke()
// }
// }
//
// // override
// func spawn() -> [AbstractNode] {
// let first = TypeANode(frame: frame, parent: self, rootLocation: nil)
// self.superview?.addSubview(first)
//
// children.append(first)
// return [first]
// }
//
//
// func recursiveReposition() {
// print("old location \(location)")
// if let rootLocation = rootLocation {
// location = rootLocation // as before
// } else {
// orientation = calcOrientation()
// location = calcLocation()
// }
//
// for (i, _) in children.enumerate() {
// children[i].recursiveReposition()
// }
// print("new location \(location)")
//// setNeedsDisplay()
//
// }
//
//}
//
//
//class _TypeANode: AbstractNode {
// static var myAngle: CGFloat = CGFloat(M_PI)
// override static var nodeColor: UIColor {
// return UIColor.purpleColor()
// }
//
// override static var angle:CGFloat {
// print("returning myANgle")
// return myAngle
// }
// override static var segmentLength: CGFloat {
// return 60
// }
//
// override init(frame: CGRect, parent: L_SystemNode?, rootLocation: CGPoint?) {
// super.init(frame: frame, parent: parent, rootLocation: rootLocation)
// myColor = UIColor.purpleColor()
// orientation = calcOrientation()
// location = calcLocation()
// }
//
// required init?(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
//
//
// override func spawn() -> [AbstractNode] {
// var first = TypeBNode(frame: frame, parent: self, rootLocation: nil)
// var second = TypeANode(frame: frame, parent: self,rootLocation: nil)
// self.superview?.addSubview(first)
// self.superview?.addSubview(second)
//
// children.append(first)
// children.append(second)
// return [first, second]
// }
//
//
//
// }
//
//class _TypeBNode: AbstractNode {
// static var myAngle: CGFloat = CGFloat(M_PI / 2)
// override static var nodeColor: UIColor {
// return UIColor.blueColor()
// }
//
// override static var angle:CGFloat {
// return CGFloat( M_PI / 6)
// }
// override static var segmentLength: CGFloat {
// return myAngle
// }
//
// override init(frame: CGRect, parent: L_SystemNode?, rootLocation: CGPoint?) {
// super.init(frame: frame, parent: parent, rootLocation: rootLocation)
// myColor = UIColor.blueColor()
// orientation = calcOrientation()
// location = calcLocation()
// }
//
// required init?(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
// override func spawn() -> [AbstractNode] {
// var first = TypeANode(frame: frame, parent: self, rootLocation: nil)
// self.superview?.addSubview(first)
//
// return [first]
// }
//
//
//
//}
//
//extension CGFloat {
// var PI: CGFloat {
// return CGFloat(M_PI)
// }
//}
//
//
//
//
//