canvas大树生长落叶动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas大树生长落叶动画效果代码

代码标签: canvas 大树 生长 落叶 动画

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

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

<head>

  <meta charset="UTF-8">
  

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	background: hsl(223,10%,90%);
	display: flex;
	height: 100vh;
}
canvas {
	display: block;
	margin: auto;
	object-fit: contain;
	max-width: 100vw;
	max-height: 100vh;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
	body {
		background: hsl(223,10%,10%);
	}
}
</style>



</head>

<body  >
  <canvas role="img" aria-label="A tree growing until it bears fruit, dropping its fruit, shrinking, and repeating the cycle"></canvas>

      <script  >
window.addEventListener("DOMContentLoaded", () => {
  const t = new Tree("canvas");
});

class Tree {
  constructor(qs) {
    this.C = document.querySelector(qs);
    this.c = this.C?.getContext("2d");
    this.S = window.devicePixelRatio;
    this.W = 800;
    this.H = 800;
    this.branches = [];
    this.darkTheme = false;
    this.debug = false;
    this.decaying = false;
    this.floorY = 685;
    this.fruit = [];
    this.gravity = 0.098;
    this.loopDelay = 500;
    this.loopEnd = Utils.dateValue;
    this.maxGenerations = 10;

    if (this.C) this.in.........完整代码请登录后点击上方下载按钮下载查看

网友评论0