canvas实现圈圈内樱花树生长动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas实现圈圈内樱花树生长动画效果代码

代码标签: canvas 圈圈 樱花 生长 动画

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

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

<head>
  <meta charset="UTF-8">

  
  
  
<style>
body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  place-content: center;
  background-color: #f9f6ef;
  background-image: radial-gradient(circle, #f9f6ef, #ebebe3), radial-gradient(at 100% 20%, #5eb0e525, #0000 70%), radial-gradient(at 20% 20%, #f3d06025, #0000 70%), radial-gradient(at 20% 100%, #a5282c25, #0000 70%), radial-gradient(at 100% 100%, #aee1cd25, #0000 70%);
  background-blend-mode: darken;
}

canvas {
  display: block;
  border-bottom: 10px solid #836539;
}

#pic {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80vmin;
  height: 80vmin;
  margin: auto;
  border: 4px solid #836539;
  border-radius: 100vmax;
  overflow: clip;
  position: relative;
}

button {
  position: absolute;
  top: 20px;
  left: 20px;
  padding: 0.15em 0.48em;
  font-size: 2.2rem;
  cursor: pointer;
  border: none;
  background-color: #444;
  color: white;
  border-radius: 5px;
}
</style>


  
  
</head>

<body translate="no">
  <div id="pic">
  <canvas id="fractalCanvas"></canvas>
</div>
<button id="restartButton">⟲</button>
  
      <script>
const container = document.getElementById("pic");
const canvas = document.getElementById("fractalCanvas");
const ctx = canvas.getContext("2d");
const restartButton = document.getElementById("restartButton");

let maxDepth = 8;
let currentDepth = 0;
let isAnimating = true;
let lastTimestamp = 0;
const frameInterval = 300;

function resizeCanvas() {
  canvas.width = container.clientWidth;
  canvas.height = container.clientHeight;

  drawFractal(); // Redraw the fractal after resizing
}

function getRandomInRange(min, max) {
  return Math.random() * (max - min) + min;
}

function drawBranch.........完整代码请登录后点击上方下载按钮下载查看

网友评论0