<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<canvas width="900" height="900" style="border: 1px solid red;"></canvas>
<script>
// 1.获取canvas对象
var canvas = document.querySelector('canvas');
// 2.获取绘图环境
var ctx = canvas.getContext('2d');
// 坐标原点移动到中间
ctx.translate(canvas.width / 2, canvas.height / 2);
var deg = 0;
setInterval(function() {
deg += 0.1;
// 1.清空画布
ctx.clearRect(-canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<canvas width="900" height="900" style="border: 1px solid red;"></canvas>
<script>
// 1.获取canvas对象
var canvas = document.querySelector('canvas');
// 2.获取绘图环境
var ctx = canvas.getContext('2d');
// 坐标原点移动到中间
ctx.translate(canvas.width / 2, canvas.height / 2);
var deg = 0;
setInterval(function() {
deg += 0.1;
// 1.清空画布
ctx.clearRect(-canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);

这篇博客展示了如何利用HTML5的canvas元素绘制太阳系中各星球的运动轨迹。作者通过JavaScript实现了一个简单的动画效果,让星球按照各自的时间周期绕太阳旋转。代码中详细解释了如何设置轨道、绘制星球以及实现动态旋转的方法。
最低0.47元/天 解锁文章
402

被折叠的 条评论
为什么被折叠?



