Post by Mottyman on Feb 12, 2006 16:05:37 GMT -5
To try Basic4Gl for the first time, I created a 3D grid of points, spinning around an off-center axis, that changed colour and rate of rotation as it goes.
I extrapolated from The StarField1 demo that comes with the program to create this.
It's a bit messy, although I'm not really looking to improve it myself, as it was just a mess around with the program, but feel free to alter the code as you wish, and also try changing the constants defined at the start.
I extrapolated from The StarField1 demo that comes with the program to create this.
It's a bit messy, although I'm not really looking to improve it myself, as it was just a mess around with the program, but feel free to alter the code as you wish, and also try changing the constants defined at the start.
const Dimension = 15 'How big the Cube is. I recommend no bigger than 25.
const Speed# = 1 'The speed at which the cube rotates. I recommend between 0.1 and 10.
const CC# = 1 'How fast the colour changes. I recommend between 0.1 and 10.
dim Points
Points = Dimension * Dimension
dim Dots#(Points)(Dimension)(2)
dim a#
dim b#
dim c#
dim d#
dim e#
dim f#
dim i
dim q
dim r
dim s
dim x#
dim y#
dim z#
dim level
dim rdot#
dim Colour#
'Presetting Variables
a# = (Rnd() % 10)* Pow(-1, (Rnd() % 2) + 1)
b# = (Rnd() % 10)* Pow(-1, (Rnd() % 2) + 1)
c# = (Rnd() % 10)* Pow(-1, (Rnd() % 2) + 1)
d# = (Rnd() % 255)/255
e# = (Rnd() % 255)/255
f# = (Rnd() % 255)/255
x# = Rnd()%360
y# = Rnd()%360
z# = Rnd()%360
q = 1
r = 1
s = 1
'Defining the points
for i = 1 to Points
for level = 1 to Dimension
Dots#(i)(level) = vec3 (((i % Dimension)-((Dimension-1)/2)),level - ((Dimension-1)/2), (-((i - (i % Dimension))/Dimension))+((Dimension-1)/2))
if i % Dimension = 0 then Dots#(i)(level)(2) = Dots#(i)(level)(2) + 1 endif
next
next
glDisable (GL_DEPTH_TEST)
'Render and Transformations
while true
glClear (GL_COLOR_BUFFER_BIT)
'Checking that colour parameters aren't getting out of range.
if d# >= 1 then q = -1 endif
if e# >= 1 then r = -1 endif
if f# >= 1 then s = -1 endif
if d# <= 0 then q = 1 endif
if e# <= 0 then r = 1 endif
if f# <= 0 then s = 1 endif
'Setting rates of change for colour and rotation.
d# = d# + q*((CC#/1000) * (Rnd() % 5))
e# = e# + r*((CC#/1000) * (Rnd() % 15))
f# = f# + s*((CC#/1000) * (Rnd() % 10))
x# = x# + 0.5
y# = y# + 0.5
z# = z# + 0.5
For i = 1 to Points
For level = 1 to Dimension
glLoadIdentity()
gltranslatef(0,0,-(Dimension*2))
a# = (a# + 100/Dimension)*sind(x#)
b# = (b# + 200/Dimension)*sind(y#)
c# = (c# + 300/Dimension)*sind(z#)
glRotatef(rdot#,a#,b#,c#)
glBegin (GL_POINTS)
glVertex3fv (Dots#(i)(level))
glColor3f (d#,e#,f#)
glEnd ()
rdot# = rdot# + ((Speed#/10)/(Dimension*Dimension))
Next
Next
SwapBuffers ()
'Delay
waittimer(20)
wend