processing - 处理中的像素橡皮擦
问题描述
我是使用 Processing 的新手,这次我尝试像绘画程序一样。由于我选择在背景中绘制网格,我不知道如何制作橡皮擦。如果有人有任何想法......
这是我的代码:
int x = 20, y = 40, w = 70, h = 50;
void setup() {
size(600, 600);
background(255);
stroke(240);
for (int linex = 0; linex < width; linex = linex+40) {
for (int liney = 0; liney < height; liney = liney + 40) {
line(0, liney, width, liney);
}
line(linex, 0, linex, height);
}
fill(255, 0, 0);
rect(x, height - 250, w, h);
fill(0, 255, 0);
rect(x, height - 190, w, h);
fill(0, 0, 255);
rect(x, height - 130, w, h);
fill(0);
rect(x, y, w, h);
textSize(17);
text("Erase everything", 10, 30);
}
void draw() {
if ((keyPressed && key == 'r') || (mousePressed && mouseX > x && mouseX < x + w && mouseY > (height - 250) && mouseY < (height - 250) + h)) {
fill(255, 0, 0);
}
if (keyPressed && key == 'g'|| (mousePressed && mouseX > x && mouseX < x + w && mouseY > (height - 190) && mouseY < (height - 190) + h)) {
fill(0, 255, 0);
}
if (keyPressed && key == 'b' || (mousePressed && mouseX > x && mouseX < x + w && mouseY > (height - 130) && mouseY < (height - 130) + h)) {
fill(0, 0, 255);
}
if (keyPressed && key == 'n'){
fill(0);
}
if (mousePressed) {
noStroke();
ellipse(mouseX, mouseY, 20, 20);
}
if (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y+h && mousePressed) {
setup();
}
}
提前致谢
解决方案
只需将以下代码潜入程序中的 draw() 函数中即可。
noStroke();
ellipse(mouseX, mouseY, 8, 8); // change width and height to the diameter (in pixels) you want your eraser to have.
strokeWeight(1);
或者,如果你想要一个正方形而不是圆形:
noStroke();
rectMode(CENTER);
rect(mouseX, mouseY, 8, 8);
rectMode(CORNER);
strokeWeight(1);
或甜菜之间的东西:
noStroke();
rectMode(CENTER);
rect(mouseX, mouseY, 8, 8, 4); // the 5th parameter is the edge smoothness (in pixels)
rectMode(CORNER);
strokeWeight(1);
推荐阅读
- python - 尝试使用用户输入在 python 中创建一个简单的表单
- python - 只需填充 numpy 数组的特定条目 -> 生成稀疏矩阵
- zip - Android 10 (Android Q):如何因外部存储更改而解压缩文件(无 android:requestLegacyExternalStorage)
- javascript - $('#demo').croppie('destroy') ; 销毁croppie实例croppie.js失败
- python - psycopg2.OperationalError:致命:角色不存在
- python - MASK R:CNN 试图将“形状”转换为张量但失败了。错误:不支持无值
- javascript - 将对象的显示数组反应到行跨度中的表
- android - Xamarin 按钮在网格内不可点击
- css - 如何同时控制 React 中多个元素的样式?
- android - RecycleView 在 android 片段中不起作用