more new ideas

This commit is contained in:
2026-06-20 11:31:44 +03:00
parent 67ff655767
commit 559a4e9175
20 changed files with 395 additions and 65 deletions
+15 -41
View File
@@ -27,24 +27,6 @@ func Circles(b image.Rectangle, radius int) chan iu.Circle {
return ch
}
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.Alpha16Model.Convert(c) == color.Transparent{
@@ -63,29 +45,21 @@ func (e Exchange) At(x, y int) color.Color {
return exchange.Convert(c)
}
func main() {
canvas := image.NewAlpha16(square(1024))
circles := Circles(canvas.Bounds(), 1024/7)
var blackAndWhite = color.ModelFunc(
func(c color.Color) color.Color {
if color.Alpha16Model.Convert(c) == color.Transparent{
return color.Black
}
return color.White
},
)
// draw n circles
for i := 0; i < 500; i++ {
c := <-circles
// Black and white's alpha image.
type BlackAndWhite struct { image.Image }
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
/*
draw.DrawMask(
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)
}
func (b BlackAndWhite) ColorModel() color.Model { return color.GrayModel }
func (b BlackAndWhite) Bounds() image.Rectangle { return b.Image.Bounds() }
func (b BlackAndWhite) At(x, y int) color.Color {
c := b.Image.At(x, y)
return blackAndWhite.Convert(c)
}
+24
View File
@@ -0,0 +1,24 @@
//go:build colored
package main
/*
const (
red = iota
green
blue
)
*/
func main() {
canvas := image.NewRGBA(image.Rect(0, 0, 3840, 2160))
circles := Circles(canvas.Bounds(), 2160/6)
palette := []color.Color{
color.RGBA{R:255, A:255},
color.RGBA{G:255, A:255},
color.RGBA{B:255, A:255},
}
c := palette[rand.Int()%2]
}
+28
View File
@@ -0,0 +1,28 @@
package main
func main() {
canvas := image.NewRGBA(image.Rect(0, 0, 3840, 2160))
circles := Circles(canvas.Bounds(), 2160/6)
// draw n circles
for i := 0; i < 24; 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{}, 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, BlackAndWhite{canvas})
if err != nil {
panic(err)
}
}
+19
View File
@@ -0,0 +1,19 @@
package main
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))
// xor operation (a || b) && !(a && b)
if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) &&
!((dstColor == color.Opaque) && (srcColor == color.Opaque)) {
return color.Opaque
}
return color.Transparent
}
+3
View File
@@ -0,0 +1,3 @@
package main