类鸟群Boid模拟动画效果
代码语言:html
所属分类:动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { margin: 0; padding: 0; } canvas { width: 100vw !important; height: 52vw !important; } </style> </head> <body translate="no"> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/p5.js"></script> <script> var logo; var vectors = []; var logoW=703; var logoH=221; const flock = []; class Boid { constructor() { this.position = createVector(random(width), random(height)); this.velocity = p5.Vector.random2D(); this.velocity.setMag(random(2, 4)); this.accelleration = createVector(); this.maxForce = 1; this.maxSpeed = 4; this.radius = 16; this.color = color("hsl("+floor(random(360))+",50%,50%)"); this.size = random(.5, 1.75); } edges() { if(this.position.x > width+this.radius) { this.position.x = 0-this.radius; } else if(this.position.x < 0-this.radius) { this.position.x = width+this.radius; } if(this.position.y > height+this.radius) { this.position.y = 0-this.ra.........完整代码请登录后点击上方下载按钮下载查看
网友评论0