add jpeg generation, refactor (#2)

This commit is contained in:
2025-03-27 22:09:43 +03:00
parent 878e3d7c05
commit 0e2806f80a
5 changed files with 222 additions and 102 deletions

63
settings.go Normal file
View File

@@ -0,0 +1,63 @@
package main
import (
"flag"
"fmt"
"image/color"
)
type colormode int
const (
cdefault colormode = iota
crandom
ctimed
crainbow
)
type outputmode int
const (
outputpng outputmode = iota
outputjpeg
)
type settings struct {
X, Y int // image size
Dots int // dots to draw for single image
BG color.Color // background color
CM colormode // settings for colorFunc
OM outputmode // what to output
Fname string // filename for output
}
func parseSettings() *settings {
var (
x, y int
dots int
cmode int
output int
fname string
)
flag.IntVar(&x, "x", 1920, "размер картинки по горизонтали")
flag.IntVar(&y, "y", 1080, "размер картинки по вертикали")
flag.IntVar(&dots, "d", 100000, "сколько точек рисовать")
flag.IntVar(&cmode, "c", 0, "color mode: 0 - default green, 1 - random, 2 - timed, 3 - rainbow")
flag.IntVar(&output, "o", 0, fmt.Sprintf("режим вывода: %d - png, %d - jpeg", outputpng, outputjpeg))
flag.StringVar(&fname, "out", "barnsley-fern.png", "полный путь файла для записи изображения")
flag.Parse()
s := &settings{
X: x,
Y: y,
Dots: dots,
BG: color.White,
CM: colormode(cmode),
OM: outputmode(output),
Fname: fname,
}
return s
}