Basic4GL
« Crazy Fractal Patterns »

Welcome Guest. Please Login or Register.
Sept 3, 2010, 4:50am




Basic4GL :: BASIC4GL Boards :: Basic4GL demo programs :: Crazy Fractal Patterns
   [Search This Thread][Send Topic To Friend] [Print]
 AuthorTopic: Crazy Fractal Patterns (Read 469 times)
matthew
Global Moderator
*****
member is offline

[avatar]

[icq] [yim] [msn] [aim]
[homepage]

Joined: Apr 2006
Gender: Male
Posts: 1,861
Location: England
 Crazy Fractal Patterns
« Thread Started on May 19, 2007, 12:43pm »

I came across this Programme when I was browsing through the FreeBasic Forum. :P

I thought I'd convert it to Basic4GL. ;)

[image]

Just leave the Programme Running and it will draw Crazy Patterns on your Screen. :D

Code:
' This Programme is Based on One I found on the FreeBASIC Forum...
'

' Define Our Variables and Constants here...
'

Dim j#, k#, x#, Xx#, y#
Dim XSize, YSize, i, Xp, Yp, RidX, XOffs, YOffs, c1, c2, c3

' Initialise any Variables and Constants here...
'

XSize = WindowWidth()
YSize = WindowHeight()

XOffs = (XSize / 2)
YOffs = (YSize / 2) - 60

' Create a 2D Screen...
'

glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, XSize, YSize, 0, 0, 1)
glMatrixMode (GL_MODELVIEW)
glDisable (GL_DEPTH_TEST)
glDrawBuffer (GL_FRONT)

' Generate True Random Numbers...
'

Randomize()

' Draw Our Scene...
'

While TRUE

glClearColor (0.0, 0.0, 0.0, 0.0)
glClear (GL_COLOR_BUFFER_BIT)

j# = Rnd() % 100
k# = Rnd() % 100
x# = 0
y# = 0

c1 = Rnd() % 255
c2 = Rnd() % 255
c3 = Rnd() % 255

For i = 0 to 500000

RidX = Rnd() % 4000

If RidX > 3998 then
c1 = Rnd() % 255
c2 = Rnd() % 255
c3 = Rnd() % 255
EndIf

Xx# = y# - Sgn(x#) * Sqr(Abs(k# * x# - 1))
y# = j# - x#
x# = Xx#

Xp = (x# * 2) + XOffs
Yp = (y# * 2) + YOffs

glBegin(GL_POINTS)
glColor3ub(c1, c2, c3)
glVertex2f(Xp, Yp)
glEnd()
glFlush()

Next

Wend

« Last Edit: May 19, 2007, 12:45pm by matthew »Link to Post - Back to Top  IP: Logged

Nicky Peter Hollyoake
Global Moderator
*****
member is offline

[avatar]

You only see what you believe.



Joined: Apr 2006
Gender: Male
Posts: 1,968
Location: uk
 Re: Crazy Fractal Patterns
« Reply #1 on May 19, 2007, 1:47pm »

Excellent programme. The one you shown up there looks like some kinda spider web.
Link to Post - Back to Top  IP: Logged
matthew
Global Moderator
*****
member is offline

[avatar]

[icq] [yim] [msn] [aim]
[homepage]

Joined: Apr 2006
Gender: Male
Posts: 1,861
Location: England
 Re: Crazy Fractal Patterns
« Reply #2 on May 19, 2007, 2:05pm »

Yeah, some of the patterns which get created look really strange. :)
Link to Post - Back to Top  IP: Logged

Nicky Peter Hollyoake
Global Moderator
*****
member is offline

[avatar]

You only see what you believe.



Joined: Apr 2006
Gender: Male
Posts: 1,968
Location: uk
 Re: Crazy Fractal Patterns
« Reply #3 on May 20, 2007, 4:10pm »

Could you explain the 'Randomize' command you use? What you mean by 'TRUE random numbers'?
Link to Post - Back to Top  IP: Logged
steven522
Posts
**
member is offline

[avatar]



Joined: May 2007
Gender: Male
Posts: 60
Location: USA
 Re: Crazy Fractal Patterns
« Reply #4 on May 21, 2007, 9:15am »

If this came from the freebasic forum originally, then freebasic mimics QBasic's rnd function and returns a list of random numbers that are the same every time. You have to use the randomize(timer) function to make the numbers randomly random.
Link to Post - Back to Top  IP: Logged
Empyrion Martyr
Posts a lot
****
member is offline

[avatar]

[yim] [msn]

Joined: Jan 2007
Gender: Male
Posts: 349
Location: Bucharest, Romania
 Re: Crazy Fractal Patterns
« Reply #5 on May 27, 2007, 4:35pm »

That is pseudorandom not truly random (the randomize thingie takes some numbers from the computer clock and initializes the rnd with that value as a seed). To build a roughly good random number generator you would probably need real life dice and coins :D. Anyways good fractals, that would be nice as a screensaver.
« Last Edit: May 27, 2007, 4:37pm by Empyrion Martyr »Link to Post - Back to Top  IP: Logged

Omnis vulnerat, ultima necat...
davy
Global Moderator
*****
member is online
member is offline

[avatar]

[msn] [aim]
[homepage]

Joined: May 2006
Gender: Male
Posts: 1,049
Location: USA
 Re: Crazy Fractal Patterns
« Reply #6 on May 29, 2007, 11:00am »


Quote:
That is pseudorandom not truly random (the randomize thingie takes some numbers from the computer clock and initializes the rnd with that value as a seed). To build a roughly good random number generator you would probably need real life dice and coins :D. Anyways good fractals, that would be nice as a screensaver.


Actually... It depends how you define random. But, there really is no TRUE random.

Even those dice and coins are playing out a physical situation based on it's initial velocity, sort of like the clock tick on a computer.

Random is basically another word for "unpredictable" and unless you know the exact tick cycle, you can't predict the computers random number.

Just like how you can't predict the outcome of a coin because you don't know how hard it will be tossed and at what angle.
Link to Post - Back to Top  IP: Logged

Empyrion Martyr
Posts a lot
****
member is offline

[avatar]

[yim] [msn]

Joined: Jan 2007
Gender: Male
Posts: 349
Location: Bucharest, Romania
 Re: Crazy Fractal Patterns
« Reply #7 on May 30, 2007, 1:53pm »

Well, yeah if that's the case i guess ya right, davy, there really is no true random. I think in the end all breaks down to what method gives you the most unpredictable numbers. (As for the coins and dice, yup, generally all phisical random outcomes of a situation, the Global Conciousness Project really shakes the belief that you can't influence the result, but that's why i said "ROUGHLY" above.)
« Last Edit: May 30, 2007, 1:53pm by Empyrion Martyr »Link to Post - Back to Top  IP: Logged

Omnis vulnerat, ultima necat...
   [Search This Thread][Send Topic To Friend] [Print]

Google
Webbasic4gl.proboards.com
Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Report Abuse | Mobile