Barnsley Fern Script

Share your scripts with other members
User avatar
Ron
Posts: 43
Joined: Wed May 28, 2008 1:57 pm

Barnsley Fern Script

Postby Ron » Wed Sep 17, 2008 10:55 pm

Here is a script I wrote to draw the Barnsley Fern in the top viewport. Hope you like it. here is a rendered image of it:



Ron

Code: Select all

import math
import random

#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------

def onSimulationBegin():
   pass




#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
   n = 10000
   vel = Vector.new(0.0,0.0,0.0)
   emsource = scene.getEmitter("Circle01")
   emsource.setParameter("Type","Dumb" )
   emsource.setParameter("Speed",0.0)

   vec1 = Vector.new(0.0, 0.0, 0.0)
   vec2 = Vector.new(0.0, 0.16, 0.0)

   vec3 = Vector.new(0.85, 0.04, 0.0)
   vec4 = Vector.new(-0.04, 0.85, 0.0)
   vec5 = Vector.new(0.0, 1.6, 0.0)

   vec6 = Vector.new(0.2, -0.26, 0.0)
   vec7 = Vector.new(0.23, 0.22, 0.0)
   vec8 = Vector.new(0.0, 1.6, 0.0)

   vec9 = Vector.new(-0.15, 0.28, 0.0)
   vec10 = Vector.new(0.26, 0.24, 0.0)
   vec11 = Vector.new(0.0, 0.44, 0.0)

   p = Vector.new(0.0,0.0,0.0)

   def dotProduct(vector1, vector2, p):
      dot1 = Vector.new(vector1.x * p.x, vector1.y * p.y, 0.0)
      dot2 = Vector.new(vector2.x * p.x, vector2.y * p.y, 0.0)
      dot = Vector.new(dot1.x + dot1.y, dot2.x + dot2.y, 0.0)
      return dot

   for i in range(0,n):
      x = random.uniform(0, 99)

      if x <= 2:
         p = dotProduct(vec1, vec2, p)
      elif x >= 3 and x <= 75:
         p = dotProduct(vec3, vec4, p) + vec5
      elif x >= 76 and x <= 88:
         p = dotProduct(vec6, vec7, p) + vec8
      else:
         p = dotProduct(vec9, vec10, p) + vec11

      pos = Vector.new(p.x, p.y, p.z)
      emsource.addParticle(pos,vel)


#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
   pass




#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------

def onSimulationEnd():
   pass




#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------

def onChangeToFrame():
   pass


User avatar
brandony
Posts: 231
Joined: Sat Oct 21, 2006 7:38 am

Barnsley Fern Script

Postby brandony » Thu Sep 18, 2008 2:13 am

wow....
Brandon Young
www.byvfx.com
FX Artist | TD

Jim M
Posts: 89
Joined: Sun Aug 05, 2007 2:31 pm

Barnsley Fern Script

Postby Jim M » Thu Dec 04, 2008 11:10 pm

Bejeezus, thats clever!

Thanks for sharing that!

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Barnsley Fern Script

Postby lukeiamyourfather » Fri Dec 05, 2008 2:31 am

Jim M wrote: Bejeezus, thats clever!

Thanks for sharing that!

If you ever get bored:

http://en.wikipedia.org/wiki/L-system

Houdini has a built in L-system that can be used to create vegetation, buildings, all kinds of goodies. This is the only implementation of it in RealFlow I've seen, very cool!

User avatar
Ron
Posts: 43
Joined: Wed May 28, 2008 1:57 pm

Barnsley Fern Script

Postby Ron » Fri Dec 05, 2008 6:04 am

Thanks for the nice replies. I'm glad you like it.

I just started to do some research to impliment an L-System in RealFlow. Well see how long it takes me to do it :)

Thanks again,
Ron


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest