Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Fractales by Bo E. Carlsson

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

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips