シェルピンスキー三角形
SUB RECURSIVE(LEV,X,Y,Z,L) IF LEV=0 THEN CALL SAVEOBJ(X,Y,Z,L) ELSE CALL RECURSIVE(LEV-1,X,Y+L,Z,L/2) CALL RECURSIVE(LEV-1,X+L*COS(0*PI/180),Y,Z+L*SIN(0*PI/180),L/2) CALL RECURSIVE(LEV-1,X+L*COS(120*PI/180),Y,Z+L*SIN(120*PI/180),L/2) CALL RECURSIVE(LEV-1,X+L*COS(240*PI/180),Y,Z+L*SIN(240*PI/180),L/2) END IF END SUB
SUB SAVEOBJ(X,Y,Z,L) LET K=K+1 PRINT #1:"Object ";CHR$(34);"obj";STR$(K);CHR$(34);" {" PRINT #1:CHR$(9);"depth 0" PRINT #1:CHR$(9);"folding 0" PRINT #1:CHR$(9);"scale 1.000000 1.000000 1.000000" PRINT #1:CHR$(9);"rotation 0.000000 0.000000 0.000000" PRINT #1:CHR$(9);"translation 0.000000 0.000000 0.000000" PRINT #1:CHR$(9);"visible 15" PRINT #1:CHR$(9);"locking 0" PRINT #1:CHR$(9);"shading 1" PRINT #1:CHR$(9);"facet 59.5" PRINT #1:CHR$(9);"color 0.898 0.498 0.698" PRINT #1:CHR$(9);"color_type 0" PRINT #1:CHR$(9);"vertex 4 {" PRINT #1:CHR$(9);FORM$(X);" ";FORM$(Y+L*2);" ";FORM$(Z) PRINT #1:CHR$(9);FORM$(X+L*2*COS(0*PI/180));" ";FORM$(Y);" ";FORM$(Z+L*2*SIN(0*PI/180)) PRINT #1:CHR$(9);FORM$(X+L*2*COS(120*PI/180));" ";FORM$(Y);" ";FORM$(Z+L*2*SIN(120*PI/180)) PRINT #1:CHR$(9);FORM$(X+L*2*COS(240*PI/180));" ";FORM$(Y);" ";FORM$(Z+L*2*SIN(240*PI/180)) PRINT #1:CHR$(9);"}" PRINT #1:CHR$(9);"face 4 {" PRINT #1:CHR$(9);CHR$(9);"3 V(0 1 2)" PRINT #1:CHR$(9);CHR$(9);"3 V(0 2 3)" PRINT #1:CHR$(9);CHR$(9);"3 V(0 3 1)" PRINT #1:CHR$(9);CHR$(9);"3 V(1 3 2)" PRINT #1:CHR$(9);"}" PRINT #1:"}" END SUB
LET L=200 INPUT PROMPT "SAVE FILENAME(.MQO)=":F$ INPUT PROMPT "LEVEL(1 - 7)=":LEV !'LET F$="シェルピンスキーガスケット" & STR$(LEV) IF POS(F$,".")=0 THEN LET F$=F$ & ".MQO" OPEN #1:NAME F$ PRINT #1:"Metasequoia Document" PRINT #1:"Format Text Ver 1.0" PRINT #1 PRINT #1:"Scene {" PRINT #1:CHR$(9);"pos 0.0000 0.0000 1500.0000" PRINT #1:CHR$(9);"lookat 0.0000 0.0000 0.0000" PRINT #1:CHR$(9);"head -0.5236" PRINT #1:CHR$(9);"pich 0.5236" PRINT #1:CHR$(9);"ortho 0" PRINT #1:CHR$(9);"zoom2 5.0000" PRINT #1:CHR$(9);"amb 0.250 0.250 0.250" PRINT #1:"}" CALL RECURSIVE(LEV,X,Y,Z,L) PRINT #1:"Eof" CLOSE #1 END
EXTERNAL FUNCTION FORM$(X) LET FORM$=LTRIM$(USING$("---%.####",X)) END FUNCTION
|