Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import std.stdio, std.math;
enum width = 1000, height = 1000; // Image dimension.
enum length = 400; // Trunk size.
enum scale = 6.0 / 10; // Branch scale relative to trunk.
void tree(in double x, in double y, in double length, in double angle) {
if (length < 1)
return;
immutable x2 = x + length * angle.cos;
immutable y2 = y + length * angle.sin;
writefln("<line x1='%f' y1='%f' x2='%f' y2='%f' " ~
"style='stroke:black;stroke-width:1'/>", x, y, x2, y2);
tree(x2, y2, length * scale, angle + PI / 5);
tree(x2, y2, length * scale, angle - PI / 5);
}
void main() {
"<svg width='100%' height='100%' version='1.1'
xmlns='http://www.w3.org/2000/svg'>".writeln;
tree(width / 2.0, height, length, 3 * PI / 2);
"</svg>".writeln;
}

View file

@ -0,0 +1,20 @@
import grayscale_image, turtle;
void tree(Color)(Image!Color img, ref Turtle t, in uint depth,
in real step, in real scale, in real angle) {
if (depth == 0) return;
t.forward(img, step);
t.right(angle);
img.tree(t, depth - 1, step * scale, scale, angle);
t.left(2 * angle);
img.tree(t, depth - 1, step * scale, scale, angle);
t.right(angle);
t.forward(img, -step);
}
void main() {
auto img = new Image!Gray(330, 300);
auto t = Turtle(165, 270, -90);
img.tree(t, 10, 80, 0.7, 30);
img.savePGM("fractal_tree.pgm");
}

View file

@ -0,0 +1,43 @@
import dfl.all;
import std.math;
class FractalTree: Form {
private immutable DEG_TO_RAD = PI / 180.0;
this() {
width = 600;
height = 500;
text = "Fractal Tree";
backColor = Color(0xFF, 0xFF, 0xFF);
startPosition = FormStartPosition.CENTER_SCREEN;
formBorderStyle = FormBorderStyle.FIXED_DIALOG;
maximizeBox = false;
}
private void drawTree(Graphics g, Pen p, int x1, int y1, double angle, int depth) {
if (depth == 0) return;
int x2 = x1 + cast(int) (cos(angle * DEG_TO_RAD) * depth * 10.0);
int y2 = y1 + cast(int) (sin(angle * DEG_TO_RAD) * depth * 10.0);
g.drawLine(p, x1, y1, x2, y2);
drawTree(g, p, x2, y2, angle - 20, depth - 1);
drawTree(g, p, x2, y2, angle + 20, depth - 1);
}
protected override void onPaint(PaintEventArgs ea){
super.onPaint(ea);
Pen p = new Pen(Color(0, 0xAA, 0));
drawTree(ea.graphics, p, 300, 450, -90, 9);
}
}
int main() {
int result = 0;
try {
Application.run(new FractalTree);
} catch(Exception e) {
msgBox(e.msg, "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
result = 1;
}
return result;
}