-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence.go
43 lines (40 loc) · 970 Bytes
/
sequence.go
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
package main
import (
"github.com/go-gl/mathgl/mgl32"
)
func squareSpiral(n int) []mgl32.Vec3 {
out := make([]mgl32.Vec3, n)
up := mgl32.Vec3{0, 1, 0}
left := mgl32.Vec3{-1, 0, 0}
down := mgl32.Vec3{0, -1, 0}
right := mgl32.Vec3{1, 0, 0}
orbit := 0
i := 0
position := mgl32.Vec3{0, 0, 0}
base := -1
for i < n {
out[i] = position
i++
// compute the next position
switch {
case i == (2*orbit+1)*(2*orbit+1):
// go to the next orbit
orbit++
base = i - 1 // last index in the previous orbit
position = position.Add(left) // the first in the left arm
case i-base <= 2*orbit:
// still in the left arm
position = position.Add(up)
case i-base <= 4*orbit:
// still in the upper arm
position = position.Add(right)
case i-base <= 6*orbit:
// still in the right arm
position = position.Add(down)
case i-base <= 8*orbit:
// still in the lower arm
position = position.Add(left)
}
}
return out
}