首页 > 解决方案 > 笔画重量小于 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");
}

以下是一些测试结果,(缩放 200%):(需要注意的是,这是一条相当直线,用于比较。实际代码使用随机坐标。) 使用 strokeWeight(0.3) 进行 1 次迭代 使用 strokeWeight(1) 进行 1 次迭代 使用 strokeWeight(0.3) 进行 10 次迭代 使用 strokeWeight(1) 进行 10 次迭代

标签: pythonprocessinggimp

解决方案


0.3 像素的笔画粗细意味着整个 3/10 像素将被着色(*),因此,假设路径穿过中间的像素,像素被绘制为 3/10 的不透明度(可能线性/感知的一些调整)。

(*) 当然,如果路径靠近像素的边缘,这可能会少一些,并且相邻的像素也会略微着色。


推荐阅读