use image().At to determine if its cool to draw an image at a location.
This commit is contained in:
parent
099438bd12
commit
92cda43897
35
grid.go
35
grid.go
|
@ -1,28 +1,29 @@
|
|||
package main
|
||||
|
||||
import "github.com/fogleman/gg"
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
// Grid is the represents the base image that houses various Bubbles and Lines.
|
||||
type Grid struct {
|
||||
DC *gg.Context
|
||||
X, Y int
|
||||
Bubbles [](*bubble)
|
||||
"github.com/fogleman/gg"
|
||||
)
|
||||
|
||||
Coord [][]bool
|
||||
}
|
||||
type bubbles map[string](*bubble)
|
||||
|
||||
func newGrid(x, y int) Grid {
|
||||
var g Grid
|
||||
g.X = x
|
||||
g.Y = y
|
||||
g.Bubbles = make([]*bubble, 0)
|
||||
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()
|
||||
|
||||
g.Coord = make([][]bool, y) //the initial value of a bool is false
|
||||
for i := range x {
|
||||
g.Coord[i] = make([]bool, x)
|
||||
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)
|
||||
}
|
||||
|
||||
return g
|
||||
return dc
|
||||
}
|
||||
|
||||
type bubble struct {
|
||||
|
|
18
main.go
18
main.go
|
@ -1,6 +1,20 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
bub := newBubble("hello world!", 16)
|
||||
bub.DC.SavePNG("hello.png")
|
||||
bs := make(bubbles)
|
||||
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