|
-
Nov 16th, 2000, 03:20 AM
#1
Thread Starter
Addicted Member
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?
-
Nov 16th, 2000, 10:22 AM
#2
Frenzied Member
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.
-
Nov 16th, 2000, 10:41 AM
#3
Fanatic Member
There are some programs for doing that on psc.
-
Nov 16th, 2000, 10:56 AM
#4
Frenzied Member
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
-
Nov 17th, 2000, 07:07 PM
#5
Monday Morning Lunatic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|