-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormationDefinition.swift
73 lines (58 loc) · 2.09 KB
/
FormationDefinition.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
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
//
// FormationDefinition.swift
// Jikoku
//
// Created by Raphaël Calabro on 02/08/2017.
// Copyright © 2017 Raphaël Calabro. All rights reserved.
//
import Foundation
import Melisse
import GLKit
fileprivate let spacing: GLfloat = 8
protocol FormationDefinition {
var interval: TimeInterval { get }
var creationPoints: [Point<GLfloat>] { get }
}
struct NoFormationDefinition : FormationDefinition {
var interval: TimeInterval = 0.5
var creationPoints = [Point<GLfloat>(x: View.instance.width / 2, y: 0)]
}
class StationaryFormationDefinition : FormationDefinition {
let width: GLfloat
let interval: TimeInterval = 0.3
var creationPoints: [Point<GLfloat>] {
if points.isEmpty {
if width >= View.instance.width / 2 {
points = [
Point<GLfloat>(x: View.instance.width / 2, y: -width / 2),
Point<GLfloat>(x: View.instance.width / 2, y: -width / 2 - 20),
Point<GLfloat>(x: View.instance.width / 2, y: -width / 2 - 40),
]
} else {
let left = width / 2 + spacing
let right = View.instance.width - width / 2
let y = -width / 2
points = stride(from: left, to: right, by: width + spacing).flatMap { x -> [Point<GLfloat>] in
return [
Point(x: x, y: y),
Point(x: x, y: y - 20),
Point(x: x, y: y - 40)
]
}
}
}
return [points.removeAtRandom()]
}
fileprivate var points = [Point<GLfloat>]()
init(group: Group) {
self.width = group.size.pixelSize
}
}
struct QuarterCircleFormationDefinition : FormationDefinition {
let interval: TimeInterval = 0.2
let creationPoints: [Point<GLfloat>]
init(group: Group) {
let margin = -group.size.pixelSize - spacing
self.creationPoints = (0 ..< group.count / 6).map { index in Point<GLfloat>(x: 0, y: GLfloat(index) * margin) }
}
}