Results 1 to 5 of 5

Thread: fractals

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    Smile

    How do you create a fractal image in VB?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    do you know what sort of fractal you want, there are loads of different types, If you mean the pretty colourful swirly ones, then those are called the Mandlebrot set and the Julia Set, if you want to do these then you will need a pretty good understanding of complex numbers, If you can get at a maths teacher, or someone with a maths or physics degree then they'll be able to explain a lot better than anyone can in just text. I'll whip you up some source code for the mandlebrot set.

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    There are some programs for doing that on psc.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    ok, here's some code, you need a picturebox and a command button. Keep the picturebox roughly sqare and press the command button.

    I've actually gotta go so I don't have time to explain much anything

    play about with changing the scalemode of the picture box to zoom in on interesting points. what's there is very basix and very slow, but it gives you the basic mandlebrot set, most of the wierd swirly things are small parts of that picture blown up. (you might need to increce the size of the counter loop and use a different colour scheme if you're zooming in, QBColor only alows 16 colours)
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
    
    Dim Cre As Double  'Cre and Cim represents the complex number C
    Dim Cim As Double
    
    Dim Zre As Double   'Zre and Zim represents the complex number Z
    Dim Zim As Double
    
    Dim Counter As Integer
    Dim dblTemp As Double
    
    'loop through
    For Cre = Picture1.ScaleLeft To (Picture1.ScaleLeft + Picture1.ScaleWidth) Step (Picture1.ScaleWidth / Form1.ScaleX(Picture1.Width, Form1.ScaleMode, vbPixels))
    
        For Cim = Picture1.ScaleTop To (Picture1.ScaleTop + Picture1.ScaleHeight) Step (Picture1.ScaleHeight / Form1.ScaleY(Picture1.Height, Form1.ScaleMode, vbPixels))
    
            Zre = 0
            Zim = 0
            
            For Counter = 0 To 14
            
                'first square the complex number z
                
                'dbltemp stores the new real part of z
                dblTemp = (Zre ^ 2) - (Zim ^ 2)
                
                'calculate the imaginary part and assign to Z
                Zim = (2 * Zre * Zim) + Cim
                Zre = dblTemp + Cre
                
                'note we added C to Z^2 so we have performed the transformation Z->Z^2 + C
                
                If ((Zre ^ 2) + (Zim ^ 2)) > 4 Then
                'if the modulus of the new complex number is greater than 2
                'then exit the loop
                'NB the modulus of z = sqrt(Zre^2 + Zim^2)
                'but we dont bother to square root and just compare to 4
                    Exit For
                    
                End If
                
                'the colour of the pixel denotes the number ot times we performed the transformation
                'before the modulus exeeded 2
                Picture1.PSet (Cre, Cim), QBColor(Counter)
            
            Next Counter
    
        Next Cim
        
    Next Cre
    
    End Sub
    
    Private Sub Form_Load()
    
    'Set the scalemode of the picturebox to represent a square of side 4
    'with the centre of the square as (0,0) (nb it's upside down but that doesn't matter)
    
    
    Picture1.ScaleTop = -2
    Picture1.ScaleLeft = -2
    Picture1.ScaleHeight = 4
    Picture1.ScaleWidth = 4
    
    End Sub

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Change part of that to this to get a top-down view of Concorde...
    Code:
    'calculate the imaginary part and assign to Z
    Zim = (2 * (Zre ^ 2) * Zim) + Cim
    Zre = dblTemp + Cre
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width