会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133651个问题
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 27228楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多个小球运动</title><style>canvas{border: 1px solid;}</style>
</head>
<body>
    <canvas width="500px" width="400px">对不起你的浏览器不支持canvas</canvas>
    <script>
        var mycanvas=document.querySelector('canvas');
        var ctx=mycanvas.getContext('2d');
        function Circle(){
            this.r=Math.floor(Math.random()*20+6);
            this.x=Math.floor(Math.random()*(500-this.r));
            this.y=Math.floor(Math.random()*(400-this.r));
            this.dx=Math.floor(Math.random*10);
            this.dy=Math.floor(Math.random*8);
            this.color='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')';
        }
        Circle.prototype.yd=function(){
            this.x+=this.dx;
            if(this.x<=this.r){
                this.dx=-this.dx
            }else if(this.x>=500-this.r){
                this.dx=-this.dx
            }
            this.y+=this.dy;
            if(this.y<=this.r){
                this.y=-this.dy
            }else if(this.y>=400-this.r){
                this.dy=-this.dy
            }
        }
       Circle.prototype.abs=function(){
           ctx.beginPath();
           ctx.arc(this.x,this.y,this.r,0,2*Math.PI);
           ctx.fillStyle=this.color;
           ctx.fill();
           ctx.closePath();
         

       }
       var arr=[];
           for(var i=0 ;i<4;i++){
               arr[i]=new Circle();
           }
           var timer=setInterval(function () {
               ctx.clearRect(0,0,mycanvas.width,mycanvas.height)
               for(var i=0;i<arr.length;i++){
                   arr[i].yd();
                   arr[i].abs();

               }
           },40)

    </script>
</body>
</html>

老师为啥我的球显示不了

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 27234楼
微服务/第十八阶段:数字货币交易所项目(Spring Cloud Alibaba架构)/IASS基础服务的搭建和开发 27235楼
微服务/第十八阶段:数字货币交易所项目(Spring Cloud Alibaba架构)/IASS基础服务的搭建和开发 27236楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 27237楼
JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解(旧) 27238楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637