Jump to content
Sign in to follow this  
lokster

L-Systems fractal generator

Recommended Posts

lokster

This script draws fractals based on l-systems. For more info on l-systems read this.

The core is written in FreeBasic - the part wihich calculates the l-system. It can be done in autoit too, but it's very slow, so I made it with FB.

It's a command line application, which can be used separately from the autoit script which draws the gererated system.

The frontend (the GUI) is written in autoit.

The complete fractal generator is here: l_systems.zip - extract it somewhere and run lsystem-fe.au3.

Here are some screenshots:

Posted Image Posted Image Posted Image

Here is the autoit script:

and here is the FreeBasic source(this is just for informative purpose, if someone thinks that lsystem.exe is something that will harm his sistem... :rolleyes: ):

lsystem.bas

Function Split(inpstr As String, separator As String, xRes() As String)
    Dim i,n
    Dim a(Len(inpstr))
    i=0
    a(i)=1
    Do
        i+=1
        a(i)=Instr(a(i-1),inpstr,separator)+1
    Loop Until a(i)=1
    a(i)=Len(inpstr)+2
    Redim xres(i+1)
    For n=0 To i-1
        xres(n+1)=Mid$(inpstr,a(n),a(n+1)-a(n)-1)
    Next
    Return i
End Function

Function lsystem (  s() As String, _
    r() As String, _
    Byval axiom As String, _
    Byval level As Integer _
    )   As String
    
    Dim axiom_ As String
    Dim axiom__ As String
    Dim iter As Integer
    Dim i As Integer
    Dim c As String
    Dim i1 As Integer
    
    axiom_ = axiom
    
    For iter = 0 To level-1
        axiom__ = ""
        For i = 1 To Len(axiom_)
            c = Mid(axiom_,i,1)
            For i1 = 0 To Ubound(s)-2
                If (c=s(i1)) Then
                    c=r(i1)
                End If
            Next
            axiom__ += c
        Next
        axiom_ = axiom__
    Next
    Return axiom_
End Function

If Command$(3)="" Then
    Print "L-System calculator by lokster (c)2007"
    Print ""
    Print "Usage: lsystem.exe <axiom> <rules> <level>"
    Print ""
    Print "Example (gererate the ""Dragon"" fractal at level 10):"
    Print ""
    Print " lsystem.exe FX ""F%F&X%X+YF+&Y%-FX-Y"" 10"
    Print ""
    Print "Please note, that the second parameter MUST be surrounded by double-quotes!" 
Else
    Dim a As String
    Dim res() As String
    
    a = Ucase( Command$(2))
    Split(a,"&",res())
    
    Dim s(Ubound(res)) As String
    Dim r(Ubound(res)) As String
    
    For rep = 1 To Ubound(res)-1
        Dim par() As String
        Split(res(rep),"%",par())
        s(rep-1) = par(1)
        r(rep-1) = par(2)
    Next
    Print lsystem(s(),r(),Ucase(Command$(1)),Valint(Command$(3)))
End If

Enjoy!

Edited by lokster

Share this post


Link to post
Share on other sites
lordofthestrings

I get an error.. would have loved to see this work..

I checked to solve it myself, but I didn't see the mistake immediately)

probably the space in teh path to lsystems.exe. too busy at work to put too much effort in it at the moment (and I'm sure you'll know what this error is about) :-)

>Running:(3.2.4.9):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\gii761\Desktop\Scripting\fractals based on L-system\lsystem-fe.au3"  
C:\Documents and Settings\gii761\Desktop\Scripting\fractals based on L-system\lsystem-fe.au3 (119) : ==> Unable to execute the external program.: 
$pid = Run(@ScriptDir & "\lsystem.exe " & $axiom & " """ & $rules & """ " & $level, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

Share this post


Link to post
Share on other sites
lokster

Corrected. The problem was that the path contained spaces, and I forgot to surround it with quotes.

Share this post


Link to post
Share on other sites
lordofthestrings

may I also suggest following easy rule for string concatenation: (small tip)

follow kix methodology..

meaning start a string with a single quote.

then if you need to place a double quote simply place one double quote.

in vbscript you can build strings with series of 4 double quotes in a row.. not clean code, you're asking for errors here :rolleyes:

hope you get it to work man!

have a nice day!


Share this post


Link to post
Share on other sites
RazerM

This is really nice! Good work.


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.