HELP!!!!!!!!!!!!!!

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

Moderators: MtnViewJohn, chris, mtnviewmark

Max

one more question

Post by Max »

I have two questions how do you get the program to draw a line /tendril

and how (just generally) do you go from making snowmen and boxes to making these elaborate trees and designs?


PEACE!!!!!!!

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

The trick make making tendrils and elaborate trees and designs is something called recursion. Recursion (as far as CFDG goes) is when a rule calls itself. For example, here is code to make a simple tendril:

Code: Select all

startshape tendril

rule tendril {
	SQUARE { }
	tendril { s .995 y .95 r .5 }
}
So what does tendril do? First, it draws a square. But then the magic happens. It draws another tendril, this time above it, rotated, and just a little smaller. So what does that second tendril do? It draw a square, and then it, like the first time, it draws another tendril. The tenril rule will just keep drawing itself, a little higher up, a little rotated, and a little smaller every time. That's why the tendril will just keep going into infinity. After a while, the the program will automatically stop drawing applying the tendril rule, since they eventually get to small to see. It's important to have any recursive object keep getting smaller, or else the program won't be able to automatically stop, and (as you can see) you'l have a mess on your hands.

There is one alternative to having a recursive rul make itself smaller every time. That is having a recursive rule that will stop itself or do something different randomly. For example:

Code: Select all

startshape line

rule line 99 {
	CIRCLE { }
	line { s 1 y 2}
}

rule line 1 {
	SQUARE {}
}
This code make a line of dots. How does it work? There are two competing line rules. When the program is told to execute a line rule, it picks one randomly using the probabilities given. The first rule happen 99 times out of 100, and it is the recursive rule It draws a circle, and then calls the line again. Most of the time, this will recurse and draw a new circle and call the line rule again. But 1 time out of 100, the program will pick the second line rule. This will just draw a square and stop. It's ok to have a recursive rule that doesn't smaller only if there's a chance it will stop recursing - that is, there's a rule with the same name that doesn't call itself.

I hope that help. I'd be happy to answer any question your have (and I'm sure I didn't explain so well that you won't have questions :))

User avatar
lagroue
Posts: 114
Joined: Wed Jul 06, 2005 11:33 pm
Location: Paris, France
Contact:

Re: one more question

Post by lagroue »

Max wrote:and how (just generally) do you go from making snowmen and boxes to making these elaborate trees and designs?
This is called recursion.

Take a look a this rule :

Code: Select all

startshape stepAfterStep

rule stepAfterStep {
    SQUARE { }
    stepAfterStep { x 2 }
}
It won't be nice it you try it. Wait a little bit. Let's imagine, first.

If I draw stepAfterStep, what do I do ?
First I draw a square, easy. Then I have to draw a stepAfterStep on the right.
OK, so I go on the right, and draw a square, and then again, a stepAfterStep, which means a square, then, on the right, a square, then, on the right, a square, then, etc, etc.

Infinity.

Code: Select all

startshape stepAfterStep

rule stepAfterStep {
    SQUARE { }
    stepAfterStep { x 2 s 0.5 }
}
Now we are still infinite. But the "s" make the next stepAfterStep half as big. So the next after the next is only a quarter. etc, etc. After a while, it is so tiny that the program decides it is invisible for human eye, and simply stops. Such infinite tininess can not be drawn.

If we put some other weirdness :

Code: Select all

startshape stepAfterStep

rule stepAfterStep {
    SQUARE { }
    stepAfterStep { x 2 s 0.5 r 10 }
}
Then we turn as we are getting tinier and tinier.

Last example for this recursion lesson :

Code: Select all

startshape stepAfterStep

rule stepAfterStep {
    SQUARE { }
    stepAfterStep2 { x 2 s 0.5 r 10 }
}

rule stepAfterStep2 {
    CIRCLE { }
    stepAfterStep { x 2 s 0.5 r -10 }
}
Two rules calling themselves !

And last but not least, your first tree :

Code: Select all

startshape stepAfterStep

rule stepAfterStep {
    SQUARE { }
    stepAfterStep {
         y 2     // up
         s 0.8  // 0.8 so that we get tiny less quick
    }
}

rule stepAfterStep 0.1 {  // 0.1 so that it doesn't occur too often
	stepAfterStep { r 30 } // one branch left
	stepAfterStep { r -30 } // one branch right
}

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

Heh. Looks like we wrote the same tutorial at hte same time. :)

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

Post by MtnViewJohn »

Would either of you mind if I used your examples and text to create a tutorial section for the CF site? Maybe we should have a Wiki so that people can add tips and tricks.

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

I wouldn;t mind at all, please do. A wiki sounds great.

