Skip to content

Instantly share code, notes, and snippets.

@godrm
Created April 6, 2022 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godrm/082d493c5aa7cffcee412fa79545b44a to your computer and use it in GitHub Desktop.
Save godrm/082d493c5aa7cffcee412fa79545b44a to your computer and use it in GitHub Desktop.
HelloPlane 심볼 예제
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
}
}
import Foundation
var line = LineFactory.makeLine()
line.comment = "JK"
print(line.display())
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