@@ -2,12 +2,23 @@ package gestures
22
33import (
44 "encoding/json"
5+ "math"
6+ "math/rand/v2"
57 "os"
8+ "time"
69
710 "github.com/ThatOtherAndrew/Hexecute/internal/config"
811 "github.com/ThatOtherAndrew/Hexecute/internal/models"
912)
1013
14+ type App struct {
15+ app * models.App
16+ }
17+
18+ func New (app * models.App ) * App {
19+ return & App {app : app }
20+ }
21+
1122func LoadGestures () ([]models.GestureConfig , error ) {
1223 configFile , err := config .GetPath ()
1324 if err != nil {
@@ -67,3 +78,43 @@ func SaveGesture(command string, templates [][]models.Point) error {
6778
6879 return os .WriteFile (configFile , data , 0644 )
6980}
81+
82+ func (a * App ) AddPoint (x , y float32 ) {
83+ newPoint := models.Point {X : x , Y : y , BornTime : time .Now ()}
84+
85+ shouldAdd := false
86+ if len (a .app .Points ) == 0 {
87+ shouldAdd = true
88+ } else {
89+ lastPoint := a .app .Points [len (a .app .Points )- 1 ]
90+ dx := newPoint .X - lastPoint .X
91+ dy := newPoint .Y - lastPoint .Y
92+ if dx * dx + dy * dy > 4 {
93+ shouldAdd = true
94+
95+ for range 3 {
96+ angle := rand .Float64 () * 2 * math .Pi
97+ speed := rand .Float32 ()* 50 + 20
98+ a .app .Particles = append (a .app .Particles , models.Particle {
99+ X : x + (rand .Float32 ()- 0.5 )* 10 ,
100+ Y : y + (rand .Float32 ()- 0.5 )* 10 ,
101+ VX : float32 (math .Cos (angle )) * speed ,
102+ VY : float32 (math .Sin (angle )) * speed ,
103+ Life : 1.0 ,
104+ MaxLife : 1.0 ,
105+ Size : rand .Float32 ()* 15 + 10 ,
106+ Hue : rand .Float32 (),
107+ })
108+ }
109+ }
110+ }
111+
112+ const MAX_POINTS = 2048
113+
114+ if shouldAdd {
115+ a .app .Points = append (a .app .Points , newPoint )
116+ if len (a .app .Points ) > MAX_POINTS {
117+ a .app .Points = a .app .Points [len (a .app .Points )- MAX_POINTS :]
118+ }
119+ }
120+ }
0 commit comments