max

THANKS

Post by max »

You both helped me out so much that it isn' t even funny. How long did it take ya'll to learn how to work with this program and to figure out all of this stuff ?
also any other info you could post that would help me out in this program would be greatly appreciated and heres my email if you want to make the tutorials a little more personal mmcwhirter213@msn.com

ps when is version 1.1 set to come out and what are the new features it will have??

thanks a ton
Max

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

Our pleasure. It didn't take me very long to figure it out, probably an hour or so. But I think most of us come from a programming background, so we're use to looking at code, and recursion is a fairly important concept in programming.

If I wiki goes up, you can be sure I'll write more about how to use the program. Until then, the best way to learn it by looking at other peoples' designs and figuring out how they work. Then try modifying them and seeing what you come up with.

max

cool

Post by max »

how do i ad a second tendril onto the one that you gave me so that they intersect each other

User avatar
lagroue
Posts: 114
Joined: Wed Jul 06, 2005 11:33 pm
Location: Paris, France
Contact:

Post by lagroue »

max, assuming you have one tendril which turns to the left, rename it "tendril_left", and copy/paste all its rules. Rename the new ones "tendril_right" and negate all angles (all the "r" stuff).

They will thus be symetrical.

Now just do something like

rule twotendril {
tendril_left { r 10 }
tendril_right { r -10 }
}

And adjust your numbers.

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

First off, you need to specify a rule that draw two tendrils. Then just make that rule your startshape. For example:

Code: Select all

startshape top

rule top {
	tendril { x -5 r -15}
	tendril { x  5 r  15}
}

rule tendril {
   SQUARE { }
   tendril { s .995 y .95 r .5 }
}
So the first rule that's called it top. Just draw two tendrils, both rotated in towards the other one. And each of the two tendril just does it's tendril thing.[/code]

max

lines

Post by max »

first off when is version 1.1 set to come out and what are the new features it will have and also how do i create a line like the ones used in the welcome preview so that i can spell words


thanks

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

Post by MtnViewJohn »

Version 1.1 will be out tomorrow. The Attack of the Show blurb on Context Free is rebroadcasting on Monday so we want v1.1 out by then. The line code in welcome.cfdg looks like this (I shortened it a bit):

Code: Select all

rule LINE {
	SQUARE { }
	LINE { size 0.98 y 0.5 }
}
In version 1.1 we have taken out the rotating and scaling code and replaced it with a general affine transform capability. Then we are adding all of the other possible affine transforms: separate scaling in x & y, shearing, and reflection. We also added a syntax for controlling the order that the transforms or adjustments are applied. And lastly, we added triangles, since you can't make them from a finite number of squares. In v1.1 you could replace the LINE rule with this:

Code: Select all

rule LINE {
	SQUARE [ size 1 24 y 0.5  ]
}
But then you would lose the tapering affect. So you would use the new TRIANGLE shape:

Code: Select all

rule LINE {
	TRIANGLE [ size 1 30 y 0.25  ]
}

robo git
Posts: 47
Joined: Sat Jul 09, 2005 11:36 pm
Location: looking for his marbles
Contact:

Post by robo git »

Thanks for that John,

With controlling the transform order, you wrote:
MtnViewJohn wrote:The syntax for controlling the transform order is to enclose the adjustments in square brackets instead of curly braces.

Code: Select all

rule polygon5sided {
   SQUARE [rotate 0 size 0.404509 0.587785 x 0.5]
   ...
}
Can you have multiple transforms of the same type? IE: Rotate (to get angle relative to source-object), Reposition (x/y), then Rotate again to point the corner of the square (or whatever) back towards the source object? EG:

Code: Select all

rule SomeRule {
    SQUARE [rotate 120 y 1.2 rotate 45]
}
I'd try it myself, but I'm at work at the moment ;)

I'm also curious as to what is the max number of transforms that can be sequenced per-object or per-rule-call

Thanks!
-Trav

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

Post by MtnViewJohn »

Yes, you can have multiple transforms of the same type. Each transform is done in the context of the transforms that precede it, just as you would hope. For example, you can have a recursive line and play with the reduction factor without having to fiddle with the translation factor:

Code: Select all

rule LINE {
    SQUARE {}
    LINE [ y 0.5 s 0.8 y 0.5 ]
}
You can change the size factor without changing the y factors and the squares will still touch without overlaps or gaps.

There is no limit to how many transforms you can do. The cfdg parser starts each shape with the identity transform matrix. As it parses a transform it constructs the corresponding affine transform matrix and premultiplies this new transform into the shape transform (transform = new_transform * transform). Then it throws away all the information about the transform and moves on to the next.

Post Reply