Jump to content

More fractal examples


crashdemons
 Share

Recommended Posts

This all reinvents the wheel [again] - but if you're interested, read on.

These fractals have already been done, but I was playing around with GDI+ by myself.

In this script:

Cantor ternary (1D, middle-thirds erased)

Sierpinski carpet (2D, middle-thirds filled [as opposed to erasing])

Koch curve* (1D, 90-degree angles/aka quadratic Koch)

Note: Currently all fractal functions are recursive

- working on some way to make them iterative.

Screenshot of all at once:Posted Image

* @ Koch Curve - I didn't bother figuring out an exact mathematical function for the changes between sides, so instead I have drawing operations for each of the four sides. (works :P )

/me *falls asleep from exhaustion now.

Fract_exmp.au3:

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)

Global $wanted_fps

Global $fractals[3]=['Cantor ternary (1D Middle thirds, reflected)','Koch curve (1D, 90-degree, reflected)','Sierpinski carpet (2D Middle thirds)']
Global $fracmax=UBound($fractals)-1


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Fractal Example", 500, 500+20*($fracmax+2), 270, 124)
GUISetOnEvent(-3,'Quit')

$lDraw=GUICtrlCreateLabel('',0,0,500,500)
GUICtrlCreateLabel(' Detail Level (1-6)',0,500,100,20)
$iDetail=GUICtrlCreateInput(4,100,500,100,20)
GUICtrlCreateLabel(' Frames Per Second',200,500,100,20)
$iFPS=GUICtrlCreateInput(10,300,500,100,20)
$bDraw = GUICtrlCreateButton("Draw", 400, 500, 100, 20, 0)
GUICtrlSetOnEvent(-1,'DrawEvent')

Global $checks[$fracmax+1]
For $i=0 To $fracmax
    $checks[$i]=GUICtrlCreateCheckbox($fractals[$i],0,520+20*$i,300,20)
    GUICtrlSetState(-1,1)
Next

GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

$cgp=ControlGetPos($Form1,'',$lDraw)
Global $ImageWidth=$cgp[2]
Global $ImageHeight=$cgp[3]
Global $Draw=False
_GDIPlus_Startup()
Global $gro = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($Form1,'',$lDraw))
Global $grb= _GDIPlus_BitmapCreateFromGraphics($ImageWidth,$ImageHeight,$gro)
Global $gr = _GDIPlus_ImageGetGraphicsContext($grb)
GUISetState(@SW_SHOW)
Clear(0xFF000000,True)
MsgBox(0,'Fractal Example','Warning: Detail level 6 can take a long time to draw and may not be exactly accurate. (to-the-pixel)'&@CRLF&'Use levels 1-5 for more accurate and quicker results')
While 1
    Display(True)
    If $Draw Then
        
        Draw()
        
        GUICtrlSetState($bDraw,128); lets keep the user from screwing up the return to NOT drawing; (DrawEvent will re-enable the button)
        $Draw=True; force the switch to change to False, Just In Case.
        DrawEvent()
    EndIf
    Sleep(500)
WEnd
Func DrawEvent()
    GUICtrlSetState($bDraw,128); yeah, I don't like multiple button presses being queued.
    Global $Draw
    $Draw=Not $Draw
    Switch $Draw
        Case True
            GUICtrlSetData($bDraw,'Abort!')
        Case False
            GUICtrlSetData($bDraw,'Draw!')
    EndSwitch
    GUICtrlSetState($bDraw,64)
EndFunc
Func Draw()
    Global $Draw, $Detail, $wanted_fps, $lfps,$fracmax,$bDraw,$iDetail,$iFPS
   ;GUICtrlSetState($bDraw,128)
    GUICtrlSetState($iDetail,128)
    GUICtrlSetState($iFPS,128)
    For $i=0 To $fracmax
        GUICtrlSetState($checks[$i],128)
    Next
    $Detail=Int(GUICtrlRead($iDetail))
    $wanted_fps=Int(GUICtrlRead($iFPS))
    If $Detail>6 Then
        $Detail=6
        GUICtrlSetData($iDetail,$Detail)
    EndIf
    $Detail=5-($Detail-1)
    Clear(0xFF000000, True)
    _GDIPlus_GraphicsFillRect($gr, 0, 0, $ImageWidth-1, $ImageHeight-1); Just in Case
    Local $pen=_GDIPlus_PenCreate(0xFF00FF00,1)
    Local $bpen=_GDIPlus_PenCreate(0xFF000000,1)
    Local $brush=_GDIPlus_BrushCreateSolid(0x00000000)
    Local $bbrush=_GDIPlus_BrushCreateSolid(0xFF007F00)
    
    $lfps=$wanted_fps
    For $i=0 To $fracmax
        If $Draw And BitAND(GUICtrlRead($checks[$i]),1)=1 Then
        ;$lfps=$wanted_fps
            Switch $i
                Case 0
                    Cantor_ternary(0,0,$ImageWidth,$pen,10)
                    Cantor_ternary(0,490,$ImageWidth,$pen,-10)
                Case 1
                    Koch_curve(50,250,400,$pen,0,$bpen)
                    Koch_curve(50,250,400,$pen,3,$bpen)
                Case 2
                    Sierpinski_carpet(50,50,400,$brush,True,$bbrush)
                Case Else
                    ContinueLoop
            EndSwitch
            Display(True)
        EndIf
    Next
    _GDIPlus_PenDispose($pen)
    _GDIPlus_PenDispose($bpen)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_BrushDispose($bbrush)
    For $i=0 To $fracmax
        GUICtrlSetState($checks[$i],64)
    Next
