with the power of vibecoding...
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
iu "git.nkpl.cc/twocookedfaggots/imageutils"
|
iu "git.nkpl.cc/twocookedfaggots/imageutils"
|
||||||
@@ -27,28 +27,63 @@ func Circles(b image.Rectangle, radius int) chan iu.Circle {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts color.Opaque and color.Transparent to color.Black and color.White respectively.
|
var Opaque, Transparent = color.Alpha{0xff}, color.Alpha{0}
|
||||||
var BlackAndWhite = color.ModelFunc(
|
|
||||||
func(c color.Color) color.Color {
|
type xor struct{ dst, src image.Image }
|
||||||
if color.AlphaModel.Convert(c) == color.Opaque {
|
|
||||||
return color.Black
|
func (t xor) ColorModel() color.Model { return t.dst.ColorModel() }
|
||||||
|
func (t xor) Bounds() image.Rectangle { return t.src.Bounds() }
|
||||||
|
func (t xor) At(x, y int) color.Color {
|
||||||
|
dstColor := t.ColorModel().Convert(t.dst.At(x, y))
|
||||||
|
srcColor := t.ColorModel().Convert(t.src.At(x, y))
|
||||||
|
|
||||||
|
|
||||||
|
if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) &&
|
||||||
|
!((dstColor == color.Opaque) && (srcColor == color.Opaque)) {
|
||||||
|
return color.Opaque
|
||||||
}
|
}
|
||||||
return color.White
|
return color.Transparent
|
||||||
|
}
|
||||||
|
|
||||||
|
var exchange = color.ModelFunc(
|
||||||
|
func(c color.Color) color.Color {
|
||||||
|
if color.Alpha16Model.Convert(c) == color.Transparent{
|
||||||
|
return color.Opaque
|
||||||
|
}
|
||||||
|
return color.Transparent
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Exchange struct { image.Image }
|
||||||
|
|
||||||
|
func (e Exchange) ColorModel() color.Model { return color.Alpha16Model }
|
||||||
|
func (e Exchange) Bounds() image.Rectangle { return e.Image.Bounds() }
|
||||||
|
func (e Exchange) At(x, y int) color.Color {
|
||||||
|
c := e.ColorModel().Convert(e.Image.At(x, y))
|
||||||
|
return exchange.Convert(c)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
canvas := image.NewRGBA(square(1024))
|
canvas := image.NewAlpha16(square(1024))
|
||||||
circles := Circles(canvas.Bounds(), 1024/16)
|
circles := Circles(canvas.Bounds(), 1024/7)
|
||||||
|
|
||||||
// draw n circles
|
// draw n circles
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 500; i++ {
|
||||||
c := <-circles
|
c := <-circles
|
||||||
|
|
||||||
|
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
|
||||||
|
/*
|
||||||
draw.DrawMask(
|
draw.DrawMask(
|
||||||
canvas, canvas.Bounds(), &image.Uniform{color.White},
|
canvas, canvas.Bounds(), &image.Uniform{color.White},
|
||||||
image.Point{}, c, image.Point{}, draw.Over,
|
image.Point{}, xor{c, canvas}, image.Point{}, draw.Src,
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
newCanvas := image.NewRGBA(canvas.Bounds())
|
||||||
|
draw.Draw(newCanvas, newCanvas.Bounds(), &image.Uniform{color.RGBA{255, 255, 0, 255}}, image.ZP, draw.Over)
|
||||||
|
draw.Draw(newCanvas, newCanvas.Bounds(), canvas, image.ZP, draw.Over)
|
||||||
|
*/
|
||||||
err := png.Encode(os.Stdout, canvas)
|
err := png.Encode(os.Stdout, canvas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user