gpt4 book ai didi

javascript - P5.js - 填充颜色为 'n %'

转载 作者:行者123 更新时间:2023-12-03 04:50:56 24 4
gpt4 key购买 nike

查看 p5.js 示例,我想知道此示例中的“n %”填充有何作用:

/**
* Based on a paper here:
* http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
*/

var n = 0;
var c = 10;

function setup() {
createCanvas(windowWidth, windowHeight);
angleMode(DEGREES);
colorMode(HSB);
background(0);
}

function draw() {
var a = n * 137.5; //var a = n * 137.5;
var r = c * sqrt(n);

var x = r * cos(a) + width / 2;
var y = r * sin(a) + height /2;

fill(n % 256, 255, 255);
noStroke();
ellipse(x, y, 8, 8);

n++;
}

我很好奇彩虹效果是如何实现的。

最佳答案

令我惊讶的是 Google 搜索没有返回任何结果。

这是modulo operator ,它基本上给出了一个数字除以另一个数字后剩下的余数。

尝试编写一个示例程序来准确测试运算符(operator)的功能。

关于javascript - P5.js - 填充颜色为 'n %',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42659801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com