canvas实现星际穿越动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas实现星际穿越动画效果代码

代码标签: canvas 星际 穿越 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  
<style>
body {
  background-color: #232323;
  position: absolute;
  inset: 0;
}
</style>



</head>

<body  >
  <canvas id="star-field"></canvas>
  
  
      <script  >
"use strict";
const canvas = document.getElementById("star-field");
canvas.width = document.body.clientWidth;
canvas.height = document.body.clientHeight;
window.addEventListener("resize", () => {
    canvas.width = document.body.clientWidth;
    canvas.height = document.body.clientHeight;
});
const context = canvas.getContext("2d");
const stars = [];
const speed = 15;
const numStars = 42;
const v = () => Math.random() * speed - speed / 2;
/**
 * Adapted from: https://slicker.me/javascript/starfield.htm
 */
function animate() {
    const { wi.........完整代码请登录后点击上方下载按钮下载查看

网友评论0