【发布时间】:2019-08-21 08:09:03
【问题描述】:
我正在将一个处理脚本重新输入 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");
}
【问题讨论】:
-
Hacky 建议,但是否可以放大坐标,使 Gimp 中的 strokeWeight 等于 1 像素? (然后,您可以对绘图进行更锐利的双三次缩放,任何可能会覆盖绘图的高通滤波版本,以防止边缘过度模糊)。 Gimp 笔刷是否不允许亚像素厚度?
-
您的建议很有趣,但并不能真正解决这个特定问题。我经常使用一个名为“绘图生成”的脚本,并希望能够在 gimp 中使用它。我试图使脚本尽可能与原始脚本相同。
-
可能值得分享您尝试移植到 gimp-python 和源代码草图,希望对 api 更有经验的人可以指导您
-
也许,应该提到的是,在计划制作 gimp-python 脚本时,我只有一个 python 脚本。它更容易测试,当一切正常时,很容易从中制作一个 gimp 脚本。我已经在 python 中复制了处理草图,当我用 strokeWeight(1) 测试它时给出了相同的结果。获得与处理草图完全相同的结果的第一步是将 strokeWeight 设置为 0.3,它应该是。所以我想我的问题不是关于 python(或 gimp),而是关于当 strokeWeight 设置为低于 1 像素时处理的问题。
标签: python processing gimp