3D Fractal Generator by Final Zero20th Mar 2004 21:51
|
---|
Summary It generates a particular fractal in 3d Description It generates a fractal in 3d that ends up looking like a single pyramid made of 3 pyramids all made of 3 pyramids and so on. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `Fractal Generator Program `Long Live the Triforce `http://chaoticvoid.vze.com `By Final_Epsilon and Final Zero `Standard Stuff Sync On Sync Rate 30 randomize rnd(1000) autocam off `Compensation for various resolutions screen_width = screen width() screen_height = screen height() `Cory - initialise camera movement code x# = 0 y# = 0 z# = -800 position camera x#, y#, z# point camera 0, 0, 0, 0 bearing# = 0 azimuth# = 0 distance# = 200 mousedistancez# = 1000 `Mathematical Variables generating = 1 p1x#=0 p1y#=50 p1z#=-25 p2x#=-50 p2y#=-50 p2z#=-25 p3x#=50 p3y#=-50 p3z#=-25 p4x#=0 p4y#=0 p4z#=50 make object sphere 1,1 position object 1, p1x#,p1y#,p1z# make object sphere 2,1 position object 2, p2x#,p2y#,p2z# make object sphere 3,1 position object 3, p3x#,p3y#,p3z# make object sphere 4,1 position object 4, p4x#,p4y#,p4z# point camera 0,0,0 mpx#=rnd(100) mpy#=rnd(100) mpz#=rnd(100) rp#=rnd(3)+1 on#=4 Do `Cory - reset camera scroll variables mouse_x# = 0 mouse_y# = 0 `Cory - Camera control (and scrolling) code if mousey() >= (screen_height - 50) then mouse_y# = 2 if mousex() >= (screen_width - 50) then mouse_x# = 2 if mousey() <= (50) then mouse_y# = -2 if mousex() <= (50) then mouse_x# = -2 bearing# = wrapvalue(bearing# - mouse_x#) azimuth# = wrapvalue(azimuth# - mouse_y#) x# = distance# * sin(azimuth#) * cos(bearing#) z# = distance# * sin(azimuth#) * sin(bearing#) y# = distance# * cos(azimuth#) position camera x#, y#, z# `Fractal Generator if generating = 1 on#=on#+1 rp#=rnd(3)+1 if rp#=1 then mpx#=mpx#/2+p1x#/2: mpy#=mpy#/2+p1y#/2: mpz#=mpz#/2+p1z#/2 if rp#=2 then mpx#=mpx#/2+p2x#/2: mpy#=mpy#/2+p2y#/2: mpz#=mpz#/2+p2z#/2 if rp#=3 then mpx#=mpx#/2+p3x#/2: mpy#=mpy#/2+p3y#/2: mpz#=mpz#/2+p3z#/2 if rp#=4 then mpx#=mpx#/2+p4x#/2: mpy#=mpy#/2+p4y#/2: mpz#=mpz#/2+p4z#/2 make object sphere on#,1 position object on#,mpx#,mpy#,mpz# endif `User Inputs if upkey()=1 then distance#=distance#-5 if downkey()=1 then distance#=distance#+5 if leftkey()=1 then generating = 0 if rightkey()=1 then generating = 1 if spacekey()=1 then sync rate 0 else sync rate 30 `print interesting data set cursor 0,0 print "Welcome to Fractal Generator" Print "Controls: Up=Zoom In; Down=Zoom Out;" Print "Left=Pause; Right=Play; Hold Spacebar=Sync Rate 0" Print "Move your cursor to the edge of the screen to rotate around" print "" print "Number of Objects: ",on# Print "FPS: ",screen fps() `resync point camera 0,0,0 Sync Loop |