p5实现一个点状花朵canvas变化效果代码
代码语言:html
所属分类:动画
代码描述:p5实现一个点状花朵canvas变化效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html lang="en"><head> <meta charset="UTF-8"> </head> <body> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.js"></script> <script> //clicktochange let rules = 0; let cnt = 0, n = 256; let dArray = []; let w = 0, r = 20; function setup() { createCanvas(windowWidth, windowHeight ); co = floor(width / (2 * r)); ro = co randomDead(); background(20); noStroke(); frameRate(5) } function draw() { background(20) translate(width / 2, height / 2); s=0.28 if(width>1000){ s=0.2 } scale(s, s) v = 12 for (let m = 0; m < v; m++) { push() rotate(m * TWO_PI / v) cnt = 0; for (let j = 0; j <= co; j++) { //columns for (let i = ro; i >= 0; i--) { //rows x = r * j * 1.5; y = -r * 12 + r * sqrt(3) * i + r * j / 1.15; if (dArray[cnt] === 0) { noFill() //fill(0,0,0,100); noStroke() } if (dArray[cnt] === 1) { fill(j * 4 + i * 5, 200 + i * 5, 255 - j * 2, 200 - m * 7) stroke(j * 4 + i * 5, 200 + i * 5, 255 - j * 2, 200 - m * 7) } circle(x, y, r*1.4 ); fill(20) cnt = cnt + 1 } } pop() } switchDead() } function randomDead() { n = (co + 1) * (ro + 1); dArray = [] for (let i = 0; i < n; i++) { tmp = random(-1, 1); if (tmp <= 0) { dArray[i] = 1; } if (tmp > 0) { dArray[i] = 0; } } } function switchDead() { cnt1 = 0 for (let j = 0; j <= co; j++) { //columns for (let i = ro; i >= 0; i--) { //rows if (j != 0 && i != 0 && i != ro && j != co) { sumd = dArray[cnt1 + co + 1] + dArray[cnt1 + co + 2] + dArray[cnt1 - co - 1] + dArray[cnt1 - co - 2] + dArray[cnt1 + 1] + dArray[cnt1 - 1]; } if (i === 0 && j != 0 && j != co) { sumd = dArray[cnt1 + co + 1] + dArray[cnt1 - co - 1] + dArray[cnt1 - co - 2] + dArray[cnt1 - 1]; } if (i === ro && j != 0 && j != co) { sumd = dArray[cnt1 + co + 1] + dArray[cnt1 - co - 1] + dArray[cnt1 + co + 2] + dArray[cnt1 + 1]; } if (j === co && i != 0 && i != ro) { sumd = dArray[cnt1 - co - 1] + dArray[cnt1 - co - 2] + dArray[cnt1 + 1] + dArray[cnt1 - 1]; } if (j === 0 && i != 0 && i != co) { sumd = dArray[cnt1 + co + 1] + dArray[cnt1 + co + 2] + dArray[cnt1 + 1] + dArray[cnt1 - 1]; } if (i === 0 && j === 0) { sumd = dArray[cnt1 + co + 1] + dArray[cnt1 + 1]; } if (i === 0 &.........完整代码请登录后点击上方下载按钮下载查看
网友评论0