-
Notifications
You must be signed in to change notification settings - Fork 55
/
imagefilterstrike.go
58 lines (49 loc) · 1.2 KB
/
imagefilterstrike.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2013 hanguofeng. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gocaptcha
import (
"math"
"strconv"
)
const IMAGE_FILTER_STRIKE = "ImageFilterStrike"
//ImageFilter is the interface of image filter
type ImageFilterStrike struct {
ImageFilterBase
}
func imageFilterStrikeCreator(config FilterConfigGroup) ImageFilter {
filter := ImageFilterStrike{}
filter.SetConfig(config)
return &filter
}
//Proc the image
func (filter *ImageFilterStrike) Proc(cimage *CImage) {
var num int
var err error
v, ok := filter.config.GetItem("Num")
if ok {
num, err = strconv.Atoi(v)
if nil != err {
num = 1
}
} else {
num = 1
}
maxx := cimage.Bounds().Max.X
maxy := cimage.Bounds().Max.Y
y := rnd(maxy/2, maxy-maxy/2)
amplitude := rndf(10, 15)
period := rndf(80, 100)
dx := 2.0 * math.Pi / period
for x := 0; x < maxx; x++ {
xo := amplitude * math.Cos(float64(y)*dx)
yo := amplitude * math.Sin(float64(x)*dx)
for yn := 0; yn < num; yn++ {
r := rnd(0, 2)
cimage.drawCircle(x+int(xo), y+int(yo)+(yn*(num+1)), r/2, 1)
}
}
}
func (filter *ImageFilterStrike) GetId() string {
return IMAGE_FILTER_STRIKE
}