;GUICtrlSetData($iFPS,Round($wanted_fps,2));- this value may not be exact if you abort.
    GUICtrlSetState($iDetail,64)
    GUICtrlSetState($iFPS,64)
   ;GUICtrlSetState($bDraw,64)
EndFunc






Func Cantor_ternary($x,$y,$w,$pen,$spacing=10)
;Cantor_ternary(0,0,$ImageWidth,$pen)
;http://en.wikipedia.org/wiki/Cantor_dust
    Global $Draw
    Local $width_limit=(3^($Detail))
    If $Detail>0 Then $width_limit+=3; shrugs - this is what it took to fix it!
    
;create drawings backlog array for fractal recursion
    Local $maxlog=20
    Local $drawings[$maxlog]
    $drawings[0]=1; [0] is the first blank item starting at 1
    For $i=1 To $maxlog-1
        $drawings[$i]=False
    Next
    
;drawing info array for the drawings backlog
    Local $drawx[3]
    $drawx[0]=$x
    $drawx[1]=$y
    $drawx[2]=$w
    
;add our requested (first/main) item.
    $drawings[$drawings[0]]=$drawx
    $drawings[0]+=1
    
    Local $addchild
    For $i=$drawings[0]-1 To 1 Step -1
; last item to first, so we can subtract when we remove, and add then we add.
    ;get backlogged item to draw
        $drawx=$drawings[$i]
        $addchild=False
        If IsArray($drawx) Then
            If $Draw And $drawx[2]>=($width_limit) Then;And (($spacing<0 And $drawx[1]>0) Or ($spacing>0 And $drawx[1]<100)) Then
            ;draw item
                
                _GDIPlus_GraphicsDrawLine($gr,$drawx[0],$drawx[1],$drawx[0]+$drawx[2],$drawx[1],$pen)
                Display()
            ;add children to backlog
                $addchild=True
                
            EndIf
        ;remove the item from the backlog
            $drawings[$i]=False
        EndIf
        $drawings[0]-=1
        
        If $addchild Then
            If $drawings[0]<($maxlog-1) And $drawx[2]>=$width_limit Then
            ;left child
                $drawx[1]+=$spacing
                $drawx[2]/=3
                $drawings[$drawings[0]]=$drawx
                $drawings[0]+=1
            ;right child
                $drawx[0]+=$drawx[2]*2
                $drawings[$drawings[0]]=$drawx
                $drawings[0]+=1
            EndIf
        EndIf
    ;reset iteration for the most recently added backlog
        $i=$drawings[0]
    Next
EndFunc

#cs
Func Cantor_ternary_o($x,$y,$w,$pen,$spacing=10)
;Cantor_Dust(0,0,$ImageWidth,$pen)
;http://en.wikipedia.org/wiki/Cantor_dust
    Global $Draw
    If Not $Draw Then Return 0
    If $spacing>0 And $y>=100 Then Return 0
    If $spacing<0 And $y<0 Then Return 0
    If $w<(3^$Detail)       Then Return 0; - $w<3 for exact lengths - we're visually cheating if detail=0.
    _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen)
    Display()
    $y+=$spacing
    $w/=3; third width of original length
    Cantor_ternary($x,$y,$w,$pen,$spacing);0/3 width from left edge of original, 1/3 width of original
    $x+=$w*2                   ;SPACE - 1/3 width from left edge, 1/3 width of original
    Cantor_ternary($x,$y,$w,$pen,$spacing);2/3 width from left edge, 1/3 width of original
