- angle 90°
- initial string FX
- string rewriting rules
- X ↦ X+YF+
- Y ↦ −FX−Y
This can be describe as:
- start with a base segment
- replace each segment by 2 segment with a right angle and a rotation of 45 degrees
Here is a further explanation
- + = turn right
- - = turn left
- F = go forward
- FX = initial string
- X = X+YF+
- Y = -FX-Y
In our python we will control the generation through some inputs
- length, = is the distance the turtle function will travel (the drawn line)
- angle, = angle of the turtles rotation
- level, = this is the iteration level
- first_state = this is the L-systems starting description basically FX
- tar1, =character to replace the each iteration
- tar2, = character to replace the each iteration
- replace, = the character/value to replace with
- replace2 = the character/value to replace with
Here we start an initial state of FX. Remember we a rule that states that every X in the list is replace with X+YF+. We get F(X+YF+) or FX+YF+. This basically means Move Forward -> Turn Right -> Move Forward -> Turn Right. This creates a corner
In the next iteration we replace all Y characters with -FX-Y.
our first corner was FX+YF++-FX-Y.F+
Here is a value in 5 level:
FX+YF++-FX-YF++-FX+YF+--FX-YF++-FX+YF++-FX-YF+--FX+YF+--FX-YF++-FX+YF++-FX-YF++-FX+YF+--FX-YF+--FX+YF++-FX-YF+--FX+YF+--FX-YF+
Here is a piece of the code :
# this means all the names in the turtle module will be available to us
from turtle import *
# in here we try and state the varaibles which are going to be used for our loops
def DragonCurve(length, angle, level,first_state, tar1,replace, tar2, replace2):
constant = first_state
for count in range(level):constant2 = ''
for char in constant:
if char == tar1:constant = constant2
constant2 +=replaceelif char == tar2:
constant2 +=replace2else:
constant2 +=char
# this will try and draw our dragon curve based on the value taken from previous loop
for char in constant:if char =='F':# this is a turtle command that takes the speed of our drawing
forward(length)elif char == '+':
right(angle)elif char =='-':
left(angle)
speed(50)
hideturtle()
# this will start up our commands
DragonCurve(10,90,10,'FX+FX+','X','X+YF','Y','FX-Y')
Tuesday, 25 February 2014
Dargon Curve Python
Wednesday, 19 February 2014
The Simple RIB
this is our simple renderman RIB file with our simple shader. The shader will have procedural pattern plug into it to produce the appearance of our shader and the growth of the frost. all of this will be done through python.
Our RIB FILE
Display "" "framebuffer" "rgba"
Format 250 250 1
Projection "perspective" "fov" 40
Translate 0 0 3
Rotate -30 1 0 0
Rotate 0 0 1 0
Scale 1 1 -1
WorldBegin
LightSource "pointlight" 1 "intensity" 30 "from" [2 2 2]
TransformBegin
Surface "FrostBase"
AttributeBegin
AttributeEnd
Color 0.078 0.120 0.160
Sphere 1 -1 1 360
TransformEnd
WorldEnd
Our Base Shader
surface FrostBase(float Kd = 0.8,
frost = 0.5)
{
normal n = normalize(N),
nf = faceforward(n, I);
float hump = 0;
color surfcolor = Cs;
color diffusecolor = Kd * diffuse(nf);
Oi = Os;
Ci = Oi * surfcolor * diffusecolor;
}
Our RIB FILE
Display "" "framebuffer" "rgba"
Format 250 250 1
Projection "perspective" "fov" 40
Translate 0 0 3
Rotate -30 1 0 0
Rotate 0 0 1 0
Scale 1 1 -1
WorldBegin
LightSource "pointlight" 1 "intensity" 30 "from" [2 2 2]
TransformBegin
Surface "FrostBase"
AttributeBegin
AttributeEnd
Color 0.078 0.120 0.160
Sphere 1 -1 1 360
TransformEnd
WorldEnd
Our Base Shader
surface FrostBase(float Kd = 0.8,
frost = 0.5)
{
normal n = normalize(N),
nf = faceforward(n, I);
float hump = 0;
color surfcolor = Cs;
color diffusecolor = Kd * diffuse(nf);
Oi = Os;
Ci = Oi * surfcolor * diffusecolor;
}
Subscribe to:
Posts (Atom)