A simple refactor of generateImage() rearranging method calls in for loops.

This commit is contained in:
Alexander Andreev 2022-06-27 01:25:28 +04:00
parent ffbc79ce4b
commit 504a8d137f
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -43,8 +43,8 @@ func (c *DwellingCaptcha) generateImage(style string) *image.Image {
for i := 0; i < 16; i++ { for i := 0; i < 16; i++ {
x0, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) x0, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height())))
x1, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) x1, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height())))
ctx.SetLineWidth(2)
r, _ := rand.Int(rand.Reader, big.NewInt(int64(4))) r, _ := rand.Int(rand.Reader, big.NewInt(int64(4)))
ctx.SetLineWidth(2)
ctx.DrawPoint(float64(x0.Int64()), float64(x1.Int64()), float64(r.Int64())) ctx.DrawPoint(float64(x0.Int64()), float64(x1.Int64()), float64(r.Int64()))
ctx.DrawLine(float64(x0.Int64()), 0, float64(ctx.Height()), float64(x1.Int64())) ctx.DrawLine(float64(x0.Int64()), 0, float64(ctx.Height()), float64(x1.Int64()))
ctx.Stroke() ctx.Stroke()
@ -53,10 +53,10 @@ func (c *DwellingCaptcha) generateImage(style string) *image.Image {
for i := 0; i < 16; i++ { for i := 0; i < 16; i++ {
x0, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) x0, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height())))
x1, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height()))) x1, _ := rand.Int(rand.Reader, big.NewInt(int64(ctx.Height())))
ctx.SetLineWidth(2)
ctx.DrawLine(0, float64(x0.Int64()), float64(x1.Int64()), float64(ctx.Height()))
r, _ := rand.Int(rand.Reader, big.NewInt(int64(4))) r, _ := rand.Int(rand.Reader, big.NewInt(int64(4)))
ctx.SetLineWidth(2)
ctx.DrawPoint(float64(x0.Int64()), float64(x1.Int64()), float64(r.Int64())) ctx.DrawPoint(float64(x0.Int64()), float64(x1.Int64()), float64(r.Int64()))
ctx.DrawLine(0, float64(x0.Int64()), float64(x1.Int64()), float64(ctx.Height()))
ctx.Stroke() ctx.Stroke()
} }