Skip to content

Instantly share code, notes, and snippets.

@AmbroseNTK
Created March 12, 2021 10:48
Show Gist options
  • Save AmbroseNTK/29dbd2b4e23dbce899bff638537eeceb to your computer and use it in GitHub Desktop.
Save AmbroseNTK/29dbd2b4e23dbce899bff638537eeceb to your computer and use it in GitHub Desktop.
Heart in Go
package main
import (
"golang.org/x/tour/pic"
"math"
//"fmt"
)
func CalcHeart(t float64) (x,y float64) {
x = 16*math.Sin(t)*math.Sin(t)*math.Sin(t)
y = 13*math.Cos(t) - 5*math.Cos(2*t) - math.Cos(4*t)
return
}
func Pic(dx, dy int) [][]uint8 {
image := make([][]uint8, dy)
for i := 0; i < dy; i++ {
image[i] = make([]uint8, dx)
}
for i:=-1000;i<1000;i++{
x,y := CalcHeart(float64(i))
//fmt.Println(x," ",y)
ix := int(x)
iy := int(y)
//fmt.Println(ix," ",iy)
if ix > -128 && ix < 128 {
if iy > -128 && iy < 128 {
image[int((y+128))][int((x+128))] = 255
}
}
}
return image
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment