Comment detail

2次元ランダムウォーク (Nested Flatten)

出力はSVGにしてみました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private import std.stdio, std.math, std.random;

void main() {
    write(`<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="600" height="600">
<title>ランダムウォーク</title>
<g transform="translate(300,300)">
<circle style="fill:blue" cx="0" cy="0" r="5"/>
<path style="fill:none; stroke:black; stroke-width:1" d="M 0 0`);

    auto rgen = Random(unpredictableSeed);
    auto uniform = UniformDistribution!(real)(0, PI * 2);
    foreach(_; 0 .. 10000) {
        auto angle = uniform.next(rgen);
        auto move = expi(angle) * 10;
        writef(` l %.2f %.2f`, move.re, move.im);
    }

    write(`"/>
</g>
</svg>`);
}

Index

Feed

Other

Link

Pathtraq

loading...