asp汉字中文图片验证码的实现代码(24)
yOffSet = Abs(y2-y1)
If xOffSet >= yOffSet Then'以位移量较大方做横轴
direction = "x"
ReDim ary(xOffSet)'用来记录连线各点y值
'x2,y2存储x值较大的点
If x2 < x1 Then
i = x1
x1 = x2
x2 = i
i = y1
y1 = y2
y2 = i
End If
'判断从x1->x2在纵轴方向上是增是减
If y2 >= y1 Then
flag = 1
Else
flag = -1
End If
'下面计算连线上点的分布(先是平均分配各行的点,然后随机分配剩余的点到各行)
rows = yOffSet + 1'所占行数
step = (xOffSet+1) \ rows'各行平均分配的点
yu = (xOffSet+1) Mod rows'剩余的点数
ReDim ary2(rows-1)'用来记录剩余点的随机分配
While yu > 0
i = int(Rnd*rows)
ary2(i) = ary2(i)&"."'被分配到的行则加一个字符"."
yu = yu - 1
WEnd
iii = 0
'将连线的点信息记录到数组
For i=0 To rows-1
For ii=1 To step+Len(ary2(i))
ary(iii) = y1 + i*flag
iii = iii + 1
Next
Next
ii = 0
'统计连线上有效点的数量
For i=0 To xOffSet
If pcd_getDot(x1+i,ary(i),str,UnitWidth) = "0" Then ii = ii + 1
Next
Else
'这里是以y为横轴,原理与x时相同
direction = "y"
ReDim ary(yOffSet)
If y2 < y1 Then
i = x1
x1 = x2
x2 = i
i = y1
y1 = y2
y2 = i
End If
If x2 >= x1 Then
flag = 1
Else
flag = -1
End If
rows = xOffSet + 1
step = (yOffSet+1) \ rows
yu = (yOffSet+1) Mod rows
ReDim ary2(rows-1)
While yu > 0
i = int(Rnd*10)
If i < rows Then
ary2(i) = ary2(i)&"."
yu = yu - 1
End If
WEnd
iii = 0
For i=0 To rows-1
For ii=1 To step+Len(ary2(i))
ary(iii) = x1 + i*flag
iii = iii + 1
内容版权声明:除非注明,否则皆为本站原创文章。