Source PostScript (newcube.pps)

Retour Texte non formaté
/newcube { 3 dict begin [[/n] [1] [1] [1] [3] [4]] gestionsolidmode /a exch 2 div def n 1 le { /F [ [0 1 2 3] [0 4 5 1] [1 5 6 2] [2 6 7 3] [0 3 7 4] [4 7 6 5] ] def %% tableau des sommets /S [ 1 1 1 %% 0 -1 1 1 %% 1 -1 -1 1 %% 2 1 -1 1 %% 3 1 1 -1 %% 4 -1 1 -1 %% 5 -1 -1 -1 %% 6 1 -1 -1 %% 7 ] {a mulv3d} papply3d def S F generesolid } { /dl 2 n div def /N n dup mul n add 4 mul def /n1 n 1 sub dup mul def %% nb sommets centre d une face %% tableau des sommets /S1 [ 0 1 n 1 sub { /j exch def 0 1 n { /i exch def -1 i dl mul add -1 j dl mul add 1 } for } for ] def /S2 S1 {-90 0 0 rotateOpoint3d} papply3d def /S3 S2 {-90 0 0 rotateOpoint3d} papply3d def /S4 S3 {-90 0 0 rotateOpoint3d} papply3d def /S5 [ 1 1 n 1 sub { /j exch def 1 1 n 1 sub { /i exch def 1 -1 i dl mul add -1 j dl mul add } for } for ] def /S6 [ 1 1 n 1 sub { /j exch def 1 1 n 1 sub { /i exch def -1 -1 i dl mul add -1 j dl mul add } for } for ] def %% tableau des faces /F1 [ 0 1 n 1 sub { /j exch def 0 1 n 1 sub { /i exch def [ i n 1 add j mul add dup 1 add dup n 1 add add dup 1 sub ] } for } for ] def %% syntaxe : i sommettourgauche --> l indice du i-eme sommet du tour %% de la face gauche (en commencant par l indice 0). ATTENTION : %% utilise la variable globale n = nb d etages /sommettourgauche { 1 dict begin /i exch def i 4 n mul ge { i (Error: indice trop grand dans sommettourgauche) == exit } if n n 1 add i mul add end } def %% syntaxe : i sommetcentregauche --> l indice du i-eme sommet du centre %% de la face gauche (en commencant par l indice 0). ATTENTION : %% utilise les variables globales n = nb d etages, et N = nb sommets %% des 4 1eres faces /sommetcentregauche { 1 dict begin /i exch def i n 1 sub dup mul ge { i (Error: indice trop grand dans sommetcentregauche) == exit } if N i add end } def /F5 [ %%%%% la face gauche %%%%% %% le coin superieur gauche [ 1 sommettourgauche 0 sommettourgauche n 4 mul 1 sub sommettourgauche n1 n 1 sub sub sommetcentregauche ] %% la bande superieure (i from 1 to n-2) 1 1 n 2 sub { /i exch def [ i 1 add sommettourgauche i sommettourgauche n1 n sub i add sommetcentregauche n1 n sub i 1 add add sommetcentregauche ] } for %% le coin superieur droit [ n sommettourgauche n 1 sub sommettourgauche n1 1 sub sommetcentregauche n 1 add sommettourgauche ] %% la descente gauche %% j from 1 to n-2 1 1 n 2 sub { /j exch def [ n1 n 1 sub j mul sub sommetcentregauche n 4 mul j sub sommettourgauche n 4 mul j 1 add sub sommettourgauche n1 n 1 sub j 1 add mul sub sommetcentregauche ] } for %% les bandes centrales (j from 1 to n-2 et i from 1 to n-2) 1 1 n 2 sub { /j exch def 1 1 n 2 sub { /i exch def [ n1 i n 1 sub j 1 sub mul add sub sommetcentregauche n1 i 1 add n 1 sub j 1 sub mul add sub sommetcentregauche n1 i 1 add n 1 sub j mul add sub sommetcentregauche n1 i n 1 sub j mul add sub sommetcentregauche ] } for } for %% la descente droite 1 1 n 2 sub { /j exch def [ n j add sommettourgauche n1 1 sub j 1 sub n 1 sub mul sub sommetcentregauche n1 1 sub j n 1 sub mul sub sommetcentregauche n j 1 add add sommettourgauche ] } for %% le coin inferieur gauche [ 0 sommetcentregauche n 3 mul 1 add sommettourgauche n 3 mul sommettourgauche n 3 mul 1 sub sommettourgauche ] %% la bande inferieure (i from 1 to n-2) 1 1 n 2 sub { /i exch def [ i sommetcentregauche i 1 sub sommetcentregauche n 3 mul i sub sommettourgauche n 3 mul i sub 1 sub sommettourgauche ] } for %% le coin inferieur droit [ n 2 mul 1 sub sommettourgauche n 2 sub sommetcentregauche n 2 mul 1 add sommettourgauche n 2 mul sommettourgauche ] ] def %% syntaxe : i sommettourdroit --> l indice du i-eme sommet du tour %% de la face droit (en commencant par l indice 0). ATTENTION : %% utilise la variable globale n = nb d etages /sommettourdroit { 1 dict begin /i exch def i 4 n mul ge { i (Error: indice trop grand dans sommettourdroit) == exit } if n 1 add i mul end } def %% syntaxe : i sommetcentredroit --> l indice du i-eme sommet du centre %% de la face droit (en commencant par l indice 0). ATTENTION : %% utilise les variables globales n = nb d etages, et N = nb sommets %% des 4 1eres faces /sommetcentredroit { 1 dict begin /i exch def i n 1 sub dup mul ge { i (Error: indice trop grand dans sommetcentredroit) == exit } if N n1 add i add end } def /F6 [ %% coin superieur droit [ 0 sommettourdroit 1 sommettourdroit n1 n 1 sub sub sommetcentredroit 4 n mul 1 sub sommettourdroit ] %% coin superieur gauche [ n 1 sub sommettourdroit n sommettourdroit n 1 add sommettourdroit n1 1 sub sommetcentredroit ] %% coin inferieur gauche [ n 2 sub sommetcentredroit 2 n mul 1 sub sommettourdroit 2 n mul sommettourdroit 2 n mul 1 add sommettourdroit ] %% coin inferieur droit [ 3 n mul 1 add sommettourdroit 0 sommetcentredroit 3 n mul 1 sub sommettourdroit 3 n mul sommettourdroit ] %% bande superieure 1 1 n 2 sub { /i exch def [ i sommettourdroit i 1 add sommettourdroit n 1 sub n 2 sub mul i add sommetcentredroit n 1 sub n 2 sub mul i 1 sub add sommetcentredroit ] } for %% bande inferieure 1 1 n 2 sub { /i exch def [ i 1 sub sommetcentredroit i sommetcentredroit 3 n mul 1 sub i sub sommettourdroit 3 n mul i sub sommettourdroit ] } for %% descente gauche 1 1 n 2 sub { /i exch def [ n1 1 sub i 1 sub n 1 sub mul sub sommetcentredroit n i add sommettourdroit n i 1 add add sommettourdroit n1 1 sub i n 1 sub mul sub sommetcentredroit ] } for %% descente droite 1 1 n 2 sub { /i exch def [ 4 n mul i sub sommettourdroit n 1 sub n 1 sub i sub mul sommetcentredroit n 1 sub n 2 sub i sub mul sommetcentredroit 4 n mul i sub 1 sub sommettourdroit ] } for %% bandes interieures 1 1 n 2 sub { /j exch def 1 1 n 2 sub { /i exch def [ n 1 sub j mul i 1 sub add sommetcentredroit n 1 sub j mul i add sommetcentredroit n 1 sub j 1 sub mul i add sommetcentredroit n 1 sub j 1 sub mul i 1 sub add sommetcentredroit ] } for } for ] def /F2 F1 {{n dup mul n add add} apply} apply def /F3 F2 {{n dup mul n add add} apply} apply def /F4 F3 {{n dup mul n add add} apply} apply def S1 S2 append S3 append S4 append S5 append S6 append {a mulv3d} papply3d F1 F2 append F3 append F4 append {{N mod} apply} apply F5 append F6 append generesolid } ifelse end } def