canvas 实现太阳系效果
一:创建画布
<canvas width="1000" height="1000" id="solar" style="background: #000000"></canvas>
二:实现功能
var solar = document.getElementById('solar');
var cxt = solar.getContext('2d');
// 轨道
function drawTrack(){
for(var i=0; i<8; i++){
cxt.beginPath();
cxt.arc(500, 500, (i+1)*50, 0, 360, false);
cxt.closePath();
cxt.strokeStyle = 'white';
cxt.stroke();
}
}
drawTrack();
function drawStar(x, y, radius, cycle, sColor, eColor) {
this.x = x;
this.y = y;
this.radius = radius;
this.cycle = cycle;
this.sColor = sColor;
this.eColor = eColor;
this.color = null;
this.time =0;
this.draw = function(){
cxt.save();
cxt.translate(500, 500);
cxt.rotate(this.time*(360/this.cycle)*Math.PI/180);
cxt.beginPath();
cxt.arc(this.x, this.y, this.radius, 0, 360, false);
cxt.closePath();
this.color = cxt.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.radius);
this.color.addColorStop(0, this.sColor);
this.color.addColorStop(1, this.eColor);
cxt.fillStyle = this.color;
cxt.fill();
cxt.restore();
this.time += 1;
}
}
function Sun(){
drawStar.call(this, 0, 0, 20, 0, '#f00', '#f90');
}
function Mercury(){
drawStar.call(this, 0, -50, 10, 87.70, '#a69697', '#5c3e40');
}
function Venus(){
drawStar.call(this, 0, -100, 10, 224.701, '#c4bbac', '#1f1315');
}
function Earth(){
drawStar.call(this, 0, -150, 10, 365.224, '#78b1e8', '#050c12');
}
function Mars(){
drawStar.call(this, 0, -200, 10, 686.98, '#cec9b6', '#76422d');
}
function Jupiter(){
drawStar.call(this, 0, -250, 10, 4332.589, '#c0a48e', '#322222');
}
function Saturn(){
drawStar.call(this, 0, -300, 10, 10759.5, '#f7f9e3', '#5c4533');
}
function Uranus(){
drawStar.call(this, 0, -350, 10, 30799.095, '#a7e1e5', '#19243a');
}
function Neptune(){
drawStar.call(this, 0, -400, 10, 60152, '#0661b2', '#1e3b73');
}
var sun = new Sun();
var mercury = new Mercury();
var venus = new Venus();
var earth = new Earth();
var mars = new Mars();
var jupiter = new Jupiter();
var saturn = new Saturn();
var uranus = new Uranus();
var neptune = new Neptune();
function move(){
cxt.clearRect(0, 0, 1000, 1000);
drawTrack();
sun.draw();
mercury.draw();
venus.draw();
earth.draw();
mars.draw();
jupiter.draw();
saturn.draw();
uranus.draw();
neptune.draw();
}
setInterval(move, 20);
canvas 实现太阳系效果的更多相关文章
- canvas之太阳系效果
星球 变量名 公转周期 光色 暗色 水星 Mercury 87.70 #a69697 #5c3e40 金星 Venus 224.701.70 #c4bbac #1f1315 地球 Earth 365. ...
- canvas绘制太阳系
原文地址:http://jeffzhong.space/2017/10/26/solar/ 学习canvas有一段时间了,顺便写个小项目练手,该项目用到的知识点包括: ES6面向对象 基本的三角函数 ...
- 使用Canvas实现动画效果 | DKlogs -- 设计 | 生活
使用Canvas实现动画效果 | DKlogs -- 设计 | 生活 使用Canvas实现动画效果
- canvas实现倒计时效果示例(vue组件内编写)
前言: 此事例是在vue组件中,使用canvas实现倒计时动画的效果.其实,实现效果的逻辑跟vue没有关系,只要读懂canvas如何实现效果的这部分逻辑就可以了 canvas动画的原理:利用定时器,给 ...
- 原生js实现canvas气泡冒泡效果
说明: 本文章主要分为ES5和ES6两个版本 ES5版本是早期版本,后面用ES6重写优化的,建议使用ES6版本. 1, 原生js实现canvas气泡冒泡效果的插件,api丰富,使用简单2, 只需引入J ...
- canvas/CSS仪表盘效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- canvas弹动效果
弹动效果,用物体与目标的距离乘上系数再累加至速度上,让物体呈加速度运动,再让速度乘与摩擦力系数,让物体最终停止运动 代码如下所示 var canvas = document.getElementByI ...
- 用Canvas制作剪纸效果
在做剪纸效果之前,先介绍剪纸效果运用到的一些知识: 1.阴影: 在Canvas之中进行绘制时,可以通过修改绘图环境中的如下4个属性值来指定阴影效果: shadowColor:CSS格式的颜色字串.默认 ...
- HTML5之Canvas时钟(网页效果--每日一更)
今天,带来的是使用HTML5中Canvas标签实现的动态时钟效果. 话不多说,先看效果:亲,请点击这里 众所周知,Canvas标签是HTML5中的灵魂,HTML5 Canvas是屏幕上的一个由Java ...
随机推荐
- Shell教程 之printf命令
上一章节我们学习了 Shell 的 echo 命令,本章节我们来学习 Shell 的另一个输出命令 printf. printf 命令模仿 C 程序库(library)里的 printf() 程序. ...
- avoid
avoid 英[əˈvɔɪd] 美[əˈvɔɪd] vt. 避开,避免,预防; [法] 使无效,撤销,废止; [例句]The pilots had to take emergency action t ...
- 写了一个兼容IE9的图片放大器(基于vue)
photoloupe 图片放大器 第一次写vue插件,本人比较喜欢用简单易懂的写法,不喜勿喷. 本插件支持IE9及以上版本,已经过验证. 本插件可根据需要设置放大倍数,最小支持1倍,支持小数 下载地址 ...
- 22 【python】入门指南:函数
#!/bin/python def test_func(): return "test_func" a = test_func() print(a) 输出结果: test_func ...
- JavaFX
[AWT-SWING-JAVA FX] 多平台.多应用的现有通用类 [inner class] (member class)inside another class, outside any meth ...
- 关于vuex状态管理模式架构
一. 什么是vuex 集中存储管理所有组件的状态 并以相应的规则保证以一种可预测的方式发生变化. 例子: 实现加减 <p>{{count}} <button @click=" ...
- avalon 双向绑定在新版chrome中不能同步中文输入
1>1.x和2.x都有这样的问题,输入中文无法同步到VM,演示地址 http://codepen.io/roscoe054/pen/XXKYMj?editors=1111 chrome 版本 5 ...
- Exploring the world of Android :: Part 1
This blog is accidentally find out, it tells the story of one of our friends about the exploration o ...
- Oracle性能优化3-sql优化一定要等价
做sql优化的前提瞧见是sql等价 1.MAX MIN写法的分与合 drop table t purge; create table t as select * from dba_objects; a ...
- Oracle性能优化1-总体思路和误区
最近在看梁敬彬老师关于Oracle性能优化的一些案例,在这里做一些简单的总结 1.COUNT(*)与COUNT(列)哪个更快 drop table t purge; create table t as ...