06-19-2005, 06:36 AM
This has nothing to do with my spinning circle graphics program, but its intresting nonetheless, imo. Not reccommended for slow computers...
to increase speed, or make it simpler, change the nodec constant lower.
to increase speed, or make it simpler, change the nodec constant lower.
Code:
declare function math.distance (x1 as double, y1 as double, x2 as double, y2 as double) as double
const nodec = 4 - 1
randomize timer
type nodetype
x as double
y as double
r as double
g as double
b as double
end type
dim node(nodec) as nodetype
dim x as double
dim y as double
dim n as double
dim dist as double
dim dist2 as double
dim maxd as double
dim n1 as double
dim n2 as double
dim zz as double
screen 19, 32
for x = 0 to nodec
node( x ).x = int( rnd * 800 )
node( x ).y = int( rnd * 600 )
node( x ).r = int(rnd * 16) + 240
node( x ).g = int(rnd * 16) + 240
node( x ).b = int(rnd * 96) + 128
pset( node( x ).x, node( x ).y ), rgb( node( x ).r, node( x ).g, node( x ).b )
next x
print 800 * 600 * nodec / 4
for x = 0 to 799 step 4
for y = 0 to 599 step 4
dist = 10000
for n = 0 to nodec
zz = math.distance( x, y, node( n ).x, node( n ).y)
if zz < dist then dist = zz
next n
if maxd < dist then maxd = dist
next y
next x
for x = 0 to 799 step 1
for y = 0 to 599 step 1
dist = 10000
dist2 = 10000
for n = 0 to nodec
zz = math.distance( x, y, node( n ).x, node( n ).y)
if zz < dist then
swap dist, dist2
swap n1, n2
dist = zz
n1 = n
elseif zz < dist2 and zz > dist then
dist2 = zz
n2 = n
end if
next n
zz = ( dist + dist2 ) / 2 / maxd
red = 255 - ( node( n1 ).r / 2 + node( n2 ).r / 2 ) * zz - 64
if red > 255 then red = 255
if red < 0 then red = 0
green = 255 - ( node( n1 ).g / 2 + node( n2 ).g / 2 ) * zz - 64
if green > 255 then green = 255
if green < 0 then green = 0
blue = 255 - ( node( n1 ).b / 2 + node( n2 ).b / 2 ) * zz - 64
if blue > 255 then blue = 255
if blue < 0 then blue = 0
pset( x, y ), rgb( red, green, blue )
next y
next x
sleep
function math.distance (x1 as double, y1 as double, x2 as double, y2 as double) as double
math.distance = sqr((x1-x2)^2 + (y1-y2)^2)
end function