当前位置:网站首页>Wechat applet picture verification code display
Wechat applet picture verification code display
2022-06-23 23:52:00 【Results of persistence and effort】
I don't say much nonsense , Code up
One .html page
<canvas canvas-id="canvas" bindtap='change' style="width:90px;height: 30px;"></canvas>Two ,js Logic
var app = getApp();
var baseUrl = getApp().baseUrl;
var ctx;
Page({
data:{
text:""
},
onLoad: function(options) {
var that = this;
this.drawPic(that);
},
change: function() {
var that = this;
this.drawPic(that);
},
mobile(e) {
this.setData({
mobile: e.detail.value
})
},
randomNum(min, max) {
return Math.floor(Math.random() * (max - min) + min);
},
/** Generate a random color **/
randomColor(min, max) {
let r = this.randomNum(min, max);
let g = this.randomNum(min, max);
let b = this.randomNum(min, max);
return "rgb(" + r + "," + g + "," + b + ")";
},
/** Draw verification code picture **/
drawPic(that) {
ctx = wx.createCanvasContext('canvas');
/** Draw the background color **/
ctx.fillStyle = this.randomColor(180, 240); // If the color is too dark, it may make you can't see clearly
ctx.fillRect(0, 0, 90, 28)
/** Draw text **/
var arr;
var text = '';
var str = 'ABCEFGHJKLMNPQRSTWXY123456789';
for (var i = 0; i < 4; i++) {
var txt = str[this.randomNum(0, str.length)];
ctx.fillStyle = this.randomColor(50, 160); // Randomly generate font colors
ctx.font = this.randomNum(20, 26) + 'px SimHei'; // Randomly generate font size
var x = 5 + i * 20;
var y = this.randomNum(20, 25);
var deg = this.randomNum(-20, 20);
// Modify the origin and rotation Angle
ctx.translate(x, y);
ctx.rotate(deg * Math.PI / 180);
ctx.fillText(txt, 5, 0);
text = text + txt;
// Restore the origin of coordinates and rotation Angle
ctx.rotate(-deg * Math.PI / 180);
ctx.translate(-x, -y);
}
/** Draw interference line **/
for (var i = 0; i < 4; i++) {
ctx.strokeStyle = this.randomColor(40, 180);
ctx.beginPath();
ctx.moveTo(this.randomNum(0, 90), this.randomNum(0, 28));
ctx.lineTo(this.randomNum(0, 90), this.randomNum(0, 28));
ctx.stroke();
}
/** Plot interference point **/
for (var i = 0; i < 20; i++) {
ctx.fillStyle = this.randomColor(0, 255);
ctx.beginPath();
ctx.arc(this.randomNum(0, 90), this.randomNum(0, 28), 1, 0, 2 * Math.PI);
ctx.fill();
}
ctx.draw(false, function() {
that.setData({
text: text
})
});
}
})
边栏推荐
- UART协议时序总结
- 为实现“双碳”目标,应如何实现节能、合理的照明管控
- 牛客网:接雨水的双指针问题
- Setting method of bar code local segment data variable
- Restore IP address [standard backtracking + standard pruning]
- B2B transaction management system of electronic components industry: improve the data-based driving ability and promote the growth of enterprise sales performance
- Golang type assertion
- 7、STM32——LCD
- Facebook open source shimmer effect
- 一个人竟然撸了一个微博 APP
猜你喜欢

1.< tag-动态规划和路径组合问题>lt.62. 不同路径 + lt.63. 不同路径 II
![入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式](/img/8c/b1535e03900d71b075f73f80030064.png)
入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式

High imitation Book flag novel flutter edition, learn it

How to ensure reliable power supply of Expressway

docker 部署redis

Recommend 4 flutter heavy open source projects

【HackTheBox】Fawn

Facebook open source shimmer effect

High imitation Betta app

WPF效果之Expander+ListBox
随机推荐
2.摄像机标定
MySQL导致索引失效的情况详解
[things about gbase] gbase 8s high availability technology and case analysis (issue 02)
Unity Text组件空格换行问题
【Try to Hack】masscan
入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式
Gbase observation: extended analytical database
7、STM32——LCD
生成式对抗网络(GANs)及变体
Some common tool functions in work
高仿斗鱼 APP
Quelques fonctions d'outils couramment utilisées au travail
Stm32-------adc (voltage detection)
Inftnews | where should the future of the creator economy go in the Web3 world?
三款很酷很骚气的底部导航
1004. number of maximum consecutive 1 III ●●
节流和防抖
How to ensure reliable power supply of Expressway
Why can't the netherworld fortress machine be remotely connected to the server? What are the ways to solve such problems?
一个人竟然撸了一个网易云音乐云村