HELP!!!!!!!!!!!!!!
Moderators: MtnViewJohn, chris, mtnviewmark
one more question
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!!!!!!!
and how (just generally) do you go from making snowmen and boxes to making these elaborate trees and designs?
PEACE!!!!!!!
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:
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:
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 )
Code: Select all
startshape tendril
rule tendril {
SQUARE { }
tendril { s .995 y .95 r .5 }
}
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 {}
}
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 )
Re: one more question
This is called recursion.Max wrote:and how (just generally) do you go from making snowmen and boxes to making these elaborate trees and designs?
Take a look a this rule :
Code: Select all
startshape stepAfterStep
rule stepAfterStep {
SQUARE { }
stepAfterStep { x 2 }
}
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 }
}
If we put some other weirdness :
Code: Select all
startshape stepAfterStep
rule stepAfterStep {
SQUARE { }
stepAfterStep { x 2 s 0.5 r 10 }
}
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 }
}
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
}
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
THANKS
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
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
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.
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, 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.
They will thus be symetrical.
Now just do something like
rule twotendril {
tendril_left { r 10 }
tendril_right { r -10 }
}
And adjust your numbers.
First off, you need to specify a rule that draw two tendrils. Then just make that rule your startshape. For example:
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]
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 }
}
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
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):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:But then you would lose the tapering affect. So you would use the new TRIANGLE shape:
Code: Select all
rule LINE {
SQUARE { }
LINE { size 0.98 y 0.5 }
}
Code: Select all
rule LINE {
SQUARE [ size 1 24 y 0.5 ]
}
Code: Select all
rule LINE {
TRIANGLE [ size 1 30 y 0.25 ]
}
Thanks for that John,
With controlling the transform order, you wrote: 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
With controlling the transform order, you wrote:
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: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] ... }
Code: Select all
rule SomeRule {
SQUARE [rotate 120 y 1.2 rotate 45]
}
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
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
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: 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.
Code: Select all
rule LINE {
SQUARE {}
LINE [ y 0.5 s 0.8 y 0.5 ]
}
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.