processing - 彩色字母与 Colorcycle | 加工
问题描述
我找到了一个程序,它在网格中生成随机字母并给它们随机颜色。程序运行时,如何使字母颜色或亮度变化?(源代码:https ://happycoding.io/examples/processing/for-loops/letters )
我尝试让填充(r,g,b)有一个从1到255循环的'r',而'g'和'b'为0,但我无法让它更新颜色。我对编程很陌生,所以我很想知道如何才能做到这一点。
解决方案
首先,让我们更改填充方法以接受 RGB 值:
fill(random(256),random(256),random(256));
要在程序运行时更改颜色,必须在方法内部进行更改,该draw()
方法将不断循环和更新画布。有关在此处绘制的更多信息我相信以下代码会输出您所要求的内容:
int rows = 10;
int cols = 10;
int cellHeight;
int cellWidth;
void setup(){
size(500, 500);
cellHeight = height/rows;
cellWidth = width/cols;
textAlign(CENTER, CENTER);
textSize(28);
}
void draw(){
background(32);
for(int y = 0; y < rows; y++){
for(int x = 0; x < cols; x++){
//get a random ascii letter
char c = '!';
c += random(93);
//calculate cell position
int pixelX = cellWidth * x;
int pixelY = cellHeight * y;
//add half to center letters
pixelX += cellWidth/2;
pixelY += cellHeight/2;
fill(random(256),random(256),random(256));
text(c, pixelX, pixelY);
}
}
delay(100);
}
推荐阅读
- jenkins - Jenkins - 如何将测试日志复制回工件目录以进行构建
- c# - 访问当前从 gmail 邮箱发送/接收的邮件
- c++ - C++ 和标准容器:成员的内存地址
- r - 无法为签名 '"NULL"' 的函数 'lhs<-' 找到继承的方法
- c++ - Boost MSM 开启当前状态
- postgresql - 将 DBMS_OUTPUT.PUT_LINE 结果发送到 Postgres 中的外部文件
- java - 编译jar项目maven eclipse时出错
- java - 在 Java 中使用 new 关键字从类创建的引用变量和对象是一回事吗?
- python-3.x - 如何用python 3从字典中减去字典?
- python - Pandas 重新采样缺失的行