zoukankan      html  css  js  c++  java
  • canvas_25 椭圆

    <template>
        <view class="zcvs">
    
            <view class="zcvs-item">
                <view>椭圆</view>
                <view>
                    <canvas canvas-id="cvs" id="cvs" style=" 400px; height: 400px;border: 1px solid #007AFF;" />
                </view>
            </view>
    
        </view>
    </template>
    
    <script>
        export default {
            data() {
                return {
    
                };
            },
            onReady() {
                this.drawCvs();
            },
            methods: {
                drawCvs() {
                    const ctx = uni.createCanvasContext('cvs');
                    const centX = 0;
                    const centY = 0;
                    const cWidth = 400;
                    const cHeight = 400;
                    const radius = 50;
    
                    ctx.save(); // 保存状态1
                    ctx.translate(cWidth / 2, cHeight / 2); // 移动原点
                    ctx.scale(2, 1); // 水平放大
                    ctx.beginPath(); // 缩放之后画圆
                    ctx.arc(centX, centY, radius, 0, 2 * Math.PI, false);
                    ctx.setFillStyle("#007AFF");
                    ctx.fill();
    
                    ctx.restore(); // 还原
                    ctx.arc(centX, centY, radius, 0, 2 * Math.PI, false);
                    ctx.fill();
    
                    ctx.draw();
                },
            }
        }
    </script>
    
    <style lang="scss" scoped>
    
    </style>
  • 相关阅读:
    05-删除提示
    04-setTimeout
    03-页面加载事件
    02-对话框
    01-window
    18-选择水果
    17-元素操作的方法
    13-动态创建表格
    【数据库】SQL必知必会复习
    【数据库】JDBC课设(2)addbatch批处理SQL语句
  • 原文地址:https://www.cnblogs.com/luwei0915/p/15271656.html
Copyright © 2011-2022 走看看