Update, new mentions, fixed captcha icons Y-pos

This commit is contained in:
2023-09-07 01:10:30 +03:00
parent 737585197e
commit e1319a951d
7 changed files with 108 additions and 70 deletions

View File

@ -10,7 +10,6 @@ import (
"log"
"math/rand"
"strings"
"time"
"github.com/fogleman/gg"
)
@ -55,13 +54,12 @@ func initImage() *gg.Context {
// а правильный вариант возвращается вместе с итоговой картинкой
func GenCaptcha() Captcha {
dc := initImage()
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(Logos), func(i, j int) { Logos[i], Logos[j] = Logos[j], Logos[i] }) // Перемешиваем логотипы
rand.Shuffle(len(XPositions), func(i, j int) { XPositions[i], XPositions[j] = XPositions[j], XPositions[i] }) // И позиции
correct_answer := 0
for i, logo := range Logos {
x := XPositions[i]
y := rand.Intn(ImageHeight - logo.Image.Bounds().Dy() - 30)
y := rand.Intn(ImageHeight - logo.Image.Bounds().Dy() - 70)
dc.DrawImage(logo.Image, x, y)
if logo.IsCorrect {
correct_answer = i + 1