123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- module genlogo;
-
- import std.experimental.all;
-
- void main()
- {
- foreach (i; 1..20)
- {
- draw(i);
- }
- }
-
- void draw(int numPetals)
- {
- enum pi = 3.1415927;
- auto dim = 256;
- auto center = 196;
- auto o = File("petal%s.svg".format(numPetals), "w");
- o.writefln(`<svg width="%s" height="%s">
- <defs>
- <radialGradient id="pinky">
- <stop stop-color="#b3879d" offset="0%%"/>
- <stop stop-color="#d8a4be" offset="50%%"/>
- <stop stop-color="#e2bace" offset="90%%"/>
- </radialGradient>
- </defs>
- <polygon stroke="#3c2631" fill="url(#pinky)" points="%s,%s`, center * 2, center * 2, center, center);
- // We have five petals. Their points are balanced at the five directions: top, top-right,
- // low-right, low-left, top-left.
- auto radius = (dim / 2) - (dim / 30);
- // 90% of the circle is divided between the petals, and there are five petals.
- auto innerRadius = dim / 9;
- auto midRadius = dim * 0.75;
- auto petalCoverage = 0.95;
- auto margin = (1 - petalCoverage) / numPetals * 2 * pi;
- auto perPetal = petalCoverage / numPetals;
- auto petalWidth = 2 * pi / numPetals;
-
- void writePoint(double radians, double radius)
- {
- auto x = sin(radians) * radius;
- auto y = cos(radians) * radius;
- o.writefln(" %s,%s", x + center, y + center);
- }
- foreach (i; 0 .. numPetals)
- {
- auto d1 = petalWidth * i + margin;
- writefln("%s: %s", i, d1);
- auto d2 = d1 + petalWidth - 2 * margin;
- auto d3 = d1 + (d2 - d1) / 2;
- writePoint(d3, innerRadius);
- writePoint(d1, radius);
- writePoint(d3, midRadius);
- writePoint(d2, radius);
- writePoint(d3, innerRadius);
- }
- o.writefln(` %1$s,%1$s" />
- <circle fill="#ac7ba8" stroke="#3c2631" cx="%1$s" cy="%1$s" r="%2$s" />`, center, dim / 6);
- o.writefln(`<circle fill="#665683" cx="%s" cy="%s" r="%s" />
- </svg>`, center, center, dim / 10);
- o.flush;
- o.close;
- }
|