Fracktal Di Visual Basic

Aduhh mulai post lagii, padahal lagi sebel…. Bgt ma seseorang. Tapi kali ini di post kedua tentang Visual Basic saya di sini akan membahasa tentang Fracktal, Tau Fracktal gak ? uuh aku juga gaks tau tapi menurut kolom “Inilah Definisinya” yang ada di tabloid PCMILD edisi18/2007 (aku nemu ini di tumpukan Koran,, ih sebel deh masa mau di buang smuanya ma mamah  ) kembali ke fracktal. Fracktal adalah benda geometris yang kasar pada segala skala, dan terlihat dapat “dibagi – bagi” dengan cara yang radikal. Fracktal dekatakan memiliki detail yang tak terhingga dan dapat memiliki struktur menyerupai dirinya sendiri pada tingkat pembesaran yang berbeda. Itulah adik2 cuplikan dari PCMILD edisi 18/2007. Oks lanjut membuat fracktal

Download Source Codenyah disini

Nah untuk membuat fracktal Anda harus mempunyai 1.Buah telur 2.Buah Ayam allllllah nyacoooo, baiklah 2 picturebox dengan background hitam dan 2 buah command button masing2 dengan caption Refresh dan Stop. Picturebox pertama ada di bagian atas button dan picturebox ke dua ada di bagian bawah button. Lets Making !



-----------------------------------------[CODE MULAI]---------------------------------------

‘ Di module

Type complex

real As Double

i As Double

End Type

Dim scheme As Integer

Dim drawing As Integer

Dim stop_draw As Integer

Function init()

stop_draw = 0

End Function

Function stop_drawing()

stop_draw = 1

End Function

Function set_scheme(x As Integer)

scheme = x

End Function

Function add(x1 As complex, x2 As complex) As complex

Dim temp As complex

Dim a1 As Double, a2 As Double

Dim b1 As Double, b2 As Double

a1 = x1.real: b1 = x1.i

a2 = x2.real: b2 = x2.i

temp.real = a1 + a2

temp.i = b1 + b2

add = temp

End Function

Function mul(x1 As complex, x2 As complex) As complex

Dim temp As complex

Dim a1 As Double, a2 As Double

Dim b1 As Double, b2 As Double

a1 = x1.real: b1 = x1.i

a2 = x2.real: b2 = x2.i

temp.real = a1 * a2 - b1 * b2

temp.i = a1 * b2 + a2 * b1

mul = temp

End Function

Function dist(x As Double, Y As Double) As Double

dist = Sqr(((x - 0) ^ 2) + ((Y - 0) ^ 2))

End Function

Function is_in_Mset(c As complex, n As Integer) As Integer

Dim Z As complex

Dim tZ As complex

Z.real = 0: Z.i = 0

tZ.real = 0: tZ.i = 0

For i = 1 To n

tZ = add(mul(Z, Z), c)

Z = tZ

If dist(Z.real, Z.i) >= 2 Then

is_in_Mset = i

GoTo done

End If

Next i

is_in_Mset = 0

done:

End Function

Function draw(pic As PictureBox, x1 As Double, y1 As Double, x2 As Double, y2 As Double, detail As Integer)

init

Dim t As complex, x As Double

Dim Y As Double, c As Integer

Dim scaleY As Double

Dim scaleX As Double

Form1.Command1.Enabled = False

scaleX = (x2 - x1) / pic.Width

scaleY = (y2 - y1) / pic.Height

drawing = 1: pic.Cls

pic.DrawWidth = 1

For det = 5 To 1 Step -1

Form1.Picture2.Cls

Form1.Picture2.Print "Rendering - Detail grade "; det

For i = 0 To pic.Width Step det

For j = 0 To pic.Height Step det

x = x1 + (i * scaleX): Y = y1 + (j * scaleY)

t.real = x: t.i = Y

c = is_in_Mset(t, 100)

If stop_draw = 1 Then GoTo zip_it

pic.Line (i + det, 0)-(i + det, pic.Height), QBColor(0)

pic.Line (i, j)-(i + det, j + det), RGB((c Mod 50) * 10, (c Mod 100) * 20, (c Mod 200) * 12), BF

Next j

If stop_draw = 1 Then GoTo zip_it

DoEvents

Next i

Next det

drawing = 0

zip_it:

Form1.Command1.Enabled = True

End Function

‘DI FORM INGET DI FORM

Dim x1 As Double, x2 As Double

Dim y1 As Double, y2 As Double

Dim tx1 As Double, tx2 As Double

Dim ty1 As Double, ty2 As Double

Dim sY As Double, sX As Double

Dim down As Integer

Private Sub Command1_Click()

sX = (x2 - x1) / Picture1.Width

sY = (y2 - y1) / Picture1.Height

draw Picture1, x1, y1, x2, y2, 100

End Sub

Private Sub Command2_Click()

stop_drawing

End Sub

Private Sub Form_Activate()

set_scheme 2

draw_it

End Sub

Private Sub Form_Load()

MsgBox "This Simple Fracktal In Visual Basic", vbInformation, "Fracktal In VB"

x1 = -2: y1 = -1.5

x2 = 1: y2 = 1.5

down = 0: drawing = 0

init

End Sub

Function draw_it()

sX = (x2 - x1) / Picture1.Width

sY = (y2 - y1) / Picture1.Height

draw Picture1, x1, y1, x2, y2, 100

End Function

Private Sub Form_Unload(Cancel As Integer)

stop_drawing

End

End Sub

-----------------------------------------[SELESE AHH]---------------------------------------

Nah klo udah ngoding nyah (padahal Cuma COPY – PASTER) tekan F5 dan lihat hasil nyahhh

klo mo donlot Source nya kilik disini

Share this

Hanya seorang bloger biasa yang mencoba untuk berbagi kepada kalian.

0 Comment to " Fracktal Di Visual Basic "

Posting Komentar

- Komentar harus sesuai topik, tidak menyimpang !
- Komentar bersifat promosi, langsung Saya hapus !