XVisuals/types.go

56 lines
999 B
Go
Raw Normal View History

2024-10-22 18:34:39 +00:00
package main
import (
"image/color"
"math"
)
type Function interface {
Func(float64) uint16
}
type ColorArray struct {
img []color.Color
}
func NewColorArray() *ColorArray {
ca := &ColorArray{make([]color.Color, screenWidth*screenHeight)}
ca.Clear(color.Black)
return ca
}
func (ca *ColorArray) Clear(c color.Color) {
for i := 0; i < len(ca.img); i++ {
ca.img[i] = c
}
}
func (ca *ColorArray) At(x, y int) color.Color {
position := x + (y * screenHeight)
if position > len(ca.img) || position < 0 {
return color.Black
} else {
return ca.img[position]
}
}
func (ca *ColorArray) Set(x, y int, c color.Color) {
position := x + (y * screenHeight)
if position < len(ca.img) && position >= 0 {
ca.img[position] = c
}
}
type Position struct {
X int
Y int
}
func (p *Position) Length() float64 {
return math.Sqrt(float64(p.X)*float64(p.X) + float64(p.Y)*float64(p.Y))
}
func (p *Position) Dist(P *Position) float64 {
return (&Position{p.X - P.X, p.Y - P.Y}).Length()
}