• canvas 满天星


    <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
    
    <canvas id="canvas" width="750" height="1134"></canvas>
    
    <script>
    
        //绘制满天星
        function draw(id) {
    
            var canvas = document.getElementById(id);
            var context = canvas.getContext('2d');
            context.fillStyle = "#000";
            //context.strokeStyle = "#f60";
            //context.lineWidth = 5;
            context.fillRect(0, 0, 750, 1134);
    
            //context.fillStyle = "#fff";
            //context.fillText("fillText", 0, 0);
    
            //********************************** 星星
            context.font = "bold 14px Arial";
            context.textAlign = "left";
            context.textBaseline = "top";
            //context.strokeStyle = "red";
    
            context.fillStyle = "#fff";
            //context.fillText("*", 0, 0);
    
            //for (var i = 0; i < 300; i++) {
    
            //               g.drawString("*", (int) (Math.random() * 1024),
    
            //                               (int) (Math.random() * 768));
    
            //}
    
            for (var i = 0; i < 300; i++) {
    
                context.fillText("*", Math.random() * 750,
    
                                Math.random() * 1134);
    
            }
    
            //********************************* 月亮
            //g.fillOval(800, 100, 100, 100);
    
            //g.setColor(Color.BLACK);
    
            //g.fillOval(780, 80, 100, 100);
            context.beginPath();
    
            context.arc(400, 100, 50, 0, 2 * Math.PI, true);
            context.closePath();
            context.fillStyle = '#f6ee74';
            context.fill();
    
            context.beginPath();
    
            context.arc(380, 80, 50, 0, 2 * Math.PI, true);
            context.closePath();
            context.fillStyle = "#000";
            context.fill();
    
            //********************************* 加载图片
            var beauty = new Image();
            beauty.src = "1.png";
            beauty.onload = function () //确保图片已经加载完毕
            {
    
                context.drawImage(beauty, 100, 100, 400, 600);
            }
    
        }
    
        $(function () {
            draw("canvas");
    
            var canvas = document.getElementById("canvas");
            canvas.onclick = function () {
                var context = canvas.getContext('2d');
                context.font = "bold 14px Arial";
                context.textAlign = "left";
                context.textBaseline = "top";
                context.fillStyle = "#fff";
                for (var i = 0; i < 300; i++) {
    
                    context.fillText("*", Math.random() * 750,
    
                                    Math.random() * 1134);
    
                }
            };
    
        });
    </script>
  • 相关阅读:
    文件数据分析制作过程【1】
    VBA学习(4)
    QTP9.2 .net与java插件破解
    GPRS开发系列文章之实战篇
    time_t到.NET的转换
    RAS函数
    GPRS开发系列文章之入门篇
    [转]惹恼程序员的十件事
    好玩和可爱的网站
    GPRS开发系列文章之进阶篇
  • 原文地址:https://www.cnblogs.com/frog2008/p/5191614.html
Copyright © 2020-2023  润新知