Compare commits
No commits in common. "master" and "1.0.0" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
child porn
|
2
clock.go
2
clock.go
@ -8,7 +8,7 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/potassium5703/imageutils"
|
||||
"git.niplace.ru/XoxJlopeZ_1488/clock/imageutils"
|
||||
"git.niplace.ru/XoxJlopeZ_1488/clock/letter"
|
||||
)
|
||||
|
||||
|
BIN
clock.test
Executable file
BIN
clock.test
Executable file
Binary file not shown.
@ -14,7 +14,7 @@ func Check(err error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
addrwithport := ":8080"
|
||||
addrwithport := "localhost:1488"
|
||||
http.HandleFunc("/",
|
||||
func(w http.ResponseWriter, req *http.Request){
|
||||
clock.Time(w)
|
||||
|
2
go.mod
2
go.mod
@ -2,4 +2,4 @@ module git.niplace.ru/XoxJlopeZ_1488/clock
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/potassium5703/imageutils v0.0.0-20240510093354-04c781c03a25
|
||||
require github.com/potassium5703/imageutils v0.0.0-20240501131630-56208ff04d2b
|
||||
|
14
go.sum
14
go.sum
@ -1,2 +1,12 @@
|
||||
github.com/potassium5703/imageutils v0.0.0-20240510093354-04c781c03a25 h1:HLqfANMhaSvT5j1S8GTdUr9/+MN6OcAeI+YkjPqDTQc=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240510093354-04c781c03a25/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501100225-479bfc4e86ba h1:8SW0WzADxgL//JdAFii8679Zzz0pcRqo87D14EbiM2E=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501100225-479bfc4e86ba/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501125036-f4985ae53c0e h1:qmuIoXkeHbsMGKsAwbyfxHIb+uBHH17GfT3AQsdS3HM=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501125036-f4985ae53c0e/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501130104-303bd59901b0 h1:YVngGzaFlXsTEAbm4ZvH7rjS8gRdkqDClRfuiIYRGZ0=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501130104-303bd59901b0/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501130520-b4a0a68a1c4f h1:bREjGPiLXCnRgV3BVSSF7XvOK6LDIeOG5wHZPGdy95A=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501130520-b4a0a68a1c4f/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501130831-8bbcc64472a5 h1:u5MEXSiQebdDspOHQMa4S3bEl0IY1V8gEmld4t8N8g0=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501130831-8bbcc64472a5/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501131630-56208ff04d2b h1:n0wsMMhfnWvD9xO2ri5rWOQMtLgKzOJtQVBjcNIMeZ4=
|
||||
github.com/potassium5703/imageutils v0.0.0-20240501131630-56208ff04d2b/go.mod h1:eTB7aSWxiurq6gf9A8pZMtwBZAEYRws37EH0Uytaafo=
|
||||
|
126
imageutils/concat.go
Normal file
126
imageutils/concat.go
Normal file
@ -0,0 +1,126 @@
|
||||
package imageutils
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
)
|
||||
|
||||
type Side int
|
||||
|
||||
const (
|
||||
Left Side = iota
|
||||
Right
|
||||
Up
|
||||
Down
|
||||
)
|
||||
|
||||
type pair struct {
|
||||
first, second image.Image
|
||||
side Side
|
||||
}
|
||||
|
||||
// Takes color.Model of the first Image.
|
||||
func (p pair) ColorModel() color.Model { return p.first.ColorModel() }
|
||||
|
||||
func (p pair) Bounds() image.Rectangle {
|
||||
var (
|
||||
b1 = p.first.Bounds()
|
||||
b2 = p.second.Bounds()
|
||||
)
|
||||
|
||||
point := image.Point{}
|
||||
switch p.side {
|
||||
case Left:
|
||||
fallthrough
|
||||
case Right:
|
||||
point = image.Point{
|
||||
X: b1.Dx() + b2.Dx(),
|
||||
Y: max(b1.Dy(), b2.Dy()),
|
||||
}
|
||||
case Up:
|
||||
fallthrough
|
||||
case Down:
|
||||
point = image.Point{
|
||||
X: max(b1.Dx(), b2.Dx()),
|
||||
Y: b1.Dy() + b2.Dy(),
|
||||
}
|
||||
}
|
||||
return image.Rectangle{
|
||||
image.ZP,
|
||||
point,
|
||||
}
|
||||
}
|
||||
|
||||
func (p pair) At(x, y int) color.Color {
|
||||
img := image.NewRGBA(p.Bounds())
|
||||
|
||||
point := image.Point{}
|
||||
switch p.side {
|
||||
case Left:
|
||||
p.first, p.second = p.second, p.first
|
||||
fallthrough
|
||||
case Right:
|
||||
point = image.Point{-p.first.Bounds().Dx(), 0}
|
||||
case Up:
|
||||
p.first, p.second = p.second, p.first
|
||||
fallthrough
|
||||
case Down:
|
||||
point = image.Point{0, -p.first.Bounds().Dy()}
|
||||
}
|
||||
// draw main
|
||||
draw.Draw(
|
||||
img, img.Bounds(),
|
||||
p.first,
|
||||
image.ZP, draw.Src,
|
||||
)
|
||||
|
||||
// draw second
|
||||
draw.Draw(
|
||||
img, p.Bounds(),
|
||||
p.second,
|
||||
point,
|
||||
draw.Src,
|
||||
)
|
||||
|
||||
return img.At(x, y)
|
||||
}
|
||||
|
||||
func render(p pair) image.Image {
|
||||
img := image.NewRGBA(p.Bounds())
|
||||
|
||||
point := image.Point{}
|
||||
switch p.side {
|
||||
case Left:
|
||||
p.first, p.second = p.second, p.first
|
||||
fallthrough
|
||||
case Right:
|
||||
point = image.Point{-p.first.Bounds().Dx(), 0}
|
||||
case Up:
|
||||
p.first, p.second = p.second, p.first
|
||||
fallthrough
|
||||
case Down:
|
||||
point = image.Point{0, -p.first.Bounds().Dy()}
|
||||
}
|
||||
// draw main
|
||||
draw.Draw(
|
||||
img, img.Bounds(),
|
||||
p.first,
|
||||
image.ZP, draw.Src,
|
||||
)
|
||||
|
||||
// draw second
|
||||
draw.Draw(
|
||||
img, p.Bounds(),
|
||||
p.second,
|
||||
point,
|
||||
draw.Src,
|
||||
)
|
||||
|
||||
return img
|
||||
}
|
||||
|
||||
// Concat concatenates second image on a given side.
|
||||
func Concat(i1, i2 image.Image, s Side) image.Image {
|
||||
return render(pair{i1, i2, s})
|
||||
}
|
46
imageutils/scale.go
Normal file
46
imageutils/scale.go
Normal file
@ -0,0 +1,46 @@
|
||||
package imageutils
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
type rescaled struct {
|
||||
src image.Image
|
||||
scale int
|
||||
}
|
||||
|
||||
// ColorModel implements image.Image interface
|
||||
func (r rescaled) ColorModel() color.Model {
|
||||
return r.src.ColorModel()
|
||||
}
|
||||
|
||||
// Bounds implements image.Image interface
|
||||
func (r rescaled) Bounds() image.Rectangle {
|
||||
b := r.src.Bounds()
|
||||
return image.Rectangle{
|
||||
Min: image.Point{
|
||||
X: b.Min.X,
|
||||
Y: b.Min.Y,
|
||||
},
|
||||
Max: image.Point{
|
||||
X: b.Max.X * r.scale,
|
||||
Y: b.Max.Y * r.scale,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// At implements image.Image interface
|
||||
func (r rescaled) At(x, y int) color.Color {
|
||||
return r.src.At(x/r.scale, y/r.scale)
|
||||
}
|
||||
|
||||
// Scale scales image.Image to a given scale
|
||||
// and then returns image.Image.
|
||||
// For now it will work only with positive integers.
|
||||
func Scale(img image.Image, scale int) image.Image {
|
||||
if scale < 1 {
|
||||
scale = 1
|
||||
}
|
||||
return rescaled{img, scale}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package letter
|
||||
|
||||
import (
|
||||
"github.com/potassium5703/imageutils"
|
||||
"git.niplace.ru/XoxJlopeZ_1488/clock/imageutils"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
|
115
swastika.go
Normal file
115
swastika.go
Normal file
@ -0,0 +1,115 @@
|
||||
//go:build nazis_hitler_AGHAGHAAHHAHAHAH
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func Check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
var numbers = []int{23, 20, 31, 5, 29}
|
||||
|
||||
func DoubleChars(r io.Reader) io.Reader {
|
||||
const n = 2
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
scanner := bufio.NewScanner(r)
|
||||
buf := bufio.NewWriter(pw)
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
Check(pw.Close())
|
||||
}()
|
||||
defer func() {
|
||||
Check(buf.Flush())
|
||||
}()
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
for i := range text {
|
||||
s := make([]byte, n, n)
|
||||
for j := 0; j < n; j++ {
|
||||
s[j] = text[i]
|
||||
}
|
||||
buf.Write(s)
|
||||
}
|
||||
_, err := buf.Write([]byte{'\n'})
|
||||
Check(err)
|
||||
}
|
||||
}()
|
||||
return pr
|
||||
}
|
||||
|
||||
func Tr(r io.Reader, m map[byte]byte) io.Reader {
|
||||
pr, pw := io.Pipe()
|
||||
r = bufio.NewReader(r)
|
||||
buf := bufio.NewWriter(pw)
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
Check(pw.Close())
|
||||
}()
|
||||
defer func() {
|
||||
Check(buf.Flush())
|
||||
}()
|
||||
loop:
|
||||
for {
|
||||
bs := make([]byte, 1)
|
||||
_, err := r.Read(bs)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case io.EOF:
|
||||
break loop
|
||||
default:
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b, ok := m[bs[0]]
|
||||
if !ok {
|
||||
b = bs[0]
|
||||
}
|
||||
buf.Write([]byte{b})
|
||||
}
|
||||
}()
|
||||
return pr
|
||||
}
|
||||
|
||||
func BinaryChar() io.Reader {
|
||||
tr := map[byte]byte{
|
||||
'0': ' ',
|
||||
'1': '#',
|
||||
}
|
||||
|
||||
r := func(r io.Reader) io.Reader {
|
||||
return Tr(r, tr)
|
||||
}(func(r io.Reader) io.Reader {
|
||||
return DoubleChars(r)
|
||||
}(func(nums []int) io.Reader {
|
||||
pr, pw := io.Pipe()
|
||||
buf := bufio.NewWriter(pw)
|
||||
|
||||
go func(w io.Writer) {
|
||||
defer func() {
|
||||
Check(pw.Close())
|
||||
}()
|
||||
defer func() {
|
||||
Check(buf.Flush())
|
||||
}()
|
||||
for i := range nums {
|
||||
fmt.Fprintf(w,
|
||||
fmt.Sprintf("%%0%db\n",
|
||||
len(nums)),
|
||||
nums[i])
|
||||
}
|
||||
}(buf)
|
||||
|
||||
return pr
|
||||
}(numbers)))
|
||||
return r
|
||||
}
|
Loading…
Reference in New Issue
Block a user