Newbie question on irregular polygons

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
ravells
Posts: 2
Joined: Wed Aug 15, 2007 3:18 am

Newbie question on irregular polygons

Post 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

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post 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.

ravells
Posts: 2
Joined: Wed Aug 15, 2007 3:18 am

Post by ravells »

Thank you! Rand static and linerel is what I needed!

Very much appreciated!

Best

Ravi.

Post Reply