Home > Article > WeChat Applet > Use the mini program canvas component to draw the automatic scaling square function
When you look at the mobile traffic page, you should have seen various changing graphics that look very sci-fi. If you look at them for a long time, you will feel dizzy. So how are these pictures made? Today we will give you a brief demonstration of how to use the mini program canvas component to draw an automatic scaling square
1. The page displays a square image.
2. The square gradually enlarges.
The dynamic rendering is as follows:
The source code of the home page is as follows:
<view class="copyright"> <view class="copyright_item">CopyRight:All Right Reserved</view> <view class="copyright_item">原创作者:html51.com</view> <view class="copyright_item">微信小程序开发者社区:51小程序</view> <view class="copyright_item"><image class="img" src="../copyright/image/logo.png"/></view> <view class="goto_counter"><button type="default" bindtap="goto_counter">点击进入图形缩放页面</button></view> </view>
Some important codes are as follows:
Page({ onReady:function(e){ var cxt_scale = wx.createContext();//创建并返回绘图上下文context对象。 var scale=0;//默认缩放倍数为0,大于0为放大,小于0位缩小 setInterval(function(){ //无限循环定时函数 scale+=0.5;// 向缩小后放大 if(scale==10){//但放大位数为10倍时,设置放大倍数为1 scale=1 } cxt_scale.scale(scale,scale)//对横纵坐标进行缩放 cxt_scale.rect(0,0,10,10)//边长为为10px的正方形 cxt_scale.stroke();//对当前路径进行描边 wx.drawCanvas({ canvasId:'canvasAutoScale',//画布标识,对应<canvas/>的cavas-id actions:cxt_scale.getActions()//导出context绘制的直线并显示到页面 }); },200) } })
The above is the detailed content of Use the mini program canvas component to draw the automatic scaling square function. For more information, please follow other related articles on the PHP Chinese website!