1点透視

 投稿者:しばっち  投稿日:2017年 2月11日(土)18時33分7秒
  立方体を1点透視で表示します

OPTION ARITHMETIC NATIVE
OPTION ANGLE DEGREES
SET POINT STYLE 1
LET LMIN=1E+10
LET LMAX=-1E+10
LET L=100
LOCATE VALUE NOWAIT(1),RANGE 1 TO 500,AT 100:K !'視点(0,0,K)
LOCATE VALUE NOWAIT(2),RANGE -500 TO 500,AT 0:XMOVE
LOCATE VALUE NOWAIT(3),RANGE -500 TO 500,AT 0:YMOVE
LOCATE VALUE NOWAIT(4),RANGE -500 TO -1,AT -1:ZMOVE
DO
   LOCATE VALUE NOWAIT(1):K
   LOCATE VALUE NOWAIT(2):XMOVE
   LOCATE VALUE NOWAIT(3):YMOVE
   LOCATE VALUE NOWAIT(4):ZMOVE
   SET DRAW MODE HIDDEN
   CLEAR
   CALL CUBE(XMOVE,YMOVE,ZMOVE,L)
   IF FL=0 THEN
      SET WINDOW LMIN*2,LMAX*2,LMIN*2,LMAX*2
   END IF
   LET FL=1
   SET DRAW MODE EXPLICIT
LOOP

SUB PLOT(X,Y,Z)
   LET XX=X/(1-Z/K)
   LET YY=Y/(1-Z/K)
   IF FL=0 THEN
      LET LMIN=MIN(LMIN,XX)
      LET LMAX=MAX(LMAX,XX)
      LET LMIN=MIN(LMIN,YY)
      LET LMAX=MAX(LMAX,YY)
   ELSE
      PLOT LINES:XX,YY;
   END IF
END SUB

SUB PLOTLINE(X1,Y1,Z1,X2,Y2,Z2)
   PLOT LINES
   CALL PLOT(X1,Y1,Z1)
   CALL PLOT(X2,Y2,Z2)
   PLOT LINES
END SUB

SUB CUBE(X,Y,Z,L)
   CALL PLOT(X-L/2,Y+L/2,Z-L/2)
   CALL PLOT(X+L/2,Y+L/2,Z-L/2)
   CALL PLOT(X+L/2,Y+L/2,Z+L/2)
   CALL PLOT(X-L/2,Y+L/2,Z+L/2)
   CALL PLOT(X-L/2,Y+L/2,Z-L/2)
   PLOT LINES
   CALL PLOT(X-L/2,Y-L/2,Z-L/2)
   CALL PLOT(X+L/2,Y-L/2,Z-L/2)
   CALL PLOT(X+L/2,Y-L/2,Z+L/2)
   CALL PLOT(X-L/2,Y-L/2,Z+L/2)
   CALL PLOT(X-L/2,Y-L/2,Z-L/2)
   PLOT LINES
   CALL PLOTLINE(X-L/2,Y+L/2,Z-L/2,X-L/2,Y-L/2,Z-L/2)
   CALL PLOTLINE(X+L/2,Y+L/2,Z-L/2,X+L/2,Y-L/2,Z-L/2)
   CALL PLOTLINE(X+L/2,Y+L/2,Z+L/2,X+L/2,Y-L/2,Z+L/2)
   CALL PLOTLINE(X-L/2,Y+L/2,Z+L/2,X-L/2,Y-L/2,Z+L/2)
END SUB
END

 

戻る