error :
type error in sub ?
trying to change a const ?
rem :
type's are double's so ?
i do not use a const in that line
Code: Select all
''bluatigro 3 may 2018
''boid's 3D
#include "color.bas"
screen 20 , 32
dim shared as integer winx , winy , i , j
screeninfo winx , winy
type tsphere
dim as double x , y , z , r , pan , tilt , rol
dim as ulong clr
declare sub show()
declare sub get_xyz( byref a as double , byref b as double , byref c as double )
end type
sub tsphere.get_xyz( byref a as double , byref b as double , byref c as double )
a = x
b = y
c = z
end sub
sub tsphere.show()
dim as double sx , sy , sr
sx = winx / 2 + x / ( z + 1000 ) * 1000
sy = winy / 2 - y / ( z + 1000 ) * 1000
sr = r / ( z + 1000 ) * 1000
circle ( sx , sy ) , sr , clr ,,,, f
end sub
function bol( x as double , y as double , z as double _
, r as double , clr as ulong ) as tsphere
dim as tsphere uit
uit.x = x
uit.y = y
uit.z = z
uit.r = r
uit.clr = clr
return uit
end function
dim as tsphere sphere( 100 )
dim as integer ry( 100 )
dim as double dx , dy , dz , x , y , z
for i = 0 to ubound( sphere )
sphere( i ).x = range( -winx / 3 , winx / 3 )
sphere( i ).y = range( -winy / 3 , winy / 3 )
sphere( i ).z = range( -winx / 3 , winx / 3 )
sphere( i ).r = 30
sphere( i ).clr = gray
sphere( i ).pan = range( 0 , 360 )
sphere( i ).tilt = range( -30 , 30 )
sphere( i ).rol = range( -30 , 30 )
ry( i ) = i
next i
paint ( 1 , 1 ) , blue
for i = 0 to ubound( sphere ) - 9 step 10
sphere( i ).get_xyz x , y , z
dx = 40 : dy = 0 : dz = 0
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 1 ) = bol( x + dx , y + dy , z + dz , 10 , red )
dx = -40 : dy = 0 : dz = 0
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 2 ) = bol( x + dx , y + dy , z + dz , 10 , cyan )
dx = 0 : dy = 40 : dz = 0
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 3 ) = bol( x + dx , y + dy , z + dz , 10 , green )
dx = 0 : dy = -40 : dz = 0
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 4 ) = bol( x + dx , y + dy , z + dz , 10 , magenta )
dx = 10 : dy = 0 : dz = -40
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 5 ) = bol( x + dx , y + dy , z + dz , 10 , black )
dx = -10 : dy = 0 : dz = -40
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 6 ) = bol( x + dx , y + dy , z + dz , 10 , black )
dx = 0 : dy = 0 : dz = 40
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 7 ) = bol( x + dx , y + dy , z + dz , 10 , yellow )
dx = 0 : dy = 10 : dz = 50
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 8 ) = bol( x + dx , y + dy , z + dz , 10 , yellow )
dx = 0 : dy = -10 : dz = 50
rotate dx , dz , sphere( i ).pan
rotate dy , dz , sphere( i ).tilt
rotate dx , dy , sphere( i ).rol
sphere( i + 9 ) = bol( x + dx , y + dy , z + dz , 10 , yellow )
next i
for j = 1 to ubound( sphere )
for i = 0 to j - 1
if sphere( ry( j ) ).z > sphere( ry( i ) ).z then
swap ry( i ) , ry( j )
end if
next i
next j
for i = 0 to ubound( sphere )
sphere( ry( i ) ).show
next i
sleep
Code: Select all
''bluatigro 13 feb 2015
''color.bas
''some colors consts + functions
#ifndef COLOR_H
#define COLOR_H
#include "math.bas"
''primary colors
const as ulong black = &hff000000
const as ulong red = &hffff0000
const as ulong green = &hff00ff00
const as ulong yellow = &hffffff00
const as ulong blue = &hff0000ff
const as ulong magenta = &hffff00ff
const as ulong cyan = &hff00ffff
const as ulong white = &hffffffff
''mix colors
const as ulong orange = &hffff7f00
const as ulong gray = &hff7f7f7f
const as ulong pink = &hffff7f7f
const as ulong purple = &hff7f007f
const as ulong darkRed = &hff7f0000
const as ulong darkYellow = &hff7f7f00
const as ulong darkGreen = &hff007f00
const as ulong darkBlue = &hff00007f
function mix( kla as ulong , f as single , klb as ulong ) as ulong
dim as ulong ra , ga , ba , rb , gb , bb , r , g , b
ra = ( kla shr 16 ) and 255
ga = ( kla shr 8 ) and 255
ba = kla and 255
rb = ( klb shr 16 ) and 255
gb = ( klb shr 8 ) and 255
bb = klb and 255
r = ra + ( rb - ra ) * f
g = ga + ( gb - ga ) * f
b = ba + ( bb - ba ) * f
return rgb( r and 255 , g and 255 , b and 255 )
end function
function rainbow( x as single ) as ulong
dim as ulong r , g , b
r = sin( rad( x ) ) * 127 + 128
g = sin( rad( x - 120 ) ) * 127 + 128
b = sin( rad( x + 120 ) ) * 127 + 128
return rgb( r and 255 , g and 255 , b and 255 )
end function
function rndcolor() as ulong
return rgb( rnd * 255 , rnd * 255 , rnd * 255 )
end function
#endif
Code: Select all
''bluatigro 6-nov-2013
''game lib : math helper functions + connstands
#ifndef MATH_H
#define MATH_H
const as double pi = atn( 1 ) * 4
const as double golden_ratio = ( sqr( 5 ) - 1 ) / 2
function rad( x as double ) as double
''help function degrees to radians
return x * pi / 180
end function
function range( l as double , h as double ) as double
return rnd * ( h - l ) + l
end function
sub rotate( byref k as double , byref l as double , deg as double )
dim as double s , c , hk , hl
s = sin( rad( deg ) )
c = cos( rad( deg ) )
hk = k * c - l * s
hl = k * s + l * c
k = hk
l = hl
end sub
#endif