EndFunc
#ce







Func Koch_curve($x,$y,$w,$pen,$dir=0,$backpen=0)
;1D & 90-degree angle - Quadratic type 1 curve
;  0=Top,1=Left,2=Right,3=Bottom (triangularly);; Height=(1/2)*Width
;Koch_curve(100,100,$ImageHeight,$pen,0)
; - this should be ALOT simpler!!!!!!
    Display()
    Global $Draw
    If Not $Draw Then Return 0
    If $w<(3^$Detail) Then Return 0
    $w/=3
    Switch $dir
        Case 0; HorizTop _|'|_
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzLeft
            Koch_curve($x,$y,$w,$pen,0,$backpen)
            $x+=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$backpen);blankspace
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertLeft
            Koch_curve($x,$y,$w,$pen,1,$backpen)
            $y-=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzTop
            Koch_curve($x,$y,$w,$pen,0,$backpen)
            $x+=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y+$w,$pen);vertRight
            $y+=$w
            Koch_curve($x,$y,$w,$pen,2,$backpen)
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzRight
            Koch_curve($x,$y,$w,$pen,0,$backpen)
            $x+=$w
            
        Case 1;VertLeft  <|
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertLeft
            Koch_curve($x,$y,$w,$pen,1,$backpen)
            $y-=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x-$w,$y,$pen);horzBottom
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$backpen);blankspace
            $x-=$w
            Koch_curve($x,$y,$w,$pen,3,$backpen)
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertLeft
            Koch_curve($x,$y,$w,$pen,1,$backpen)
            $y-=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzTop
            Koch_curve($x,$y,$w,$pen,0,$backpen)
            $x+=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertLeft
            Koch_curve($x,$y,$w,$pen,1,$backpen)
            $y-=$w
        Case 2;VertRight |>
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertRight
            Koch_curve($x,$y,$w,$pen,2,$backpen)
            $y-=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzBottom
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$backpen);blankspace
            Koch_curve($x,$y,$w,$pen,3,$backpen)
            $x+=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertRight
            Koch_curve($x,$y,$w,$pen,2,$backpen)
            $y-=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x-$w,$y,$pen);horzTop
            $x-=$w
            Koch_curve($x,$y,$w,$pen,0,$backpen)
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertRight
            Koch_curve($x,$y,$w,$pen,2,$backpen)
            $y-=$w
        Case 3; HorizBottom `|_|`
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzBottom
            Koch_curve($x,$y,$w,$pen,3,$backpen)
            $x+=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$backpen);blankspace
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y+$w,$pen);vertLeft
            $y+=$w
            Koch_curve($x,$y,$w,$pen,1,$backpen)
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzBottom
            Koch_curve($x,$y,$w,$pen,3,$backpen)
            $x+=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x,$y-$w,$pen);vertRight
            Koch_curve($x,$y,$w,$pen,2,$backpen)
            $y-=$w
            _GDIPlus_GraphicsDrawLine($gr,$x,$y,$x+$w,$y,$pen);horzBottom
            Koch_curve($x,$y,$w,$pen,3,$backpen)
            $x+=$w
        Case Else
            Return 0
    EndSwitch
    Display()
EndFunc
Func Sierpinski_carpet($x,$y,$w,$brush,$fill=True,$backbrush=0)
    Global $Draw
    If Not $Draw Then Return 0
    If $fill Then
        _GDIPlus_GraphicsFillRect($gr, $x, $y, $w, $w,$brush)
        Display()
    EndIf
    If $w<(3^$Detail) Then Return 0
    $w/=3
    For $xi=0 To 2
        For $yi=0 To 2
            $xn=$x+($w*$xi)
            $yn=$y+($w*$yi)
            If $xi=1 And $yi=1 Then
                _GDIPlus_GraphicsFillRect($gr, $xn, $yn, $w, $w,$backbrush)
                Display()
            Else
                Sierpinski_carpet($xn,$yn,$w,$brush,$fill,$backbrush)
            EndIf
        Next
    Next
EndFunc
Func Clear($color=0xFF000000,$force=True)
    _GDIPlus_GraphicsClear($gr,$color)
    Display($force)
EndFunc
Func Display($force=False)
    Global $fpstimer
    Global $wanted_fps
    #cs
    Min frames   1 frame      (1 frame)*(1000 ms)   X   ms
    ---------- = -------      ------------------- = --------
    1000 ms    X  ms         Min frames           1
    
    1000 ms / Min frames = X ms where X ms is the corresponding time until 1 frame is forced. 
    #ce
    
    If (Not $force) And $wanted_fps=0 Then Return 0; Zero FPS will only redraw when forced.
    Local $diff=TimerDiff($fpstimer)
    If $force Or $diff>(1000/$wanted_fps) Then; this will return true when $fpstimer is not set (zero value)
        _GDIPlus_GraphicsDrawImageRect($gro, $grb, 0, 0, $ImageWidth, $ImageHeight);copy to bitmap
        
        
        If Not $force Then
        
            $diff=1000/$diff; assumed fps judging by time since last frame
            
            Global $lfps
            $lfps+=$diff
            $lfps/=2; the current average FPS
            
            
        ;#cs
            If $lfps<$wanted_fps Then 
                $lfps+=0.1; add 0.2 because otherwise the FPS goes continually down.
            EndIf
            $wanted_fps+=$lfps
            $wanted_fps/=2;  auto-adjust the desired FPS to average between the current FPS and the desired FPS
        ; would just skip using LFPS, but the changes can be too drastic.
            Global $fpsinputtimer
            If TimerDiff($fpsinputtimer)>300 Then; updating the input control too often will reduce performance.
                GUICtrlSetData($iFPS,Round($wanted_fps,2))
                $fpsinputtimer=TimerInit()
            EndIf
        ;#ce
        EndIf
        $fpstimer=TimerInit()
    EndIf
EndFunc

Func Quit()
    _GDIPlus_GraphicsDispose($gr)
    _GDIPlus_BitmapDispose($grb)
    _GDIPlus_GraphicsDispose($gro)
    Exit
EndFunc

11:32 PM 3/11/2009 - changed the position of and the function for the Cantor Ternary.

3:41 AM 3/10/2009 - graphics drawn on bitmap buffer; settable auto-adjusting FPS timer; drawing now abortable.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Ugh, after some searching of the forum I wished I could have deleted this attempt [but I can't] since I found an example by someone else that did much more than this

- now why did I waste all that time doing it by hand? X (

...

:P

Nice work at all! I will have a look on your iterations...

Good night,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

:unsure:

Nice work at all! I will have a look on your iterations...

Good night,

UEZ

Yeah, well I made this post before I saw your posts so.. :P

- none of the drawings here are done with self-contained functions, they all call themselves recursively.

(until they get down to the suggested quality level)

I could probably tweak them to loop instead of calling themselves.

The Koch example works quickly for me but it needs to be greatly simplified, as it currently just draws out one of four sides based on position and length. ( _|``|_ rotated)

Also, with the Koch example, I'm drawing over existing lines to get smaller in detail instead of expanding. (as suggested in articles)

_|``|_ would have 5 sides that could have the pattern drawn on, but if since I get smaller, I have to erase (or draw over with a background color) the middle third of the original line so that the pattern is consistent.

You can see it "erase" the larger pattern while drawing when it makes large lines which are broken down.

PS: I keep having a problem where my desktop appears to refresh while drawing and the Graphics object clears to the GUI background color. (as if I dragged it off-screen)

Going to use a Bitmap buffer like you did, but I'm still having the same problem.

(although at least using the bitmap redraws the entire image when it happens)

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Small edit

Now drawing on a bitmap buffer before drawing to the screen (complete image redrawn now, not partials)

Added adjustable FPS/redraw timer - this will increase/decrease automatically depending on the performance.

Drawing is now abortable (Note: try this on the Koch Curve with detail 4+ :P )

Buffer is now redrawn while idle. (so that you don't lose what you had drawn)

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Small edit

Now drawing on a bitmap buffer before drawing to the screen (complete image redrawn now, not partials)

Added adjustable FPS/redraw timer - this will increase/decrease automatically depending on the performance.

Drawing is now abortable (Note: try this on the Koch Curve with detail 4+ :unsure: )

Buffer is now redrawn while idle. (so that you don't lose what you had drawn)

You have a completely different buildup of the code structure, which is much faster than what I used :P

When I've more time I will analyze it...

Good job!

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You have a completely different buildup of the code structure, which is much faster than what I used :P

When I've more time I will analyze it...

Good job!

UEZ

Small update

Changed the postion of the Cantor Ternary (bottom edge was cut off)

Changed the function for the Cantor Ternary. (no parameters or results have changed, though.)

I ATTEMPTED to make an iterated Cantor Ternary

- but what I ended up doing is created a arrayed backlog of the children to draw.

(since if you purely iterate you'd only draw draw down one side of the Ternary - you need some way to remember that you have more than one item at the same level to draw the children of.)

So, I'm not sure if an array of draw information qualifies as iteration or not - it is, however, using only one loop and no calls to itself.

(However, the function is longer)

This function and the original need to be checked for speed - they are both in the script.

(the original is in a comment block)

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Without backlogging or some other trick, I don't think there's a great way to handle a recursively-natured fractal like Cantor Ternary .... I mean, unless you have some way to produce these values:

Line 1 - 0 spaces
Line 2 - 1 space   [1/3]
Line 3 - 3 spaces  [1/9, 1/3, 1/9]
Line 4 - 7 spaces  [1/27, 1/9, 1/27, 1/3, 1/27, 1/9, 1/27]
Line 5 - 15 spaces
...

And so on..

And that's just the SPACES in order!

(actually after writing that out it looks SORTA possible, but difficult - I'll still need an array I bet )

Anyway - here's an iterated function that will quickly EMULATE Candor Ternary up to line 5 (and no further)

Since it's only emulating what it can't reach, I won't include it in the script.

I will start working on something that actually works for all values - but I'm seeing difficulties already.

Func Cantor_ternary_emulate($x,$y,$w,$pen,$spacing=10)
;emulation of Cantor Ternary - only works for lines 2-5
    Local $sections=1
    For $line=1 To 5
            Local $offset=$x
            Local $offset2
            Local $csects=$sections/2
            For $i=1 To $csects
                If $i>$csects Then ExitLoop
                $offset2=$offset
                If Mod($i,2)=0 And $i>2 Then
                    $offset2-=$w*3  +  ((3^($i-1))*$w)
                    $offset2+=$w*3  +  ((3^1)*$w)
                EndIf
                _GDIPlus_GraphicsDrawLine($gr,$offset2,$y,$offset2+$w,$y,$pen)
                _GDIPlus_GraphicsDrawLine($gr,$offset2+$w*2,$y,$offset2+$w*3,$y,$pen)
                ConsoleWrite(' End: '&($offset2+$w*3)&@CRLF)
                Display()
                If Mod($i,2)=0 And $i>2 Then
                    $offset=$offset2 +$w*3 +  (3^($i-1)*$w)
                    $i-=4
                    $csects-=4
                Else
                    $offset+=$w*3   +  ((3^$i)*$w)
                EndIf
            Next
        $y+=$spacing
        $w/=3
        $sections*=2
    Next
EndFunc
Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

I also tried to convert the Levy-C Curve to an iteration version but I didn't find out the way to transfer it. I draw the tree to excel but couldn't see it :P

That's the challenge...

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I also tried to convert the Levy-C Curve to an iteration version but I didn't find out the way to transfer it. I draw the tree to excel but couldn't see it :unsure:

That's the challenge...

UEZ

I still think that without cheap tricks like storing a changeable list of children, it may be beyond the capabilities of iteration to do some of these operations (how else do you process for each child of a parent AS a parent inside itself without losing track of children at other levels?)

- you will find yourself staring into the "loop abyss."

Pseudo:

for each child ...
   for each child ...
        for each child ...
           .....
        next
   next
next

With no real way to reintroduce the entry into an identical loop without losing the other items in the loop you're currently in! (eg: trying to replace these infinite number of loops with a single loop has the cost of your other children in the loop, without a trick, that is.)

Originally I tried to overcome this in my "emulation" by considering the children simply as "lines" which I could calculate the spaces for.

- I was dead wrong, every parent above the child as well as separate sets of children change influence the line and space widths.

Even the *new* cantor_ternary could be considered an "emulation" because of two things:

1. using an array to backlog children to draw may be considered cheating; Cantor probably is NOT able to be iterated similar ways.

2. the backlog array is limited in the number of same-level children (+1 for the iterated child being added/deleted). It currently can only hold 20 items (that's all I needed for this example) but it will always be limited in some way.

However, if we are hell-bent on iteration, we might accept several emulative compromises:

1. Have the drawing data saved before-hand (lengths hopefully saved relative to the total width)

2. Back-log children (using arrays, strings, patterned variable names, other quirky devilry.)

3. Give up and dig a hole somewhere to avoid fractals altogether.

4. Write a DLL in C++ (or whatever) so you can do recursion or one of the above cheats somewhat faster.

5. Give up and go back to functional recursion.

Cantor - WikiPedia highlights of doom.

"It has no derivative at any member..."

"... is not injective ..."

"

Iterative Construction:

... Then fn+1(x) will be defined in terms of fn(x) ..." (In AutoIt? I doubt it. :P )

Good luck - if you can iterate it without a "trick", you'll amaze me.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...