Created
April 6, 2022 10:51
-
-
Save godrm/082d493c5aa7cffcee412fa79545b44a to your computer and use it in GitHub Desktop.
HelloPlane 심볼 예제
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class LineFactory { | |
static var lineCount : Int = 0 | |
static func makeLine() -> Line { | |
return Line() | |
} | |
class func randomLine() -> Line { | |
let line = Line() | |
line.pointA.x = Int.random(in: 0...256) | |
return line | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var line = LineFactory.makeLine() | |
line.comment = "JK" | |
print(line.display()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum ColorCode { | |
case Black, White, Gray | |
} | |
typealias ShapeComment = String | |
struct Point<T> : CustomStringConvertible{ | |
var x : T | |
var y : T | |
var description : String { "Point(x:\(x), y:\(y))" } | |
} | |
protocol Shapable { | |
func display() -> String | |
} | |
extension Shapable { | |
func display() -> String { | |
return "shapable :: \(self)" | |
} | |
} | |
class Shape { | |
let color : ColorCode | |
var comment : ShapeComment | |
init() { | |
color = .Gray | |
comment = "" | |
} | |
deinit { | |
} | |
} | |
class Line : Shape, CustomStringConvertible, Shapable{ | |
var pointA : Point<Int> | |
var pointB : Point<Int> | |
override init() { | |
pointA = Point(x:0, y:0) | |
pointB = Point(x:10, y:5) | |
super.init() | |
} | |
var description : String { "Line \(color) = \(pointA) -> \(pointB)"} | |
func moved(vector: Point<Int>) -> (Point<Int>, Point<Int>) { | |
let nextA = Point(x: pointA.x + vector.x, y: pointA.y + vector.y) | |
let nextB = Point(x: pointB.x + vector.x, y: pointB.y + vector.y) | |
return (nextA, nextB) | |
} | |
func center() -> (x:Int, y:Int) { | |
return (x: (pointA.x + pointB.x)/2, y: (pointA.y + pointB.y)/2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment