python - 笔画重量小于 1 像素会发生什么
问题描述
我将处理脚本重新输入到 python 中,以便我可以在 gimp-python 脚本中使用它。我遇到了 strokeWeight(0.3) 的问题,这意味着厚度小于 1 像素。
我遵循了将 rgb 颜色与 alpha 混合的建议,但这没有用。处理似乎正在做其他事情。我试图在处理源代码中查找 strokeWeight 函数,但我无法真正理解它。我还尝试将 strokeWeight 为 1 的颜色值与 strokeWeight 为 0.3 的颜色值进行比较,但我也无法理解。
有谁知道将 strokeWeight 设置为 0.3 时会进行什么处理,如何模拟这个?
我正在使用的脚本是:
String filename = "image2";
String fileext = ".jpg";
String foldername = "./";
// run, after 30 iterations result will be saved automatically
// or press SPACE
int max_display_size = 800; // viewing window size (regardless image size)
/////////////////////////////////////
int n=2000;
float [] cx=new float[n];
float [] cy=new float[n];
PImage img;
int len;
// working buffer
PGraphics buffer;
String sessionid;
void setup() {
sessionid = hex((int)random(0xffff),4);
img = loadImage(foldername+filename+fileext);
buffer = createGraphics(img.width, img.height);
buffer.beginDraw();
//buffer.noFill();
//buffer.smooth(8);
//buffer.strokeWeight(1);
buffer.strokeWeight(0.3);
buffer.background(0);
buffer.endDraw();
size(300,300);
len = (img.width<img.height?img.width:img.height)/6;
background(0);
for (int i=0; i<n; i++) {
cx[i] = i; // changed to a none random number for testing
cy[i] = i;
//for (int i=0;i<n;i++) {
// cx[i]=random(img.width);
// cy[i]=random(img.height);
}
}
int tick = 0;
void draw() {
buffer.beginDraw();
for (int i=1;i<n;i++) {
color c = img.get((int)cx[i], (int)cy[i]);
buffer.stroke(c);
buffer.point(cx[i], cy[i]);
// you can choose channels: red(c), blue(c), green(c), hue(c), saturation(c) or brightness(c)
cy[i]+=sin(map(hue(c),0,255,0,TWO_PI));
cx[i]+=cos(map(hue(c),0,255,0,TWO_PI));
}
if (frameCount>len) {
frameCount=0;
println("iteration: " + tick++);
//for (int i=0;i<n;i++) {
// cx[i]=random(img.width);
// cy[i]=random(img.height);
for (int i=0; i<n; i++) {
cx[i] = i; // changed to a none random number for testing
cy[i] = i;
}
}
buffer.endDraw();
if(tick == 30) keyPressed();
image(buffer,0,0,width,height);
}
void keyPressed() {
buffer.save(foldername + filename + "/res_" + sessionid + hex((int)random(0xffff),4)+"_"+filename+fileext);
println("image saved");
}
解决方案
0.3 像素的笔画粗细意味着整个 3/10 像素将被着色(*),因此,假设路径穿过中间的像素,像素被绘制为 3/10 的不透明度(可能线性/感知的一些调整)。
(*) 当然,如果路径靠近像素的边缘,这可能会少一些,并且相邻的像素也会略微着色。
推荐阅读
- java - 为什么我的通知在 android TV 模拟器中不起作用?
- git - Merge repository into a folder of an other repository
- python - 如何在 QLabel 中创建项目符号列表?
- python - 如何将交互式绘图图表保存为 R 中的本地文件?
- vue.js - 在 Prettier 中,如何防止 HTML 结束标记的“>”字符被放置在新行上?
- python - KeyError:0 在 Matplotlib 中绘制标签
- android - 在 Espresso 测试中旋转 Android 模拟器
- java - Java 中的 ECDSA 签名验证性能
- kubernetes - Kuberentes 更新策略等到实际准备好
- xml - PowerShell:找到父节点并编辑子节点