PDA

Click to See Complete Forum and Search --> : fractals


Harrild
Nov 16th, 2000, 02:20 AM
How do you create a fractal image in VB?

Sam Finch
Nov 16th, 2000, 09:22 AM
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.

oetje
Nov 16th, 2000, 09:41 AM
There are some programs (http://www.planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?txtCriteria=fractal&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPage=10&blnResetAllVariables=TRUE&lngWId=1&optSort=Alphabetical) for doing that on psc.

Sam Finch
Nov 16th, 2000, 09:56 AM
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)

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

parksie
Nov 17th, 2000, 06:07 PM
Change part of that to this to get a top-down view of Concorde...

'calculate the imaginary part and assign to Z
Zim = (2 * (Zre ^ 2) * Zim) + Cim
Zre = dblTemp + Cre