Skip to content

Instantly share code, notes, and snippets.

@rngtm
Last active January 5, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rngtm/b312c380db75a609f75f76e9aee0538f to your computer and use it in GitHub Desktop.
Save rngtm/b312c380db75a609f75f76e9aee0538f to your computer and use it in GitHub Desktop.
ランダムウォークを複数回描画してpng出力するprocessingコード(.pde)
final boolean isSave = true; // save as png
final int FrameN = 4;
final int N = 5000; // random walk number
final int alpha = 15; // line alpha
// random walk parameter
final float startRadius = 45;
final float addRadius = 45;
final float degreeRandom = 180;
final float radianRandom = radians(degreeRandom); // degree -> radian
// save file name
String getFileName(int frame)
{
return "randomWalkSpread_"
+ frame
+ ".png";
}
void setup()
{
size(1024, 1024);
for (int i = 0; i < FrameN; i++)
{
drawLines(i);
}
exit();
}
void drawLines(int frame)
{
background(255);
stroke(0, alpha);
for (int i = 0; i < N; i++)
{
drawLine(); // draw random walk line
}
fill(0, 255);
ellipse(width/2, height/2, startRadius * 2, startRadius * 2);
if (isSave)
{
PImage img = get();
img.resize(512, 512);
img.save(getFileName(frame));
}
}
// draw random walk line
void drawLine()
{
float x1, y1;
float x2, y2;
x2 = width / 2;
y2 = height / 2;
float baseRadian = random(0, 2 * PI);
x2 += startRadius * cos(baseRadian);
y2 += startRadius * sin(baseRadian);
while (dist(width/2, height/2, x2, y2) < width)
{
float radian = baseRadian + radianRandom * random(-0.5, 0.5);
x1 = x2;
y1 = y2;
x2 += addRadius * cos(radian);
y2 += addRadius * sin(radian);
line(x1, y1, x2, y2);
}
}
@rngtm
Copy link
Author

rngtm commented Jan 5, 2019

実行するとpdeと同じ階層にpngが出力されます
image

@rngtm
Copy link
Author

rngtm commented Jan 5, 2019

Unityの連番アニメーションとして取り込み、シェーダーで色を付ける作例:
5

参考 : 【Unityシェーダーグラフ+Processing その2】ランダムウォークを利用して雷の球っぽいものを作る
http://r-ngtm.hatenablog.com/entry/2019/01/05/205925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment