Jump to content
Sign in to follow this  
lokster

Drawing Sierpinski Triangle fractal with AutoIt

Recommended Posts

lokster

This example shows how to draw The Sierpinski triangle with autoit:

Posted Image

sierpinski.au3:

#cs
According to wikipedia, sierpinski triangle is a fractal named after Waclaw Sierpinski 
who described it in 1915. Originally constructed as a curve, this is one of the basic 
examples of self-similar sets, i.e. it is a mathematically generated pattern that can 
be reproducible at any magnification or reduction.
#ce

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Sierpinski triangle example (by lokster)", 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "Bye")
GUISetState(@SW_SHOW)

Global $user32 = DllOpen("user32.dll")
Global $gdi32 = DllOpen("gdi32.dll")
Global $hdc = GetDC($Form1)

For $x = 0 To 400
    For $y = 0 To 400
        If BitAND($x,$y) Then
            pix($hdc,$x,$y,0xFFFFFF)
        Else
            pix($hdc,$x,$y,0x000000)
        EndIf
    Next
Next   

While 1
    Sleep(100)
WEnd

Func Bye()
    DllCall ($user32,"int","ReleaseDC","int",$hdc,"hwnd",$Form1)
    DllClose($user32)
    DllClose($gdi32)
    Exit
EndFunc

Func pix($dc,$x,$y,$color)
    DllCall ($gdi32, "long", "SetPixel", "long", $dc, "long", $x, "long", $y, "long", $color)
EndFunc

Func GetDC($handle)
    $dc = DllCall ($user32, "int", "GetDC", "hwnd", $handle)
    Return $dc[0]
EndFunc

Share this post


Link to post
Share on other sites
Sn0opy

Remembers me to John Conway's Game of Life ^^ Nice idea!

Share this post


Link to post
Share on other sites
RazerM

Nice, i can't believe it's so simple!


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
lordofthestrings

that is (again) some freaky looking code from you Lokster.. :rolleyes:


Share this post


Link to post
Share on other sites
lokster

To be honest, I have found this example in wikipedia, but it was written in Java...

I am long time interested in fractals, regardless of my math skills :rolleyes:

Now I am working on a complete script for generating and drawing L-Systems http://en.wikipedia.org/wiki/L-systems

It is 50% in FreeBasic (the iterative calculations) and 50% in autoit - the GUI

Here are some screenshots (I will post the complete script soon):

Posted Image

Posted Image

Share this post


Link to post
Share on other sites
lordofthestrings

I first saw fractals when a MOD file player called CHAOS (before MP3 before Windows 3.0)

would display neverending fractals on the beat of the MOD Files..

that's a long time ago... at least 20 years?


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.