zoukankan      html  css  js  c++  java
  • canvas_30 动画-滚动的方块

    <template>
        <view class="zcvs">
            <canvas canvas-id="cvs" id="cvs" :style="setCanvasStyle" />
        </view>
    </template>
    
    <script>
        export default {
            data() {
                return {};
            },
            onReady() {
                this.drawCvs();
            },
            computed: {
                setCanvasStyle() {
                    let retStyle = "background: #000;";
                    const info = uni.getSystemInfoSync();
                    retStyle += "" + info.windowWidth + "px;";
                    retStyle += "height:" + info.windowHeight + "px;";
                    return retStyle;
                }
            },
            methods: {
                drawCvs() {
                    const ctx = uni.createCanvasContext('cvs');
    
                    const info = uni.getSystemInfoSync();
                    const canvas = {
                         info.windowWidth,
                        height: info.windowHeight
                    };
    
                    let [dX, dY, sX, sY, speed] = [true, true, 0, 0, 2];
    
                    var animate = (sx, sy) => {
                        ctx.fillRect(sx, sy, 20, 20);
                        ctx.stroke();
                        ctx.draw();
                    };
    
                    var start = () => {
                        ctx.setFillStyle("#d6b816");
                        ctx.setStrokeStyle("#007AFF");
                        ctx.setLineWidth(10);
    
                        if (dX && dY) {
                            sX < canvas.width - 20 ? sX += speed : dX = false
                            sY < canvas.height - 20 ? sY += speed : dY = false
                        } else if (!dX && dY) {
                            sX > 0 ? sX -= speed : dX = true
                            sY < canvas.height - 20 ? sY += speed : dY = false
                        } else if (dX && !dY) {
                            sX < canvas.width - 20 ? sX += speed : dX = false
                            sY > 0 ? sY -= speed : dY = true
                        } else if (!dX && !dY) {
                            sX > 0 ? sX -= speed : dX = true
                            sY > 0 ? sY -= speed : dY = true
                        }
    
                        animate(sX, sY);
                        window.requestAnimationFrame(start);
                    };
    
                    start();
                }
            }
        }
    </script>
    
    <style lang="scss" scoped>
        .zcvs {
            flex: 1;
            background: "#000";
        }
    </style>
  • 相关阅读:
    amfphp1.9 class mapping初探
    C#程序打包.exe应用程序
    数据库备份方案
    ListView 控件使用
    在C#中运用SQLDMO备份和恢复Microsoft SQL Server数据库
    .NET
    转载:MATLAB 符号函数作图
    整理雷达相关
    Python 程序 运行过程
    struts2 文件上传显示进度条
  • 原文地址:https://www.cnblogs.com/luwei0915/p/15319542.html
Copyright © 2011-2022 走看看