« Visio: Transparencies and Soft Shadows | Main | Pixels: LineoGrammer – Pen-centric Diagram Creation »

Visio: Spirograph sample

Last month while playing around with some code samples for my visio automation library I stumbled on Veerle’s blog post about making Spirographs with Adobe illustrator


Which was, in turn inspired by the work of Andy Gilmore.

I liked the look so much I decided to replicate it in Visio 2007. Below is a screenshot of what I was able to generate.


Link to the Visio file: http://cid-19ec39cb500669d8.skydrive.live.com/self.aspx/Public/Visio/Sample%20Files/Spirograph-%7C52009-03-18%7C6.vsd

Combining Code and Direct Manipulation

Note that this sample goes through the VisioInteractive API which is intended to be used via IronPython. However, to make it easier for me to run the test cases and perform refactoring, I’ve written the sample in C# and added some helper functions to make it look more like the final Python code.

The code generates a very plain looking Sirograph…


And then by playing around with the fill settings and shape heights and sizes, I made the final Spirographs. So for example, select all the shapes, bring up the Shape & Position window


And then set the Width to 6.0 …


public IVisio.Shape draw_leaf(Isotope.Drawing.Point p0)
    var vi = this.Shell;
    var p1 = p0.Add(1, 1);
    var p2 = p1.Add(1, 0);
    var p3 = p2.Add(1, -1);
    var p4 = p3.Add(-1, -1);
    var p5 = p4.Add(-1, 0);
    var p6 = p5.Add(-1, 1);
    var bezier_points = vi.Drawing.Points(p0, p1, p2, p3, p4, p5, p6);
    var s = vi.Draw.Bezier(bezier_points);
    return s;

public void Demo07_Spirograph()
    var vi = this.Shell;

    vi.Page.Name = "Spirograph";

    var colors =
        list(0xf26420, 0xf7931c, 0xfec20d, 0xfff200, 0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39, 0x6f3a, 0x6f71,
             0x8eb0, 0xadee, 0x8ed3, 0x71bb, 0x53a6, 0x2e3091, 0x5b57a6, 0x652d91, 0x92278e, 0xbd198c, 0xec008b,
             0xec1c23, 0xc1272c, 0x981a1e);

    var origin = vi.Drawing.Point(4, 4);
    double radius = 3.0;
    int numpoints = colors.Count();
    double angle_step = (System.Math.PI*2/numpoints);
    var indices = Enumerable.Range(0, numpoints);
    var angles = list(indices.Select(i => i*angle_step));
    var centers = list(angles.Select(a => vi.Drawing.GetPointAtRadius(origin, a, radius)));
    var shapes = list(centers.Select(p => draw_leaf(p)));
    var angles_as_degrees = list( angles.Select(a => vi.Drawing.RadiansToDegrees(a)) );

    vi.Fill.ForegroundColor = colors;
    vi.XForm.Angle = angles_as_degrees;
    vi.Line.Weight = list(0.0);
    vi.Line.Pattern = list(0);
    vi.Fill.ForegroundTransparency = list(0.5);
    vi.Page.ResizeToFitContents(1.0, 1.0);

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>