more new ideas
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"math/rand"
|
||||
|
||||
iu "git.nkpl.cc/twocookedfaggots/imageutils"
|
||||
)
|
||||
|
||||
func square(side int) image.Rectangle { return image.Rect(0, 0, side, side) }
|
||||
|
||||
func Circles(b image.Rectangle, radius int) chan iu.Circle {
|
||||
ch := make(chan iu.Circle)
|
||||
go func() {
|
||||
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))
|
||||
ch <- iu.Circle{image.Point{x, y}, r}
|
||||
}
|
||||
}()
|
||||
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))
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
var blackAndWhite = color.ModelFunc(
|
||||
func(c color.Color) color.Color {
|
||||
if color.Alpha16Model.Convert(c) == color.Transparent {
|
||||
return color.Black
|
||||
}
|
||||
return color.White
|
||||
},
|
||||
)
|
||||
|
||||
// Black and white's alpha image.
|
||||
type BlackAndWhite struct{ image.Image }
|
||||
|
||||
func (b BlackAndWhite) ColorModel() color.Model { return color.Gray16Model }
|
||||
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)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"os"
|
||||
)
|
||||
|
||||
type XORMask struct {
|
||||
dst, src image.Image
|
||||
}
|
||||
|
||||
func (m XORMask) ColorModel() color.Model { return color.Gray16Model }
|
||||
func (m XORMask) Bounds() image.Rectangle { return m.dst.Bounds() }
|
||||
func (m XORMask) At(x, y int) color.Color {
|
||||
srcColor := m.src.At(x, y)
|
||||
dstColor := m.dst.At(x, y)
|
||||
|
||||
if ((dstColor == color.Black) || (srcColor == color.Black)) &&
|
||||
!((dstColor == color.Black) && (srcColor == color.Black)) {
|
||||
return color.Black
|
||||
}
|
||||
return color.White
|
||||
}
|
||||
|
||||
func main() {
|
||||
img, err := png.Decode(os.Stdin)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
grayImg := image.NewGray16(img.Bounds())
|
||||
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
|
||||
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
|
||||
c := img.At(x, y)
|
||||
grayImg.Set(x, y, color.Gray16Model.Convert(c))
|
||||
}
|
||||
}
|
||||
canvas := image.NewRGBA(img.Bounds())
|
||||
circle := Circles(canvas.Bounds(), canvas.Bounds().Dy()/6)
|
||||
for i := 0; i < 24; i++ {
|
||||
c := <-circle
|
||||
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
|
||||
}
|
||||
|
||||
err = png.Encode(
|
||||
os.Stdout, XORMask{
|
||||
grayImg,
|
||||
BlackAndWhite{
|
||||
Exchange{
|
||||
canvas,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build upsampling
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"image"
|
||||
|
||||
"git.nkpl.cc/twocookedfaggots/imageutils/downscale"
|
||||
"git.nkpl.cc/twocookedfaggots/imageutils/util"
|
||||
)
|
||||
|
||||
var x = flag.Int("x", 256, "dx value of new bounds")
|
||||
var y = flag.Int("y", 256, "dy value of new bounds")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := util.ProcessStdio(func(img image.Image) image.Image {
|
||||
return downscale.GridDownscale{
|
||||
Image: img,
|
||||
Rectangle: image.Rect(0,0,x,y),
|
||||
}
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
var (
|
||||
x = flag.Int("x", 0, "")
|
||||
y = flag.Int("y", 0, "")
|
||||
size = flag.Int("size", 24, "size of font")
|
||||
// img = flag.String("path", "", "path to image")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
|
||||
|
||||
f, err := truetype.Parse(gomono.TTF)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
face := truetype.NewFace(f, &truetype.Options{
|
||||
Size: float64(img.Bounds().Dx() / size),
|
||||
DPI: 72,
|
||||
Hinting: font.HintingNone,
|
||||
})
|
||||
|
||||
d := &font.Drawer{
|
||||
Dst: dst,
|
||||
Src: image.NewUniform(color.Black),
|
||||
Face: face,
|
||||
Dot: fixed.Point26_6{fixed.Int26_6(img.Bounds().Dx() /
|
||||
x,
|
||||
),
|
||||
fixed.Int26_6(img.Bounds().Dy() /
|
||||
y,
|
||||
),
|
||||
},
|
||||
}
|
||||
d.DrawString(time.Now().Format(time.Kitchen))
|
||||
}
|
||||
Reference in New Issue
Block a user