with the power of vibecoding...
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
||||
iu "git.nkpl.cc/twocookedfaggots/imageutils"
|
||||
@@ -19,36 +19,71 @@ func Circles(b image.Rectangle, radius int) chan iu.Circle {
|
||||
defer close(ch)
|
||||
for {
|
||||
x, y := rand.Int()%b.Dx(), rand.Int()%b.Dy()
|
||||
dxdy := b.Dx()*b.Dy()
|
||||
r := rand.Int() % (dxdy/(dxdy/radius))
|
||||
dxdy := b.Dx() * b.Dy()
|
||||
r := rand.Int() % (dxdy / (dxdy / radius))
|
||||
ch <- iu.Circle{image.Point{x, y}, r}
|
||||
}
|
||||
}()
|
||||
return ch
|
||||
}
|
||||
|
||||
// Converts color.Opaque and color.Transparent to color.Black and color.White respectively.
|
||||
var BlackAndWhite = color.ModelFunc(
|
||||
var Opaque, Transparent = color.Alpha{0xff}, color.Alpha{0}
|
||||
|
||||
type xor struct{ dst, src image.Image }
|
||||
|
||||
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.Transparent
|
||||
}
|
||||
|
||||
var exchange = color.ModelFunc(
|
||||
func(c color.Color) color.Color {
|
||||
if color.AlphaModel.Convert(c) == color.Opaque {
|
||||
return color.Black
|
||||
if color.Alpha16Model.Convert(c) == color.Transparent{
|
||||
return color.Opaque
|
||||
}
|
||||
return color.White
|
||||
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() {
|
||||
canvas := image.NewRGBA(square(1024))
|
||||
circles := Circles(canvas.Bounds(), 1024/16)
|
||||
canvas := image.NewAlpha16(square(1024))
|
||||
circles := Circles(canvas.Bounds(), 1024/7)
|
||||
|
||||
// draw n circles
|
||||
for i := 0; i < 100; i++ {
|
||||
for i := 0; i < 500; i++ {
|
||||
c := <-circles
|
||||
|
||||
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
|
||||
/*
|
||||
draw.DrawMask(
|
||||
canvas, canvas.Bounds(), &image.Uniform{color.White},
|
||||
image.Point{}, c, image.Point{}, draw.Over,
|
||||
canvas, canvas.Bounds(), &image.Uniform{color.White},
|
||||
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)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user