美文网首页微信小程序/Java/App
微信小程序转盘抽奖积分

微信小程序转盘抽奖积分

作者: Leslie_Lee | 来源:发表于2020-08-25 11:19 被阅读0次

        // 绘制转盘

        drawPrizes() {

            let prizes = this.data.prizes

            wx.getSystemInfo({

                success: function (res) {

                    let f = res.windowWidth / 750 * 32

                    let r = res.windowWidth / 750 * 530 / 2

                    let canvas = wx.createCanvasContext('prizes')

                    prizes.forEach((item, index) => {

                        canvas.save()

                        canvas.translate(r, r);

                        canvas.rotate(index * 36 * Math.PI / 180);

                        canvas.translate(-r, -r);

                        canvas.beginPath()

                        canvas.moveTo(r, r)

                        canvas.arc(r, r, r, -108 * Math.PI / 180, -72 * Math.PI / 180, false)

                        canvas.fillStyle = index % 2 ? '#FFAC3A' : '#FFFEEE'

                        canvas.closePath();

                        canvas.fill();

                        canvas.beginPath()

                        canvas.fillStyle = '#333'

                        canvas.textAlign = 'center';

                        canvas.setFontSize(f)

                        let txt1 = item.name.substring(0, 4)

                        let txt2 = item.name.substring(4).substring(0, 4)

                        canvas.fillText(txt1, r, r / 5)

                        canvas.fillText(txt2, r, r / 5 + f)

                        canvas.closePath()

                        canvas.fill()

                        canvas.restore();

                    })

                    canvas.draw()

                }

            })

        },

    相关文章

      网友评论

        本文标题:微信小程序转盘抽奖积分

        本文链接:https://www.haomeiwen.com/subject/amiajktx.html