p5实现随机多边形旋转动画效果代码

代码语言:html

所属分类:动画

代码描述:p5实现随机多边形旋转动画效果代码

代码标签: p5 随机 多边形 旋转 动画

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

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

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

  
  
  
<style>
/* #447abd */
body {
  background-color: #447abd;
  display: flex;
  height: 100vh;
  overflow: hidden;
  margin: 0;
  align-items: center;
  justify-content: center;
  text-align: left;
}
</style>



  
  
</head>

<body translate="no">
  
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.1.10.0.js"></script>
      <script  >
//#mathober2024

const bgCol = "#447abd";
const gCol = "#a2c2e8";
const nGrid = 20;
let players;
let gSpace;
let polygon1;
let isE = true;

function setup() {
  w = max(400, min(windowWidth, windowHeight) * 0.9);
  describe(" ");
  players = [];
  createCanvas(w, w);
  describe(
    "A polygon with midpoint polygons iteratively drawn inside with alternating colors in a blueprint design."
  );
  rectMode(CENTER);
  polygon1 = [];
  n = int(random(3, 9));
  gSpace = (w / nGrid) * 0.95;
  angleMode(DEGREES);
  for (let i = 0; i < n; i++) {
    tmpR = random(3, 9);
    polygon1[i] = {
      x: tmpR * gSpace * cos((360 / n) * i),
      y: tmpR * gSpace * sin((360 / n) * i)
    };
  }
  r = (w * 0.82) / 2;
  d = w;
  textSize(16);
}

function draw() {
  isE = true;
  background(bgCol);
  translate(w / 2, w / 2);
  t = frameCount;
  rd = 10;
  let polygon2 = [];
  for (let i = 0; i < polygon1.length; i++) {
    polygon2[i] = {
      x: polygon1[i].x + (i / 2 + gSpace) * cos(t - i * 50),
      y: polygon1[i].y + (i / 2 + gSpace) * sin(t - i * 50)
    };
  }
  stroke(255, 255, 255);
  strokeWeight(0.5);
  plotPolygon(polygon2);
  makeMidPointPolygon(polygon2, gSpace);
  noStroke();
  fill(gCol);
  text("midpoint polygon", -w / 2 + .........完整代码请登录后点击上方下载按钮下载查看

网友评论0