Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2010-10-17
I found my old book on fractales from 1992 by Bo E. Carlsson, in Swedish. The book basically lists a bunch of different fractales, and explains the underlying mathematical formulas.
The book ends with a few Basic code listings.
A quick translation of the Julia set fractal to Visual Basic might look like this. The code is written in a Windows Forms application, so the System.Drawing namespace is imported. I also use type inference:
Using Btmp As New Bitmap(320, 200) Dim S = 3 / 200 Dim T = 3 / 200 Dim P = 0.31 Dim Q = 0.04 For YY = -1.1 To 1.1 Step S For XX = -1.5 To 1.5 Step T Dim X = XX Dim Y = YY Dim K = 0.0 Dim I = ((200 / 3) * XX) + 160 Dim J = ((200 / 3) * YY) + 100 Dim M = 0.0 Do Btmp.SetPixel(I, J, Color.Red) Dim A = ((X * X) - (Y * Y)) + P Dim B = ((2 * X) * Y) + Q X = A Y = B K += 1 M = (X * X) + (Y * Y) If K > 100 Then Exit Do End If If Not M < 4 Then I = ((200 / 3) * XX) + 160 J = ((200 / 3) * YY) + 100 Btmp.SetPixel(I, J, Color.Black) End If Loop While M < 4 Next Next Using G As Graphics = Me.CreateGraphics() G.DrawImage(Btmp, 0, 9) End Using End Using
The above code could be written in the click event of a button. If you think the result is slightly stiff and unromantic, remember that the original code could be written for any strange old machine, like a Commodore 128 or an Apple II.
Thank you, Bo E. Carlsson!
Categories: Geeky
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
Leave a Reply