1. spiral3d
- Posted by Sistema Solar Roos <roos at CTV.ES> Nov 13, 1996
- 1552 views
Este es un mensaje multipartes en formato MIME. --------------692769A555DF This is a follow up to my spiral program sent earlier this week. As I have been currently experimenting with 3D calculations, this version is 3D! Again, the user is asked for input and then a 3D spiral is calculated stored in memory and rotated on the x,y and z axis. I think I have more or less clear the calculations to rotate a 3D object and then transform the coordinates to 2D for screen output. But when it comes to shading a side eg. a rotating cube, I am having problems finding out which sides are visible (therefore require painting) and which are not. Saludos Adam H. Jackson --------------692769A555DF Content-Disposition: inline; filename="SPIRAL.EX" without type_check include get.e include graphics.e object spiral,draw,draw_old atom check integer turns,step,size_x,size_y,depth constant pi=3.141596 constant rad=pi/180 -- To convert from Radians to Degrees when multiplied by -- the angle. eg. sin(90*rad)=1 function input(sequence text) -- To print a message a return a number sequence inp,cur inp={1,0} puts (1,text) -- message on screen while inp[1] do -- repeat until valid number cur=get_position() -- back to position if not valid inp = get (0) position (cur[1],cur[2]) end while return inp[2] end function -- ** convert_3d2d function convert_3d2d(object points, atom turn_x, atom turn_y, atom turn_z, atom pos_x, atom pos_y, atom pos_z) object work_x, work_y, work_z object temp_x, temp_y, temp_z object screen_x, screen_y -- turn on x axis work_x=points[1] --turn on y axis work_x=temp_x work_z=temp_z --turn on z axis work_x=temp_x work_y=temp_y --convert 3d coordinates to 2d screen coordinates screen_x=(work_x/(work_z-1024))*pos_z+pos_x screen_y=(work_y/(work_z-1024))*pos_z+pos_y return {floor(screen_x),floor(screen_y)} end function -- ** flip_array function flip_array(sequence array) --eg array {{1,2,3},{10,20,30}} sequence f_array -- flips to {{1,10},{2,20},{3,30}} -- and vice versa. NB. all elements = f_array=array[1] for n=1 to length(array[1]) by 1 do for i=2 to length(array) by 1 do f_array[n]=f_array[n]&array[i][n] end for end for return f_array end function procedure finito() check=graphics_mode(-1) abort(-1) end procedure -- Main part of program sorry about lazy structuring of the program but I will -- leave something for you to do turns=input("Number of spiral turns(try 10) ") step=input("\nSpiral steps(try 30) ") size_x=input("\nMax size x of spiral(try 300) ") size_y=input("\nMax size y of spiral(try 300) ") depth=input("\nDepth of spiral (1-500) ") clear_screen() integer color,x,y,z check=graphics_mode(18) bk_color(BLACK) clear_screen() spiral={} -- centre of spiral in first element draw_old={} draw={} for a=1 to 360*turns by step do x=floor(cos(a*rad)*a/(360*turns)*size_x) y=floor(sin(a*rad)*a/(360*turns)*size_y) z=floor(a/(360*turns)*depth) -- Depth of spiral spiral=spiral&{{x,y,z}} end for spiral=flip_array(spiral) -- Rearranges spiral for easier 3D calculations for turn_z=1 to 360 by 90 do -- to turn spiral on z axle for turn_y=1 to 360 by 45 do -- to y for turn_x=1 to 360 by 10 do -- x draw=convert_3d2d(spiral,turn_x,turn_y,turn_z,320,200,256) -- Converts 3D to 2D draw=flip_array(draw) -- Puts spiral into original arrangment if length(draw_old)>1 then draw_line(BLACK,draw_old) end if -- erase old draw_line(WHITE,draw) -- draw new spiral draw_old=draw check=get_key() if check!=-1 then finito() end if end for end for end for finito() --------------692769A555DF--
2. Re: spiral3d
- Posted by "Lucien T. Elliott" <lucien at NY.FRONTIERCOMM.NET> Nov 13, 1996
- 1518 views
neat effects to all you spiral writers. drove myself nuts getting some idea of what values worked for the parameters tho! and whoever had the printer.dbf, how about a url reference? Lucien T. Elliott Warwick Information Technology 29 Hawthorn Avenue Warwick, NY 10990 (914) 986 5139 URL //ny.frontiercomm.net/~lucien EMAIL lucien at ny.frontiercomm.net