use image().At to determine if its cool to draw an image at a location.
This commit is contained in:
parent
099438bd12
commit
92cda43897
39
grid.go
39
grid.go
|
@ -1,28 +1,29 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/fogleman/gg"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
// Grid is the represents the base image that houses various Bubbles and Lines.
|
"github.com/fogleman/gg"
|
||||||
type Grid struct {
|
)
|
||||||
DC *gg.Context
|
|
||||||
X, Y int
|
|
||||||
Bubbles [](*bubble)
|
|
||||||
|
|
||||||
Coord [][]bool
|
type bubbles map[string](*bubble)
|
||||||
|
|
||||||
|
func (b bubbles) draw(x int, y int) *gg.Context {
|
||||||
|
dc := gg.NewContext(x, y)
|
||||||
|
for key, i := range b {
|
||||||
|
px, py := 0, 0
|
||||||
|
noCollision := false
|
||||||
|
for !noCollision {
|
||||||
|
px, py = rand.Intn(x-i.SizeX)+i.SizeX/2, rand.Intn(y-i.SizeY)+i.SizeY/2
|
||||||
|
fr, fg, fb, fa := dc.Image().At(px, py).RGBA()
|
||||||
|
|
||||||
|
fmt.Printf("key: %v, keyX: %v, keyY: %v\npx: %v, py: %v\nred: %v, green: %v, blue: %v, alpha: %v\n", key, i.SizeX, i.SizeY, px, py, fr, fg, fb, fa)
|
||||||
|
}
|
||||||
|
dc.DrawImageAnchored(i.DC.Image(), px, py, 0.5, 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGrid(x, y int) Grid {
|
return dc
|
||||||
var g Grid
|
|
||||||
g.X = x
|
|
||||||
g.Y = y
|
|
||||||
g.Bubbles = make([]*bubble, 0)
|
|
||||||
|
|
||||||
g.Coord = make([][]bool, y) //the initial value of a bool is false
|
|
||||||
for i := range x {
|
|
||||||
g.Coord[i] = make([]bool, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
return g
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type bubble struct {
|
type bubble struct {
|
||||||
|
|
18
main.go
18
main.go
|
@ -1,6 +1,20 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bub := newBubble("hello world!", 16)
|
bs := make(bubbles)
|
||||||
bub.DC.SavePNG("hello.png")
|
bs["1"] = newBubble("hello", 16)
|
||||||
|
bs["2"] = newBubble("world", 16)
|
||||||
|
bs["3"] = newBubble("*glomps u*", 16)
|
||||||
|
bs["4"] = newBubble("penis", 16)
|
||||||
|
bs["5"] = newBubble("lol", 16)
|
||||||
|
bs["6"] = newBubble("colada", 16)
|
||||||
|
bs["7"] = newBubble("oh, woah", 16)
|
||||||
|
bs["8"] = newBubble("what's this?", 16)
|
||||||
|
bs["9"] = newBubble("best girl", 16)
|
||||||
|
bs["10"] = newBubble("icetal", 16)
|
||||||
|
bs["11"] = newBubble(":jadeteefs:", 16)
|
||||||
|
bs["12"] = newBubble("oct2pus", 16)
|
||||||
|
|
||||||
|
bs.draw(500, 500).SavePNG("hello.png")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue