Post by Alan on Jul 29, 2005 9:36:42 GMT -5
const width = 128 ' Must be a power of 2
const height = 128 ' Must be a power of 2
dim a1#(height-1)(width-1) ' Due to the way Basic4GL stores arrays, the first dimension
dim a2#(height-1)(width-1) ' actually ends up as the Y, and the second as the X when the texture is loaded into OpenGL
dim n
dim x, y
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
gluOrtho2D (0, 1, 0, 1)
glMatrixMode (GL_MODELVIEW)
dim tex
glEnable (GL_TEXTURE_2D)
tex = glGenTexture ()
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
sleep(1000)
here:
for x = (width * .5) - 4 TO (width * .5) + 4
for y = (height * .5) - 4 to (height * .5) + 4
if a1#(y)(x) = 0 then a1#(y)(x) = int(rnd() % 4) endif
if a1#(y)(x) > 1 then a1#(y)(x) = 0 endif
next
next
for x = 1 to width - 2
for y = 1 to height - 2
n = (a1#(y-1)(x-1) + a1#(y-1)(x) + a1#(y-1)(x+1) + a1#(y)(x+1) + a1#(y+1)(x+1) + a1#(y+1)(x) + a1#(y+1)(x-1) + a1#(y)(x-1))
if a2#(y)(x) = 1 then
if n = 2 or n = 3 then a2#(y)(x) = 1 else a2#(y)(x) = 0 endif
else
if n = 3 then a2#(y)(x) = 1 endif
endif
next
next
for x = 0 to width - 1
for y = 0 to height - 1
a1#(y)(x) = a2#(y)(x)
next
next
glTexImage2D (GL_TEXTURE_2D, 0, 1, width, height, 0, GL_LUMINANCE, GL_FLOAT, a1#)
glClearColor (0, 0, 0, 0)
glDisable (GL_DEPTH_TEST)
glEnable (GL_TEXTURE_2D)
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE)
glClear (GL_COLOR_BUFFER_BIT)
glColor3f (1, 1, 1)
glBegin (GL_QUADS)
glTexCoord2f (0, 1): glVertex2f (0, 0)
glTexCoord2f (1, 1): glVertex2f (1, 0)
glTexCoord2f (1, 0): glVertex2f (1, 1)
glTexCoord2f (0, 0): glVertex2f (0, 1)
glEnd ()
SwapBuffers ()
waittimer(10)
goto here:
const width = 128 ' Must be a power of 2
const height = 128 ' Must be a power of 2
dim a1#(height-1)(width-1) ' Due to the way Basic4GL stores arrays, the first dimension
dim a2#(height-1)(width-1) ' actually ends up as the Y, and the second as the X when the texture is loaded into OpenGL
dim a3#(height-1)(width-1)
dim n
dim x, y
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
gluOrtho2D (0, 1, 0, 1)
glMatrixMode (GL_MODELVIEW)
dim tex
glEnable (GL_TEXTURE_2D)
tex = glGenTexture ()
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
sleep(1000)
here:
for x = (width * .5) - 4 TO (width * .5) + 4
for y = (height * .5) - 4 to (height * .5) + 4
if a1#(y)(x) = 0 then a1#(y)(x) = int(rnd() % 4) endif
if a1#(y)(x) > 1 then a1#(y)(x) = 0 endif
next
next
for x = 1 to width - 2
for y = 1 to height - 2
n = (a1#(y-1)(x-1) + a1#(y-1)(x) + a1#(y-1)(x+1) + a1#(y)(x+1) + a1#(y+1)(x+1) + a1#(y+1)(x) + a1#(y+1)(x-1) + a1#(y)(x-1))
if a2#(y)(x) = 1 then
if n = 2 or n = 3 then a2#(y)(x) = 1 else a2#(y)(x) = 0 endif
else
if n = 3 then a2#(y)(x) = 1 endif
endif
next
next
for x = 0 to width - 1
for y = 0 to height - 1
a1#(y)(x) = a2#(y)(x)
if a1#(y)(x) = 1 then a3#(y)(x) = a3#(y)(x) + .05 endif
next
next
glTexImage2D (GL_TEXTURE_2D, 0, 1, width, height, 0, GL_LUMINANCE, GL_FLOAT, a3#)
glClearColor (0, 0, 0, 0)
glDisable (GL_DEPTH_TEST)
glEnable (GL_TEXTURE_2D)
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE)
glClear (GL_COLOR_BUFFER_BIT)
glColor3f (1, 1, 1)
glBegin (GL_QUADS)
glTexCoord2f (0, 1): glVertex2f (0, 0)
glTexCoord2f (1, 1): glVertex2f (1, 0)
glTexCoord2f (1, 0): glVertex2f (1, 1)
glTexCoord2f (0, 0): glVertex2f (0, 1)
glEnd ()
SwapBuffers ()
waittimer(10)
goto here:
If your a mathematician run the first program
If your an artist run the second.