<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas</title>
<script type="text/javascript" src="../js/jQuery.js"></script>
<style type="text/css">
*{
margin: 0;
padding: 0;
outline: none;
border: none;
}
#canvas{
width: 7rem;
margin: .25rem 0 0 1.5rem;
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="canvas" width="1000" height="600"></canvas>
</body>
</html>
<script type="text/javascript">
/**
* rem 布局初始化
*/
$('html').css('font-size', $(window).width()/10);
/**
* 获取 canvas 画布
* 获取 canvas 绘图上下文环境
*/
var canvas = $('#canvas')[0];
var cxt = canvas.getContext('2d'); /**
* 绘制一片星空
*/
cxt.fillStyle = 'black';
cxt.fillRect(0, 0, canvas.width, canvas.height);
for(var i = 0; i <= 300; i++){
var fiveStart = {};
fiveStart.bigRadius = Math.random()*6+6;
fiveStart.smallRadius = fiveStart.bigRadius/2.0;
fiveStart.offsetX = Math.random()*canvas.width;
fiveStart.offsetY = Math.random()*canvas.height;
fiveStart.RotationAngle = Math.random()*360;
console.log(fiveStart);
drawFiveStar(cxt, fiveStart);
} /**
* 绘制五角星的方法
*/
function drawFiveStar(cxt, fiveStart){
cxt.beginPath();
var x = 0, y = 0;
for(var i = 0; i < 5; i++){
x = Math.cos((18+72*i-fiveStart.RotationAngle)/180*Math.PI);
x = x*fiveStart.bigRadius+fiveStart.offsetX;
y = -Math.sin((18+72*i-fiveStart.RotationAngle)/180*Math.PI);
y = y*fiveStart.bigRadius+fiveStart.offsetY;
cxt.lineTo(x,y);
x = Math.cos((54+i*72-fiveStart.RotationAngle)/180*Math.PI);
x = x*fiveStart.smallRadius+fiveStart.offsetX;
y = -Math.sin((54+i*72-fiveStart.RotationAngle)/180*Math.PI);
y = y*fiveStart.smallRadius+fiveStart.offsetY;
cxt.lineTo(x,y);
}
cxt.closePath();
cxt.lineWidth = 3;
cxt.strokeStyle = "#FD5";
cxt.fillStyle = 'yellow';
cxt.lineJoin = "round";
cxt.fill();
cxt.stroke();
}
</script>

HTML5 Canvas ( 绘制一片星空 )的更多相关文章

  1. 学习笔记:HTML5 Canvas绘制简单图形

    HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...

  2. 使用 HTML5 Canvas 绘制出惊艳的水滴效果

    HTML5 在不久前正式成为推荐标准,标志着全新的 Web 时代已经来临.在众多 HTML5 特性中,Canvas 元素用于在网页上绘制图形,该元素标签强大之处在于可以直接在 HTML 上进行图形操作 ...

  3. 使用html5 canvas绘制图片

    注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...

  4. 使用html5 canvas绘制圆形或弧线

    注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...

  5. html5 Canvas绘制图形入门详解

    html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...

  6. 解决html5 canvas 绘制字体、图片与图形模糊问题

    html5 canvas 绘制字体.图片与图形模糊问题 发生情况 多出现在高dpi设备,这意味着每平方英寸有更多的像素,如手机,平板电脑.当然很多高端台式电脑也有高分辨率高dpi的显示器. canva ...

  7. 使用html5 Canvas绘制线条(直线、折线等)

    使用html5 Canvas绘制直线所需的CanvasRenderingContext2D对象的主要属性和方法(有"()"者为方法)如下: 属性或方法 基本描述 strokeSty ...

  8. html5 canvas绘制环形进度条,环形渐变色仪表图

    html5 canvas绘制环形进度条,环形渐变色仪表图                                             在绘制圆环前,我们需要知道canvas arc() 方 ...

  9. 怎样用JavaScript和HTML5 Canvas绘制图表

    原文:https://code.tutsplus.com/zh-...原作:John Negoita翻译:Stypstive 在这篇教程中,我将展示用JavaScript和canvas作为手段,在饼状 ...

随机推荐

  1. JQuery输入框获取/失去焦点行为

    //搜索框获取焦点清除内容 $(function() { $("input").focus(function() { //获取焦点,清空默认内容 $(this).css('colo ...

  2. JQuery判断form表单是否为空

    功能:通过jquery判断form表单中是否有内容还未填写,如果有未填写的,则阻止提交 $(function () { $('form').bind('submit',function () {  / ...

  3. 当php版本为5.6时的提示信息解决方法

    ecshop修饰符preg_replace/e不安全的几处改动 Strict standards: Only variables should be passed by reference in D: ...

  4. 动画Completed事件里获取执行该动画的UI对象

    转:http://www.cnblogs.com/xyq/p/3775732.html 昨天群里有位童鞋提出如何在动画完成事件Completed里获取到执行该动画的UI对象. WPF里动画的Compl ...

  5. MySQL Disk--NAND Flash原理

    ====================================================== NAND Flash最小存储单元: 写数据操作: 通过对控制闸(Control Gate) ...

  6. k8s helm 可视化UI 管理工具 monocular部署试用

    官方建议是用 helm 进行安装,但是helm 有点费事(各种原因...) 所以使用官方说的使用docker-compose 但是默认官方的compose 跑起来 还是真费事,经过调整,修改了一版支持 ...

  7. pipelinedb 滑动窗口

    滑动窗口可以方便的让我们进行一段时间的数据分析 几个主要函数 clock_timestamp 内置的函数,总是返回当前的时间戳 arrival_timestamp 事件达到的时间 单滑动窗口 参考 C ...

  8. SQL Server MERGE

    Merge关键字是一个神奇的DML关键字.它在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根据与源 ...

  9. net web service 参数类型

    因为Web Services的执行是建立在XML架构之上的,所以它能够支持丰富的数据类型. 下表列出了使用SOAP协议时Web Services支持的数据类型:  类 型 含 义 基础类型 也即标准基 ...

  10. Jmeter 在linux下的分布式压测

    Jmeter 在linux下的分布式压测 0.将 windows机器作为master 控制机(同时也兼做负载机slave), linux机器作为 负载机 slave. 1.linux环境安装 : (1 ...