p5实现canvas绘制花朵效果代码
代码语言:html
所属分类:布局界面
代码描述:p5实现canvas绘制花朵效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { padding: 0; margin: 0; } body { display: flex; flex-direction: column; background-color: #00000c; align-items: center; justify-content: center; } p { color: #eee; margin: 4px; font-size: 1.5rem; font-family: helvetica, sans-serif; } canvas { display: block; } </style> </head> <body> <p>Click on canvas to regenerate</p> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.js"></script> <script > // source code: https://github.com/moPsych/flowers-00 let c, cn; let t, s, bd; let regenerate = true; let ellipseList = []; let pts = []; let palette = ["#00ffaa", "#ff006f", "#ff9d00", "#ffa3fd", "#f2f794", "#d9c0fa"]; // let palette = ["#FF0052", "#00FF79", "#0096FF", "#FF8700", "#C400FF", "#FFE200", "#ffffff"]; // number of flower curves let n = 30; // number of background elements let nBg = 30; // basic stroke weight let baseSW = 3; // stroke weight decrease per length let dSF = 0.01; function setup() { c = createCanvas(windowHeight, windowHeight); // c = createCanvas(1500, 1500); } function draw() { if (regenerate) { calcParameters(); pointsData(); drawBackground(nBg); drawCurves(); drawPetals(); regenerate = false; } } function calcParameters() { // parameters calculated according to canvas size bd = height / 20; t = random(0, PI); s = random(0, PI); } function pointsData() { // calculates the points used to generate the curves pts = []; for (let i = 0; i < n; i++) { p = { l: createVector(round(random(0.2 * width, 0.8 * width)), height + 10), pl: createVector(), t: random(0.005), s: random(0.02), len: round(random(height * 0.4, height * 0.6)), strk: round(random(50, 100)) }; pts.push(p); } } function drawBackground(n) { //draws the background elements background("#e0f5ff"); // background(0, 0, 10); for (let k = 0; k < n; k++) { let num = ceil(random(5)); let bLst = []; let bx = random(0.1 * width, 0.9 * width); let by = random(0.1 * height, 0.9 * height); bLst.push(createVector(bx, by)); for (let i = 0; i < num; i++) { let nbx = bx + random(-bd, bd); let nby = by + random(-bd, bd); bLst.push(createVector(nbx, nby)); } let col = palette[floor(random(palette.length))]; fill(red(col), green(col), blue(col), random(20, 40)); stroke(red(col), green(col), blue(col), random(40, 60)); // the below function I created to generate bezier curves from a list of points drawBezierOpen(bLst); } } function drawCurves() { // flower curves are calculated as a function of sin and cosine ellipseList =.........完整代码请登录后点击上方下载按钮下载查看
网友评论0