p5实现搭木块动画效果代码

代码语言:html

所属分类:动画

代码描述:p5实现搭木块动画效果代码

代码标签: p5 木块 动画

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

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

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

  
  
<style>
html, body {
  margin: 0;
  padding: 0;
}

canvas {
  width: 500px;
  height: 500px;
  max-width: 100vw;
	max-height: 100vh;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
  border: 2px solid #8DA5B2;
}
</style>


  
</head>

<body translate="no">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.1.10.0.js"></script>
      <script  >
console.clear();

function setup() {
  createCanvas(windowWidth,windowHeight);
  create();
}

const gap = 17;
const size = 5;
const dampingSpeed = .1;


let arms = [];

class Arm {
  constructor(x,y) {
    this.x = x;
    this.y = y;
    this.pos = getPos(x,y);
    this.join = getJoin(x,y);
    this.targetJoin = this.join;
    
    this.updateColor();
  }
  updateColor () {
    this.color = random() < .95 ? 220 : [220,0,0];
  }
  update() {
    this.join.x += (this.targetJoin.x - this.join.x) * dampingSpeed;
    this.join.y += (this.targetJoin.y - this.join.y) * dampingSpeed;
  }
  draw () {
    if(random() < .001) {
      this.targetJoin = getJoin(this.x, this.y);
    }
    if(random() < .0005) {
      this.updateColor();
    }
    
    this.update().........完整代码请登录后点击上方下载按钮下载查看

网友评论0