tangled
alpha
login
or
join now
voigt.tngl.sh
/
firefly-zero-playground
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
2
pipelines
add coordinate system
voigt.tngl.sh
2 months ago
e7ec68ee
0de54f2f
verified
This commit was signed with the committer's
known signature
.
voigt.tngl.sh
SSH Key Fingerprint:
SHA256:6ShT3iHt6IpCPJtT9Ndevva6c3xzr4RI2LrvKeOXH2U=
+102
3 changed files
expand all
collapse all
unified
split
coordinates
go.mod
go.sum
main.go
+4
coordinates/go.mod
reviewed
···
1
1
module controllingdot
2
2
3
3
go 1.25.0
4
4
+
5
5
+
require github.com/firefly-zero/firefly-go v0.9.5
6
6
+
7
7
+
require github.com/orsinium-labs/tinymath v1.0.0 // indirect
+4
coordinates/go.sum
reviewed
···
1
1
+
github.com/firefly-zero/firefly-go v0.9.5 h1:BzBr4t76bDVVFwNaWJixs1XasqLNBIdg0k9JXblBfU4=
2
2
+
github.com/firefly-zero/firefly-go v0.9.5/go.mod h1:+X/XGyPdES51OESkV8NSf1mszEBZionoROM7x2pBofw=
3
3
+
github.com/orsinium-labs/tinymath v1.0.0 h1:Uzp3GmjWIBxMObx4MQi9ACDu4Q8WKjSRakB1OMo9Bu0=
4
4
+
github.com/orsinium-labs/tinymath v1.0.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A=
+94
coordinates/main.go
reviewed
···
1
1
+
package main
2
2
+
3
3
+
import (
4
4
+
"github.com/firefly-zero/firefly-go/firefly"
5
5
+
)
6
6
+
7
7
+
var (
8
8
+
font firefly.Font
9
9
+
cheatShowCoordinateSystem bool = true
10
10
+
)
11
11
+
12
12
+
const SCREENWIDTH = 240
13
13
+
const SCREENHEIGHT = 160
14
14
+
15
15
+
func init() {
16
16
+
firefly.Cheat = cheat
17
17
+
firefly.Boot = boot
18
18
+
firefly.Render = render
19
19
+
}
20
20
+
21
21
+
func cheat(cmd, val int) int {
22
22
+
switch cmd {
23
23
+
case 1:
24
24
+
cheatShowCoordinateSystem = !cheatShowCoordinateSystem
25
25
+
return 0
26
26
+
default:
27
27
+
return 0
28
28
+
}
29
29
+
}
30
30
+
31
31
+
func boot() {
32
32
+
font = firefly.LoadFile("font", nil).Font()
33
33
+
}
34
34
+
func render() {
35
35
+
firefly.ClearScreen(firefly.ColorWhite)
36
36
+
if cheatShowCoordinateSystem {
37
37
+
drawCoordinateSystem()
38
38
+
} else {
39
39
+
firefly.ClearScreen(firefly.ColorNone)
40
40
+
}
41
41
+
}
42
42
+
43
43
+
func translatePoint(p firefly.Point) firefly.Point {
44
44
+
x := p.X + SCREENWIDTH/2
45
45
+
y := -p.Y + SCREENHEIGHT/2
46
46
+
// firefly.LogDebug(strings.Join([]string{"x: ", strconv.Itoa(x), ", y: ", strconv.Itoa(y)}, " "))
47
47
+
return firefly.Point{X: x, Y: y}
48
48
+
}
49
49
+
50
50
+
func drawCoordinateSystem() {
51
51
+
firefly.DrawLine(translatePoint(firefly.Point{X: 0, Y: -SCREENHEIGHT / 2}), translatePoint(firefly.Point{X: 0, Y: SCREENHEIGHT / 2}), firefly.LineStyle{Color: firefly.ColorLightGray, Width: 1})
52
52
+
firefly.DrawLine(translatePoint(firefly.Point{X: -SCREENWIDTH / 2, Y: 0}), translatePoint(firefly.Point{X: SCREENWIDTH / 2, Y: 0}), firefly.LineStyle{Color: firefly.ColorLightGray, Width: 1})
53
53
+
54
54
+
for i := 0; i < SCREENWIDTH; i += 5 {
55
55
+
// x ->
56
56
+
if (SCREENWIDTH+i)%5 == 0 {
57
57
+
firefly.DrawPoint(translatePoint(firefly.Point{X: i, Y: -1}), firefly.ColorLightGray)
58
58
+
}
59
59
+
if (SCREENWIDTH+i)%10 == 0 {
60
60
+
firefly.DrawPoint(translatePoint(firefly.Point{X: i, Y: -2}), firefly.ColorLightGray)
61
61
+
}
62
62
+
// <- x
63
63
+
if (SCREENWIDTH+i)%5 == 0 {
64
64
+
firefly.DrawPoint(translatePoint(firefly.Point{X: -i, Y: -1}), firefly.ColorLightGray)
65
65
+
}
66
66
+
if (SCREENWIDTH+i)%10 == 0 {
67
67
+
firefly.DrawPoint(translatePoint(firefly.Point{X: -i, Y: -2}), firefly.ColorLightGray)
68
68
+
}
69
69
+
70
70
+
// y ^
71
71
+
if (SCREENHEIGHT+i)%5 == 0 {
72
72
+
firefly.DrawPoint(translatePoint(firefly.Point{X: -1, Y: i}), firefly.ColorLightGray)
73
73
+
}
74
74
+
if (SCREENWIDTH+i)%10 == 0 {
75
75
+
firefly.DrawPoint(translatePoint(firefly.Point{X: -2, Y: i}), firefly.ColorLightGray)
76
76
+
}
77
77
+
// y v
78
78
+
if (SCREENHEIGHT+i)%5 == 0 {
79
79
+
firefly.DrawPoint(translatePoint(firefly.Point{X: -1, Y: -i}), firefly.ColorLightGray)
80
80
+
}
81
81
+
if (SCREENWIDTH+i)%10 == 0 {
82
82
+
firefly.DrawPoint(translatePoint(firefly.Point{X: -2, Y: -i}), firefly.ColorLightGray)
83
83
+
}
84
84
+
}
85
85
+
86
86
+
firefly.DrawText(
87
87
+
"y",
88
88
+
font, translatePoint(firefly.Point{X: -8, Y: (SCREENHEIGHT / 2) - 8}), firefly.ColorLightGray,
89
89
+
)
90
90
+
firefly.DrawText(
91
91
+
"x",
92
92
+
font, translatePoint(firefly.Point{X: (SCREENWIDTH/2 - 5), Y: -8}), firefly.ColorLightGray,
93
93
+
)
94
94
+
}