-- -- dimanche 28 octobre 2001 00:39:02 -- -- Lionel Gonalvs // Y0/UnkN0rgZ -- -- Rvision 25/02/2011 -- -- -- -- -- fichier cration des systmes NKYO Galactics -- -- puis criture dans des fichiers de type: -- -- > texte -- -- > *.e -- -- > *.c -- -- > *.pov -- -- -- t0d0: -- -- > contrle de la cration des systmes: -- -- = gestion des variables Nbre_Syst -- -- soit: Nbre_Syst (=33) MaxPlanets (=8) Seed (=20) -- -- -- -- > possibilit d'inclure les noms des systmes et astres divers.-- -- - gnration de noms alatoires. -- -- -- -- > inclure la sortie vers d'autres format (???) -- -- include machine.e --set_rand() include graphics.e include Xget.e -- fichier get.e traduit et lgrement modifi --with trace --trace(1) machine_proc(6,#2000) -- NoTextCursor global constant X=1, Y=2, Z=3, P=4, -- P = nombre de plantes d'un systme -- CadreColor = 5, Seed = 20 integer Nbre_Syst, MaxPlanets sequence coord sequence planets atom rayon integer scale set_rand(Seed) -- X Y Z P coord=repeat({0,0,0,0},33) -- X Y Z planets=repeat({0,0,0},10) planets=repeat(planets,33) scale=0 Nbre_Syst=33 MaxPlanets=8 atom f1 -- flag ouverture fichier sequence nomfichier, nomdefini --nomfichier={} nomdefini={"test"} integer numerofichier function abs(atom x) if x<0 then x=-x end if return x end function constant TO_LOWER = 'a' - 'A' global function lower(object x) -- convertit un atom ou une sequence en minuscule return x + (x >= 'A' and x <= 'Z') * TO_LOWER end function procedure banner() clear_screen() text_color(11) position(23,1) bk_color(1) puts(1,"><\n") puts(1,"> Coords.Ex: Gnrateur de Systmes Galactiques V1.0 <\n") puts(1,"> dimanche 28 octobre 2001 01:13:07 -- Code EUPHORIA RDS <\n") puts(1,"> Lionel Gonalvs // Y0/UnkN0rgZ <\n") puts(1,"><") position(1,1) puts(1,"><\n") puts(1,"> if msg.. <\n") puts(1,"><") bk_color(0) end procedure procedure AffVariables() position(15,15) text_color(CadreColor) puts(1,"ͻ") position(16,15) puts(1,"ͺ") for i=17 to 19 do position(i,15) puts(1," ") end for position(20,15) puts(1,"ͼ") text_color(12) for i=1 to 3 do position(16+i,16) printf(1," %d - ",{i}) end for text_color(14) position(17,20) puts(1," Nombre d'toiles:") position (17,56) text_color(10) bk_color(8) printf(1," %3d",{Nbre_Syst}) bk_color(0) text_color(14) position(18,20) puts(1," Nombre Maxi de plantes par toile:") position(18,56) text_color(10) bk_color(8) printf(1," %3d",{MaxPlanets}) bk_color(0) text_color(14) position(19,20) puts(1," Semence de gnration alatoire:") text_color(10) position(19,56) bk_color(8) printf(1," %3d",{Seed}) bk_color(0) end procedure procedure tirage() atom modif, entre integer NewSeed entre=-1 modif=0 --titre et affichage des variables modifiables banner() AffVariables() position(12,10) text_color(15) puts(1,"Dsires-tu modifier les variables de cration de la Galaxie?") position(13,10) text_color(10) puts(1,"([O]ui-[N]on / par dfaut=Non)") while entre=-1 do entre=lower(get_key()) -- position (2,5) -- printf(1,"%c",{entre}) if entre='o' then modif=1 else modif=0 end if end while -- modification des variables -- nombre d'toiles (Nbre_Syst=33) (mini=10 - maxi=100) if modif=1 then while modif !=-1 do position(10,10) text_color(10) modif = prompt_number("Nombre d'toiles? (Mini:10 - Maxi:100)", {}, 10,10) if modif<10 or modif>100 then modif=1 else Nbre_Syst=modif modif=-1 end if end while AffVariables() end if -- maximum de plantes par toile (MaxPlanets=8) (mini=1 - maxi=15) if modif=-1 then while modif =-1 do position(10,10) text_color(10) modif =prompt_number("Max de plantes par toiles? (Mini:1 - Maxi:15)", {},10,10) if modif<1 or modif>15 then modif=-1 else MaxPlanets=modif modif=1 end if end while AffVariables() end if -- semence du gnrateur (Seed=20) (mini=1 - NoMaxiLimit) if modif=1 then while modif !=-1 do position(10,10) text_color(10) modif = prompt_number("Semence du gnrateur? (Mini:1 - Maxi:100) ", {},10,10) if modif<1 or modif>100 then modif=1 else NewSeed=modif modif=-1 end if end while AffVariables() set_rand(NewSeed) end if -- tirage alatoire des coordonnes de chaque toile for i=1 to Nbre_Syst do coord[i][X]=(rand(100)-50)+rand(100)/100 coord[i][Y]=(rand(100)-50)+rand(100)/100 coord[i][Z]=(rand(100)-50)+rand(100)/100 end for -- tirage du nbre de plantes pour chaque systme et de leurs coordonnes: for i=1 to Nbre_Syst do coord[i][P]=rand(MaxPlanets) scale+=coord[i][P] for i1=1 to coord[i][P] do planets[i][i1][X]=coord[i][X]+((rand(200)-100)/50) planets[i][i1][Y]=coord[i][Y]+((rand(200)-100)/50) planets[i][i1][Z]=coord[i][Z]+((rand(200)-100)/50) end for end for position(20,7) printf(1,"Le nouveau systme galactique comprend: %d toiles et %d plantes", {Nbre_Syst, scale}) end procedure -------------------------------------------------------- -- CRITURES DANS LES FICHIERS ----------------------- -------------------------------------------------------- ------------------------------------------- -- criture dans un fichier format *.POV -- ------------------------------------------- procedure fichierPov() nomfichier="Nkyogn_" & numerofichier & ".pov" --nomfichier=append(nomdefini,".pov") f1=open(nomfichier,"w") puts(f1,"#include \"colors.inc\"\n") puts(f1,"#version unofficial MegaPov 0.4;\n") puts(f1,"global_settings {\n\tassumed_gamma 1.8\n") puts(f1,"\tphotons {\n\t\tcount 100000\n") puts(f1,"\t\tautostop 0.5\n\t\tjitter 1.0\n") puts(f1,"\t\texpand_thresholds 0.2, 40\n\tmax_trace_level 20\n") puts(f1,"\t}\n") puts(f1,"}\n") puts(f1,"#declare sky_vect = z;\n") puts(f1,"#declare cam_loc = <-52,0,-90>;\n") puts(f1,"#declare lookat = <0,0,0>;\n") puts(f1," camera {\n location cam_loc\n look_at lookat\n angle 90\n }\n") puts(f1," light_source { <0, 0, -50> White }\n") puts(f1," light_source { <0, -50, 0> White }\n") puts(f1," light_source { <-50, 0, 0> Green }\n") for i=1 to Nbre_Syst do printf(f1,"// Systme: %d\n",i) --rayon=(rand(10)+5)/10 rayon = 0.9 --printf(1,"#declare flare_brightness = <%1.2f, %1.2f, %1.2f>;\n", -- { (abs(coord[i][X])/20), abs(coord[i][Y]/30), abs(coord[i][Z]/30)}) --printf(1,"#declare light_loc = <%3.2f, %3.2f, %3.2f>;\n", -- { coord[i][X], coord[i][Y], coord[i][Z]}) --puts(1,"#include \"smlstar.flr\"\n") --puts(1,"#include \"nkflare.inc\"\n") printf(f1,"sphere{<%3.2f, %3.2f, %3.2f> %1.2f\n ",{ coord[i][X], coord[i][Y], coord[i][Z], rayon}) printf(f1," pigment{ color red %1.2f green %1.2f blue %1.2f}\n", { abs(coord[i][X]/20), abs(coord[i][Y]/20), abs(coord[i][Z]/20)}) puts(f1," finish {diffuse 0.8 brilliance 0.9 metallic 0.9}\n}\n") for ii=1 to coord[i][P] do -- rayon=rand(6)/10 rayon = 0.23 printf(f1,"// Plante: %d\n",ii) printf(f1,"sphere{<%3.2f, %3.2f, %3.2f> %1.2f \n", {planets[i][ii][X], planets[i][ii][Y], planets[i][ii][Z], rayon}) printf(f1," pigment{ color red %1.2f green %1.2f blue %1.2f}\n}\n", { abs(planets[i][ii][X]/20), abs(planets[i][ii][Y]/20), abs(planets[i][ii][Z]/20)}) end for puts(f1,"\n//===================================\n") end for close(f1) end procedure -- fichier *.pov ------------------------------------------- -- criture dans un fichier format texte -- ------------------------------------------- procedure fichierTexte() nomfichier="Nkyogn_" & numerofichier & ".txt" f1=open(nomfichier,"w") for i=1 to Nbre_Syst do printf(f1,"Systme %d :\n============\n%3.2f, %3.2f, %3.2f\n", {i, coord[i][X], coord[i][Y], coord[i][Z]}) printf(f1,"Nbre plantes: %d\n", coord[i][P]) for ii=1 to coord[i][P] do printf(f1,">%d : %3.2f, %3.2f, %3.2f\n", {ii, planets[i][ii][X], planets[i][ii][Y], planets[i][ii][Z]}) end for puts(f1,"\n") end for printf(f1,"=====================================\nTotal: %d plantes",{scale}) close(f1) end procedure -- fichier *.txt ----------------------------------------------------- ------------------------------------------ -- criture dans un fichier format *.ex -- ------------------------------------------ ----------------------------------------------------- procedure fichierEx() nomfichier="Nkyogn_" & numerofichier & ".ex" f1=open(nomfichier,"w") puts(f1,"constant systeme={\n") for i=1 to Nbre_Syst do printf(f1,"-- toile n %d --\n",{i}) printf(f1,"{%3.2f, %3.2f, %3.2f},\n",{coord[i][X], coord[i][Y], coord[i][Z]}) for ii=1 to coord[i][P] do printf(f1,"-- plante n %d --\n",{ii}) printf(f1,"{%3.2f, %3.2f, %3.2f},\n",{planets[i][ii][X], planets[i][ii][Y], planets[i][ii][Z]}) end for puts(f1,"\n") end for puts(f1,"}\n") close(f1) end procedure -- fichier *.ex ----------------------------------------------------- ----------------------------------------- -- criture dans un fichier format *.c -- ----------------------------------------- ----------------------------------------------------- procedure fichierC() nomfichier="Nkyogn_" & numerofichier & ".c" f1=open(nomfichier,"w") puts(f1,"/* NKYO Galaxie */\n") puts(f1,"void XGalaxie(void)\n {\n") puts(f1," int NA; // NA = Nombre d'Astres \n") puts(f1," NA=33;\n") for i=1 to Nbre_Syst do printf(f1," Vertex[%d].x = %3.2f; Vertex[%d].y = %3.2f; Vertex[%d].z = %3.2f;\n", {i, coord[i][X], i, coord[i][Y], i, coord[i][Z]}) end for puts(f1,"}\n\n\n") puts(f1,"\t\t/***======================***/\n") puts(f1,"\t\t/* NKYO Systmes Solaires */\n") puts(f1,"\t\t/***----------------------***/\n\n") for i=1 to Nbre_Syst do puts(f1,"/**-======================-**/\n") printf(f1,"/* Systme numro: %2d */\n",{i}) puts(f1,"/**-======================-**/\n") printf(f1,"void XSyst%d(void)\n {\n",{i}) puts(f1," int NA; // NA = Nombre d'Astres \n") printf(f1," NA=%d;\n",{coord[i][P]+1}) printf(f1," Vertex[%d].x = %3.2f; Vertex[%d].y = %3.2f; Vertex[%d].z = %3.2f;\n", {1, coord[i][X], 1, coord[i][Y], 1, coord[i][Z]}) for ii=1 to coord[i][P] do printf(f1," Vertex[%d].x = %3.2f; Vertex[%d].y = %3.2f; Vertex[%d].z = %3.2f;\n", { ii+1, planets[i][ii][X], ii+1, planets[i][ii][Y], ii+1, planets[i][ii][Z]}) end for puts(f1,"}\n") puts(f1,"\n") end for close(f1) end procedure --fichier *.c ----------------------------------------------------- ----------------------------------------------------- ----------------------------------------------------- procedure ecran() clear_screen() banner() text_color(CadreColor) position(7,8) puts(1,"ͻ") for i=8 to 15 do position(i,8) puts(1,"ͺ") end for position(16,8) puts(1,"ͼ") text_color(12) --RedOrange for i=0 to 5 do position(10+i,9) printf(1," %d - ",{i}) end for text_color(14) --Yellow position (10,14) puts(1,"Quitter Coords.Ex ") position (11,14) puts(1,"Nouvelle Gnration ") position (12,14) puts(1,"Fichier format Texte ") position (13,14) puts(1,"Fichier format *.ex ") position (14,14) puts(1,"Fichier format *.c ") position (15,14) puts(1,"Fichier format *.POV ") end procedure ----------------------------------------------------- ----------------------------------------------------- ----------------------------------------------------- procedure openfile(sequence extension) integer file_no, fn file_no = 0 for i = 'a' to 'z' do fn = open("gener_" & i & extension, "rb") if fn = -1 then file_no = i exit else close(fn) end if end for if file_no then numerofichier=file_no end if end procedure ----------------------------------------------------- ----------------------------------------------------- -- principal ----------------------------------------------------- atom sortie, ok, tiragefait tiragefait=0 ok=0 sortie=-1 tirage() ecran() trace(1) while sortie=-1 do sortie=get_key() if sortie='1' then tirage() ok=1 end if if sortie='2' then ok=1 openfile(".txt") fichierTexte() end if if sortie='3' then ok=1 openfile(".ex") fichierEx() end if if sortie='4' then ok=1 openfile(".c") fichierC() end if if sortie='5' then ok=1 openfile(".pov") fichierPov() end if if sortie='0' then exit end if if ok=1 then ecran() ok=0 end if sortie=-1 end while --include graphics.e procedure fin() --fin while get_key()=-1 do end while if graphics_mode(-1) then end if abort(0) end procedure procedure tst_vdo() if graphics_mode(257)=0 then puts(1,"Ok pour la carte vido") else puts(1,"Mauvaise Carte, dsol") fin() end if end procedure