holly molly
This commit is contained in:
commit
4ea00774ca
8
README.md
Normal file
8
README.md
Normal file
@ -0,0 +1,8 @@
|
||||
залил как есть
|
||||
любая кринжовая хуйня которая здесь найдется... просто зайбейте на это хуй, не обращайте внимания
|
||||
|
||||
запускается значится так:
|
||||
заходите в cmd и...
|
||||
> go run .
|
||||
|
||||
заходите в бровз и пишите адрес с портом
|
83
clock.go
Normal file
83
clock.go
Normal file
@ -0,0 +1,83 @@
|
||||
package clock
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"strconv"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"clock/imageutils"
|
||||
"clock/letter"
|
||||
)
|
||||
|
||||
func Check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
var img1, img2 = letter.Nums[6].Render(), letter.Nums[9].Render()
|
||||
|
||||
func DownRightBlank(img image.Image) image.Image {
|
||||
clr := color.White
|
||||
img = letter.Blank(img, clr, imageutils.Down)
|
||||
return letter.Blank(img, clr, imageutils.Right)
|
||||
}
|
||||
|
||||
func LeftUpBlank(img image.Image) image.Image {
|
||||
clr := color.White
|
||||
img = letter.Blank(img, clr, imageutils.Left)
|
||||
return letter.Blank(img, clr, imageutils.Up)
|
||||
}
|
||||
|
||||
func RenderNum(n int) image.Image {
|
||||
var img image.Image = image.NewRGBA(image.Rect(0,0,0,0))
|
||||
s := strconv.Itoa(n)
|
||||
for i := range s {
|
||||
n, err := strconv.Atoi(string(s[i]))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println(n)
|
||||
|
||||
num := letter.Nums[n].Render()
|
||||
num = DownRightBlank(num)
|
||||
img = imageutils.Concat(img, num, imageutils.Right)
|
||||
}
|
||||
img = LeftUpBlank(img)
|
||||
return img
|
||||
}
|
||||
|
||||
func RenderTime(t time.Time) image.Image {
|
||||
hour := RenderNum(t.Hour())
|
||||
if t.Hour() < 10 {
|
||||
hour = imageutils.Concat(
|
||||
DownRightBlank(letter.Empty), hour, imageutils.Right)
|
||||
}
|
||||
minute := RenderNum(t.Minute())
|
||||
if t.Minute() < 10 {
|
||||
minute = imageutils.Concat(
|
||||
DownRightBlank(letter.Empty), minute, imageutils.Right)
|
||||
}
|
||||
|
||||
img := imageutils.Concat(hour, minute, imageutils.Down)
|
||||
return img
|
||||
}
|
||||
|
||||
func Margin(img image.Image, length int) image.Image {
|
||||
for i := 0; i < length; i++ {
|
||||
img = LeftUpBlank(DownRightBlank(img))
|
||||
}
|
||||
return img
|
||||
}
|
||||
|
||||
func Time(w io.Writer) {
|
||||
t := time.Now()
|
||||
img := RenderTime(t)
|
||||
img = Margin(img, 3)
|
||||
img = imageutils.Scale(img, 1<<6)
|
||||
Check(png.Encode(w, img))
|
||||
|
||||
}
|
BIN
clock.test
Executable file
BIN
clock.test
Executable file
Binary file not shown.
12
clock_test.go
Normal file
12
clock_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
package clock
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"io"
|
||||
)
|
||||
|
||||
func BenchmarkNumber(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
Numbers(io.Discard)
|
||||
}
|
||||
}
|
26
cmd/main.go
Normal file
26
cmd/main.go
Normal file
@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"clock"
|
||||
// "clock/imageutils"
|
||||
)
|
||||
|
||||
func Check(err error) {
|
||||
if err != nil {
|
||||
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))
|
||||
}
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module clock
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/potassium5703/imageutils v0.0.0-20240501131630-56208ff04d2b
|
12
go.sum
Normal file
12
go.sum
Normal file
@ -0,0 +1,12 @@
|
||||
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}
|
||||
}
|
87
letter/image.go
Normal file
87
letter/image.go
Normal file
@ -0,0 +1,87 @@
|
||||
package letter
|
||||
|
||||
import (
|
||||
"clock/imageutils"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
)
|
||||
|
||||
type Letter string
|
||||
|
||||
var Nums = []Letter{
|
||||
"111101111",
|
||||
"010010010",
|
||||
"110010011",
|
||||
"111011111",
|
||||
"101111001",
|
||||
"011010110",
|
||||
"001111111",
|
||||
"111001001",
|
||||
"011111111",
|
||||
"111111001",
|
||||
}
|
||||
|
||||
var Empty = Letter("000000000").Render()
|
||||
|
||||
func (l Letter) ColorModel() color.Model {
|
||||
return color.RGBAModel
|
||||
}
|
||||
|
||||
func (l Letter) Bounds() image.Rectangle {
|
||||
return image.Rect(0, 0, 3, 3)
|
||||
}
|
||||
|
||||
func (l Letter) At(x, y int) color.Color {
|
||||
target := l[x+y*3]
|
||||
if target != '1' {
|
||||
return color.Alpha{}
|
||||
}
|
||||
return color.Black
|
||||
}
|
||||
|
||||
func (l Letter) Render() image.Image {
|
||||
img := image.NewRGBA(l.Bounds())
|
||||
draw.Draw(img, l.Bounds(), image.White, image.ZP, draw.Src)
|
||||
draw.Draw(img, l.Bounds(), l, image.ZP, draw.Over)
|
||||
return img
|
||||
}
|
||||
|
||||
type blank struct {
|
||||
image.Image
|
||||
color.Color
|
||||
imageutils.Side
|
||||
}
|
||||
|
||||
func (b blank) ColorModel() color.Model { return b.Image.ColorModel() }
|
||||
|
||||
func (b blank) Bounds() image.Rectangle {
|
||||
rect := image.Rectangle{}
|
||||
switch b.Side {
|
||||
case imageutils.Left:
|
||||
fallthrough
|
||||
case imageutils.Right:
|
||||
rect = image.Rectangle{
|
||||
image.ZP,
|
||||
image.Point{
|
||||
1, b.Image.Bounds().Dy(),
|
||||
},
|
||||
}
|
||||
case imageutils.Up:
|
||||
fallthrough
|
||||
case imageutils.Down:
|
||||
rect = image.Rectangle{
|
||||
image.ZP,
|
||||
image.Point{
|
||||
b.Image.Bounds().Dx(), 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
return rect
|
||||
}
|
||||
|
||||
func (b blank) At(x, y int) color.Color { return b.Color }
|
||||
|
||||
func Blank(img image.Image, clr color.Color, side imageutils.Side) image.Image {
|
||||
return imageutils.Concat(img, blank{img, clr, side}, side)
|
||||
}
|
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