6 Commits

Author SHA1 Message Date
7ecbcbecfd it works again 2025-08-17 22:18:03 +03:00
d54bf4d662 BB 2025-08-17 22:09:40 +03:00
d55b3cf864 emerge 2025-08-17 22:02:26 +03:00
c718034307 other location of imageutils 2024-08-20 06:32:21 +03:00
11f15e0c7d cleanin'up 2024-08-14 00:36:15 +03:00
19a89b5988 пересаживаемся на новые колеса 2024-08-14 00:34:01 +03:00
12 changed files with 23 additions and 331 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
child porn

View File

@@ -4,20 +4,14 @@ import (
"image" "image"
"image/color" "image/color"
"image/png" "image/png"
"strconv"
"io" "io"
"strconv"
"time" "time"
"git.niplace.ru/XoxJlopeZ_1488/clock/imageutils" "git.niplace.ru/XoxJlopeZi4BB/clock/letter"
"git.niplace.ru/XoxJlopeZ_1488/clock/letter" "git.niplace.ru/XoxJlopeZi4BB/imageutils"
) )
func Check(err error) {
if err != nil {
panic(err)
}
}
var img1, img2 = letter.Nums[6].Render(), letter.Nums[9].Render() var img1, img2 = letter.Nums[6].Render(), letter.Nums[9].Render()
func DownRightBlank(img image.Image) image.Image { func DownRightBlank(img image.Image) image.Image {
@@ -33,7 +27,7 @@ func LeftUpBlank(img image.Image) image.Image {
} }
func RenderNum(n int) image.Image { func RenderNum(n int) image.Image {
var img image.Image = image.NewRGBA(image.Rect(0,0,0,0)) var img image.Image = image.NewRGBA(image.Rect(0, 0, 0, 0))
s := strconv.Itoa(n) s := strconv.Itoa(n)
for i := range s { for i := range s {
n, err := strconv.Atoi(string(s[i])) n, err := strconv.Atoi(string(s[i]))
@@ -78,6 +72,9 @@ func Time(w io.Writer) {
img := RenderTime(t) img := RenderTime(t)
img = Margin(img, 3) img = Margin(img, 3)
img = imageutils.Scale(img, 1<<6) img = imageutils.Scale(img, 1<<6)
Check(png.Encode(w, img))
err := png.Encode(w, img)
if err != nil {
panic(err)
}
} }

Binary file not shown.

View File

@@ -1,8 +1,8 @@
package clock package clock
import ( import (
"testing"
"io" "io"
"testing"
) )
func BenchmarkNumber(b *testing.B) { func BenchmarkNumber(b *testing.B) {

View File

@@ -3,24 +3,20 @@ package main
import ( import (
"net/http" "net/http"
"git.niplace.ru/XoxJlopeZ_1488/clock" "git.niplace.ru/XoxJlopeZi4BB/clock"
// "clock/imageutils"
) )
func Check(err error) { func main() {
addrwithport := ":8080"
http.HandleFunc("/",
func(w http.ResponseWriter, req *http.Request) {
clock.Time(w)
},
)
println("this thingy running on", addrwithport)
err := http.ListenAndServe(addrwithport, nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
func main() {
addrwithport := "localhost:1488"
http.HandleFunc("/",
func(w http.ResponseWriter, req *http.Request){
clock.Time(w)
},
)
println("this thingy running on", addrwithport)
Check(http.ListenAndServe(addrwithport, nil))
}

BIN
cpu.log

Binary file not shown.

6
go.mod
View File

@@ -1,5 +1,3 @@
module git.niplace.ru/XoxJlopeZ_1488/clock module git.niplace.ru/XoxJlopeZi4BB/clock
go 1.22.2 go 1.26
require github.com/potassium5703/imageutils v0.0.0-20240501131630-56208ff04d2b

12
go.sum
View File

@@ -1,12 +0,0 @@
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=

View File

@@ -1,126 +0,0 @@
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})
}

View File

@@ -1,46 +0,0 @@
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}
}

View File

@@ -1,7 +1,6 @@
package letter package letter
import ( import (
"git.niplace.ru/XoxJlopeZ_1488/clock/imageutils"
"image" "image"
"image/color" "image/color"
"image/draw" "image/draw"

View File

@@ -1,115 +0,0 @@
//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
}