HTML5 Canvas ( 径向渐变, 升级版的星空 ) fillStyle, createRadialGradient
- <!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');
- /**
- * 径向渐变 RadialGradient( 小圆圆心横坐标, 小圆圆心纵坐标, 小圆半径, 大圆圆心横坐标, 大圆圆心纵坐标, 大圆半径 )
- */
- var radial = cxt.createRadialGradient(500, 300, 0, 500, 300, 300); //创建径向渐变
- radial.addColorStop(0.0, 'yellow');
- radial.addColorStop(0.5, 'red');
- radial.addColorStop(1.0, 'blue');
- cxt.fillStyle = radial;
- cxt.fillRect(0, 0, 1000, 600);
- </script>
- <!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');
- /**
- * 绘制一片星空
- */
- var skyStyle = cxt.createRadialGradient(canvas.width/2, canvas.height, 0, canvas.width/2, canvas.height, canvas.height);
- skyStyle.addColorStop(0.0, '#035');
- skyStyle.addColorStop(1.0, 'black');
- cxt.fillStyle = skyStyle;
- cxt.fillRect(0, 0, canvas.width, canvas.height);
- for(var i = 0; i < 150; i++){
- var fiveStart = {};
- fiveStart.Radius = Math.random()*6+6;
- fiveStart.offsetX = Math.random()*canvas.width;
- fiveStart.offsetY = Math.random()*canvas.height*0.65;
- fiveStart.RotationAngle = Math.random()*360;
- drawFiveStar(cxt, fiveStart);
- }
- /**
- * 控制五角星的方法
- */
- function drawFiveStar(cxt, fiveStart){
- cxt.save();
- cxt.translate(fiveStart.offsetX, fiveStart.offsetY); //相对于原点的偏移量
- cxt.rotate(fiveStart.RotationAngle/180*Math.PI); //图形旋转(弧度)
- cxt.scale(fiveStart.Radius, fiveStart.Radius); //图形缩放( X轴的倍数, Y轴的倍数 )
- fiveStartPath(cxt);
- cxt.fillStyle = "yellow";
- cxt.fill();
- cxt.restore();
- }
- /**
- * 绘制标准五角星路径的方法
- */
- function fiveStartPath(cxt){
- cxt.beginPath();
- var x = 0; y = 0;
- for(var i = 0; i < 5; i++){
- x = Math.cos((18+72*i)/180*Math.PI);
- y = Math.sin((18+72*i)/180*Math.PI);
- cxt.lineTo(x, 0-y);
- x = Math.cos((54+72*i)/180*Math.PI)/2.0;
- y = Math.sin((54+72*i)/180*Math.PI)/2.0;
- cxt.lineTo(x, 0-y);
- }
- cxt.closePath();
- }
- </script>
HTML5 Canvas ( 径向渐变, 升级版的星空 ) fillStyle, createRadialGradient的更多相关文章
- HTML5 Canvas ( 线性渐变, 升级版的星空 ) fillStyle, createLinearGradient, addColorStop
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- html5 canvas 径向渐变2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html5 canvas 径向渐变
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- HTML5 Canvas ( 图形变换, 升级版的星空 ) translate, rotate, scale
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- html5 canvas 填充渐变形状
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- canvas径向渐变详解
创建径向渐变步骤如下: 1,创建径向渐变对象 createRadialGradient(x0,y0,r0,x1,y1,r1),其中x0,y0,r0分别为起始圆的位置坐标和半径,x1,y1,r1为终止圆 ...
- html5 canvas 对角线渐变
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html5 canvas 垂直渐变描边
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html5 canvas 水平渐变描边
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- (2)流程控制(for循环、if...else判断、while循环)
for循环 for item in names: #结构语法 print(item) for循环嵌套for循环 for循环配合range()可以直接指定要打印的数量 例:打印一个金字塔 for i ...
- 各大OJ题目分类
http://www.pythontip.com/acm/problemCategory
- java并发编程-Executor框架 + Callable + Future
from: https://www.cnblogs.com/shipengzhi/articles/2067154.html import java.util.concurrent.*; public ...
- 【LGR-054】洛谷10月月赛II
[LGR-054]洛谷10月月赛II luogu 成功咕掉Codeforces Round #517的后果就是,我\(\mbox{T4}\)依旧没有写出来.\(\mbox{GG}\) . 浏览器 \( ...
- MySQL Transaction--RC和RR区别
在MySQL中,事务隔离级别RC(read commit)和RR(repeatable read)两种事务隔离级别基于多版本并发控制MVCC(multi-version concurrency con ...
- Monocular 集成harbor helm 仓库
harbor 已经支持了helm 仓库(使用chartmuseum),Monocular 是一个不错的helm 仓库可视化工具 测试Monocular集成harbor 私服功能 使用docker- ...
- Linux下的Nginx、php、mysql、apache部署
待补充,先搞几个博客链接: https://www.cnblogs.com/Candies/p/8282934.html http://sujianjob.com/2017/12/18/yum%E5% ...
- oracle之 redo过高诊断
一.诊断过度redo 要找到生成大量重做的会话,您可以使用以下任何一种方法.这两种方法都检查生成的撤销量.当一个事务生成撤销,它将自动生成重做. 当需要检查生成大量的程序时,使用第一个查询.当这些程序 ...
- spring考试
- 开始转型学习java
什么编程语言这些都是一样的,编程思想都是一样的.只不过是表现形式. 标识符 每一个字符在ascll码表例都有对应的数字 所以字符和数字是可以相加的 'a'+1 也可以显示数字对应的字符 (ch ...