This commit is contained in:
Ingy döt Net 2013-04-10 16:19:29 -07:00
parent e5e8880e41
commit 518da4a923
1019 changed files with 15877 additions and 0 deletions

View file

@ -0,0 +1,17 @@
package raster
func (b *Bitmap) Flood(x, y int, repl Pixel) {
targ, _ := b.GetPx(x, y)
var ff func(x, y int)
ff = func(x, y int) {
p, ok := b.GetPx(x, y)
if ok && p.R == targ.R && p.G == targ.G && p.B == targ.B {
b.SetPx(x, y, repl)
ff(x-1, y)
ff(x+1, y)
ff(x, y-1)
ff(x, y+1)
}
}
ff(x, y)
}

View file

@ -0,0 +1,20 @@
package main
import (
"fmt"
"raster"
)
func main() {
b, err := raster.ReadPpmFile("Unfilledcirc.ppm")
if err != nil {
fmt.Println(err)
return
}
b.Flood(200, 200, raster.Pixel{127, 0, 0})
err = b.WritePpmFile("flood.ppm")
if err != nil {
fmt.Println(err)
return
}
}