diff --git a/internal/captcha/dwelling_captcha.go b/internal/captcha/dwelling_captcha.go index a5eb7d0..e2df229 100644 --- a/internal/captcha/dwelling_captcha.go +++ b/internal/captcha/dwelling_captcha.go @@ -1,10 +1,9 @@ package captcha import ( - "crypto/rand" "image" "justcaptcha/pkg/captcha" - "math/big" + "math/rand" "time" "github.com/fogleman/gg" @@ -47,30 +46,28 @@ func (c *DwellingCaptcha) generateImage(style string) *image.Image { ctx.DrawStringAnchored(string(c.GetAnswer()), 20, 5, .5, .5) // draw lines and points + h := float64(ctx.Height()) - ctx.SetRGB255(0x9f, 0x2b, 0x68) - for i := 0; i < 16; i++ { - x0, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) - x1, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) - r, _ := rand.Int(rand.Reader, big.NewInt(int64(4))) - ctx.SetLineWidth(2) - ctx.DrawPoint(float64(x0.Int64()), float64(x1.Int64()), float64(r.Int64())) - ctx.DrawLine(float64(x0.Int64()), 0, float64(ctx.Height()), float64(x1.Int64())) - ctx.Stroke() - } - - for i := 0; i < 16; i++ { - x0, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) - x1, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) - r, _ := rand.Int(rand.Reader, big.NewInt(int64(4))) - ctx.SetLineWidth(2) - ctx.DrawPoint(float64(x0.Int64()), float64(x1.Int64()), float64(r.Int64())) - ctx.DrawLine(0, float64(x0.Int64()), float64(x1.Int64()), float64(ctx.Height())) + for i := 0; i < 24; i++ { + x0 := rand.Float64() * h + x1 := rand.Float64() * h + x2 := rand.Float64() * h + x3 := rand.Float64() * h + ctx.DrawLine(x0, 0, h, x1) + ctx.DrawLine(0, x2, x3, h) + r := rand.Intn(256) + g := rand.Intn(256) + b := rand.Intn(256) + ctx.SetRGB255(r, g, b) + lw := float64(rand.Float32() * 4.0) + if lw == 0 { + lw = 0.1 + } + ctx.SetLineWidth(lw) ctx.Stroke() } c.Image = ctx.Image() - return &c.Image }