0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

xtools Creative Spaceで数理造形をレーザー彫刻

Last updated at Posted at 2024-04-23

image.png

はじめに

 レーザー彫刻で画像(ラスター)を印刷するのは、デフォルト機能にある。しかし、名刺サイズで、30分ぐらい時間がかかる。大量に作るには、ちと辛い。昔のプロッターのように、直線・曲線のベクターなら、速いんじゃないかと思って、ProcessingのLine命令でグラフィックを描いて、出力したら4分弱で出力できた話です。

環境

xtools Creative Space
Processing 4
Mac

SVGの書き出し例

直線によるデザイン例

processing
import processing.svg.*;

size(600,600);

beginRecord(SVG, "fn1.svg");
translate(width/2,height/2);

for(float th=-PI; th<PI; th+=PI/45f){
  float r = 200;
  float x1 = r*cos(th);
  float y1 = r*sin(th);
  float x2 = r*cos(th*2);
  float y2 = r*sin(th*2);
  line(x1,y1,x2,y2);
}

endRecord();

円によるデザイン例

processing
import processing.svg.*;

size(600,600);

beginRecord(SVG, "fn.svg");

noFill();

translate(width/2,height/2);

for(float th=-PI; th<PI; th+=PI/24f){
  float x = 100*cos(th);
  float y = 100*sin(th);
  float r = 2*dist(0,0,x,y+100);
  ellipse(x,y,r,r);
}

endRecord();

xtools CSで読み込み

xtoolsCSで読み込むと、バラバラで読み込まれる。↓
image.png

作例

 水戸黄門の印籠っぽいのをイメージした。最終出力が黒アルミに白の線を引くので、それにイメージを合わせた。

inro.pde
import processing.svg.*;

size(800, 500);

//beginRecord(SVG, "fn.svg");
fill(0);
rect(0, 0, width, height);
noFill();
stroke(255);

translate(400, 250);
for (float th=0; th<2*PI; th+=PI/60f) {
  push();
  rotate(th);
  line(-500, 215, 500, 215);
  pop();
}

for(float th=0; th<2*PI; th+=PI/90f){
  float r = 200;
  float x1 = r*cos(th);
  float y1 = r*sin(th);
  float x2 = r*cos(th*4);
  float y2 = r*sin(th*4);
  line(x1,y1,x2,y2);
}

//endRecord();

image.png

必要な線だけにして、SVGで出力する。

inro.pde
import processing.svg.*;

size(800, 500);

beginRecord(SVG, "fn.svg");

noFill();

translate(400, 250);
for (float th=0; th<2*PI; th+=PI/60f) {
  push();
  rotate(th);
  line(-500, 215, 500, 215);
  pop();
}

for(float th=0; th<2*PI; th+=PI/90f){
  float r = 200;
  float x1 = r*cos(th);
  float y1 = r*sin(th);
  float x2 = r*cos(th*4);
  float y2 = r*sin(th*4);
  line(x1,y1,x2,y2);
}

endRecord();

このSVGはMacのFinderで見る分には問題ないが、xtoolsに持ってくると、クリッピングされておらず、いらない領域が多い。レーザーなので、はみ出てもいいとは思うが、レーザーが大きく動いて、どこかにぶつかるとか、出力時間が長くなるので、なんとかしたい。また、実際に使ってみると、レーザーの位置決め作業が困難になる。

線分のクリッピング

 はみ出る線分は、削除したい。Adobeのイラレで「パスファインダー」「クリッピングパスの削除」「消しゴム」「挟み」「カッター」、InkScapeなどもやってみたが、うまくできないor非効率。結局、Processingで実装した。

inroClipping.pde
import processing.svg.*;

void setup() {
  size(800, 500);
  beginRecord(SVG, "svg.svg");

  noFill();
  translate(400, 250);

  for (float th=0; th<2*PI; th+=PI/60f) {
    float sx=-500, sy=215;
    float ex= 500, ey=215;
    float su=sx*cos(th)-sy*sin(th);
    float sv=sx*sin(th)+sy*cos(th);
    float eu=ex*cos(th)-ey*sin(th);
    float ev=ex*sin(th)+ey*cos(th);
    Line line = new Line(su, sv, eu, ev);
    line.clip(-400, 400, -250, 250);
    line.draw();
  }

  for (float th=0; th<2*PI; th+=PI/90f) {
    float r = 200;
    float x1 = r*cos(th);
    float y1 = r*sin(th);
    float x2 = r*cos(th*4);
    float y2 = r*sin(th*4);
    line(x1, y1, x2, y2);
  }
  endRecord();
}

class Line {
  float x1, y1, x2, y2;
  float ratio;//傾き
  Line (float a, float b, float c, float d) {
    x1=a;
    y1=b;
    x2=c;
    y2=d;
    ratio=(b-d)/(a-c);
  }
  void clip(float xMin, float xMax, float yMin, float yMax) {
    if (x1<xMin) {
      y1-=ratio*(x1-xMin);
      x1=xMin;
    }
    if (x2<xMin) {
      y2-=ratio*(x2-xMin);
      x2=xMin;
    }
    if (xMax<x1) {
      y1-=ratio*(x1-xMax);
      x1=xMax;
    }
    if (xMax<x2) {
      y2-=ratio*(x2-xMax);
      x2=xMax;
    }
    //
    if (y1<yMin) {
      x1-=1/ratio*(y1-yMin);
      y1=yMin;
    }
    if (y2<yMin) {
      x2-=1/ratio*(y2-yMin);
      y2=yMin;
    }
    if (yMax<y1) {
      x1-=1/ratio*(y1-yMax);
      y1=yMax;
    }
    if (yMax<y2) {
      x2-=1/ratio*(y2-yMax);
      y2=yMax;
    }
  }
  void draw() {
    line(x1, y1, x2, y2);
  }
}

xtools CSで出力

svgファイルを読み込んで、サイズ調整。
名刺ケースの場合は幅を95mmにする。
image.png
アルミカードの場合は幅を86mmにする。
image.png
素材をMetal Card指定して、位置決めをして、出力する。
image.png

出力結果

名刺ケースは3分56秒。
名刺カードは3分38秒。
クリッピングなしの場合、5分かかるので、20%以上、短縮している。

image.png

名刺ケースは、仕上がりが綺麗だが、アルミカードはなんかいまいち。
名刺ケースは、匂わないが、アルミカードは、焦げっぽい匂いがある。

--
以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?