Add line that strikes through digits.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 20 Apr 2011 03:05:45 +0200
3 files changed,
50 insertions(+),
33 deletions(-)
M
captcha.go
→
captcha.go
@@ -44,7 +44,7 @@
var store = newStore() func NewImage(numbers []byte) *image.NRGBA { - w := numberWidth * (dotSize + 2) * len(numbers) + w := numberWidth * (dotSize + 3) * len(numbers) h := numberHeight * (dotSize + 5) img := image.NewNRGBA(w, h) color := image.NRGBAColor{uint8(rand.Intn(50)), uint8(rand.Intn(50)), uint8(rand.Intn(128)), 0xFF}@@ -55,8 +55,9 @@ setRandomBrightness(&color, 180)
for _, n := range numbers { y = rand.Intn(dotSize * 4) drawNumber(img, font[n], x, y, color) - x += dotSize*numberWidth + rand.Intn(maxSkew) + 3 + x += dotSize*numberWidth + rand.Intn(maxSkew) + 8 } + drawCirclesLine(img, color) return img }
M
draw.go
→
draw.go
@@ -38,6 +38,7 @@ drawHorizLine(img, color, x0-y, x0+y, y0-x)
} } + func min3(x, y, z uint8) (o uint8) { o = x if y < o {@@ -82,6 +83,21 @@ drawCircle(img, color, rand.Intn(maxx-r*2)+r, rand.Intn(maxy-r*2)+r, r)
} } +func drawCirclesLine(img *image.NRGBA, color image.Color) { + r := 0 + maxx := img.Bounds().Max.X + maxy := img.Bounds().Max.Y + y := rand.Intn(maxy/2+maxy/3) - rand.Intn(maxy/3) + for x := 0; x < maxx; x += r { + r = rand.Intn(dotSize/2) + y += rand.Intn(3) - 1 + if y <= 0 || y >= maxy { + y = rand.Intn(maxy/2) + rand.Intn(maxy/2) + } + drawCircle(img, color, x, y, r) + } +} + func drawNumber(img *image.NRGBA, number []byte, x, y int, color image.NRGBAColor) { skf := rand.Intn(maxSkew) - maxSkew/2 if skf < 0 {@@ -90,8 +106,8 @@ }
for y0 := 0; y0 < numberHeight; y0++ { for x0 := 0; x0 < numberWidth; x0++ { radius := rand.Intn(dotSize/2) + dotSize/2 - addx := rand.Intn(radius / 2) - addy := rand.Intn(radius / 2) + addx := rand.Intn(radius / 4) + addy := rand.Intn(radius / 4) if number[y0*numberWidth+x0] == 1 { drawCircle(img, color, x+x0*dotSize+dotSize+addx, y+y0*dotSize+dotSize+addy, radius)
M
font.go
→
font.go
@@ -6,17 +6,17 @@ numberHeight = 8
) var font = [][]byte{ - { - 0, 1, 1, 1, 0, - 1, 0, 0, 0, 1, - 1, 0, 0, 0, 1, - 1, 0, 0, 0, 1, - 1, 0, 0, 0, 1, - 1, 0, 0, 0, 1, - 1, 0, 0, 0, 1, - 0, 1, 1, 1, 0, + { // 0 + 0,1,1,1,0, + 1,0,0,0,1, + 1,0,0,0,1, + 1,0,0,0,1, + 1,0,0,0,1, + 1,0,0,0,1, + 1,0,0,0,1, + 0,1,1,1,0, }, - { + { // 1 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0,@@ -26,7 +26,7 @@ 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 1, 1, 1, 1, 1, }, - { + { // 2 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,@@ -36,17 +36,17 @@ 1, 0, 0, 0, 0,
1, 0, 0, 0, 0, 1, 1, 1, 1, 1, }, - { - 1, 1, 1, 1, 1, + { // 3 + 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 1, - 0, 1, 1, 0, 0, + 0, 0, 0, 1, 0, + 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, }, - { + { // 4 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0,@@ -56,27 +56,27 @@ 0, 0, 0, 1, 0,
0, 0, 0, 1, 0, 0, 0, 0, 1, 0, }, - { + { // 5 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, - 0, 0, 0, 1, 1, + 0, 0, 0, 0, 1, + 0, 0, 0, 0, 1,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