canvas线条跟随引力绘图动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas线条跟随引力绘图动画效果代码,小球越大引力越大,线条就会朝它过去。

代码标签: canvas 线条 跟随 引力 绘图 动画

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

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

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


  
  
  
<style>
body {
  height: 100vh;
  margin: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
}

#frame-count {
  position: absolute;
  bottom: 0;
  right: 0;
  display: none;
}

canvas {
  width: clamp(200px, 80vmin, 600px);
  height: clamp(200px, 80vmin, 600px);
}
</style>

  
</head>

<body>
  <canvas></canvas>
<div id="frame-count">0</div>
 
  
      <script  >
const { cos, sin, pow, atan2, min, max, PI: π } = Math;
const query = document.querySelector.bind(document);
const canvas = query('canvas');
const ctx = canvas.getContext('2d');

const Physics = {
  G: 6.7 * 10 };


const setup = () => {
  const width = 600;
  const height = 600;
  canvas.width = width;
  canvas.height = height;
  ctx.fillStyle = 'white';
  ctx.fillRect(0, 0, width, height);
  return {
    width,
    height };

};

const { width, height } = setup();

const Marker = {
  // Not confident about physics terminology
  init({ x, y, mass, radius, style, veloc.........完整代码请登录后点击上方下载按钮下载查看

网友评论0