Page 1 of 1

Newbie question on irregular polygons

Posted: Sun Jul 26, 2009 4:35 am
by ravells
Hi everyone, I'm having great fun with Context Free (thank you to the creator). but I'm stuck on something and wondered if anyone could kindly give me some help.

I'm trying to create an irregular stroked polygon (i.e. where the number of sides, the angle of any apex and the length of sides is randomised to a degree). It strikes me that using paths is the best way to do this as the CLOSEPOLY command would be able to complete the path. The downside about using shapes to do it would be that I can't work out (although it may well be possible) how to enclose the polygon once I've sent the shape on its walk.

Here's my problem (and assumptions).

I assume that you can only use rules with shapes (but not paths) and rules support randomisation, so for example with shapes I could have a rule which said:

start at x,y

rule make a square

rule extend square 10 units, rotation 0
rule extend square 10 units, rotation 45
rule extend squre 10 units, rotation 90

// this gives me a general movement up and to the right.

rule extend square 10 units, rotation 90
rule extend square 10 units, rotation 135
rule extend square 10 units, rotation 180

etc until when (most of the time) the end point of the shape is somewhere below and right of the start point ... but I can't link up to the start point to close the polygon.

On the other hand if I were to use paths, I cannot see how I can 'randomise' the angle and length of the path even though paths let me close the polygon.

I suspect there is a stunningly simple answer to the problem which my feeble brain can't grasp, and all help in this direction would be most welcome!

Many thanks!

Ravs

Posted: Mon Jul 27, 2009 5:46 pm
by MtnViewJohn
Put a CLOSEPOLY{} after the last LINETO{} and the path will draw a line back to the first point. Context Free has a rand_static() function that generates "compile-time" random numbers. You could use that with LINEREL{} path operators.

Posted: Wed Aug 05, 2009 9:27 am
by ravells
Thank you! Rand static and linerel is what I needed!

Very much appreciated!

Best

Ravi.