多角形

 投稿者:しばっち  投稿日:2017年10月29日(日)14時50分54秒
 
正多角形

CALL GINIT(600,600)
OPTION ANGLE DEGREES
SET LINE COLOR 7
INPUT  PROMPT "何角形 =":N
LET A=360/N
FOR T=0 TO 360
   LET X=200*COS(T)*COS(A/2)/COS(A*(T/A-IP(T/A))-A/2)
   LET Y=200*SIN(T)*COS(A/2)/COS(A*(T/A-IP(T/A))-A/2)
   PLOT LINES:X+300,Y+300;
NEXT T
END

EXTERNAL SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
SET WINDOW 0,XSIZE-1,YSIZE-1,0
SET POINT STYLE 1
SET COLOR MODE "REGULAR"
SET COLOR MIX(0) 0,0,0
SET COLOR MIX(1) 0,0,1
SET COLOR MIX(2) 1,0,0
SET COLOR MIX(3) 1,0,1
SET COLOR MIX(4) 0,1,0
SET COLOR MIX(5) 0,1,1
SET COLOR MIX(6) 1,1,0
SET COLOR MIX(7) 1,1,1
CLEAR
END SUB

------------------------------------------------------------------------------
星型多角形

CALL GINIT(600,600)
OPTION ANGLE DEGREES
SET LINE COLOR 7
INPUT N !'N>=5
LET A=360/N
FOR T=0 TO 360
   LET X=200*COS(T)*COS(A)/COS(A-1/N*ACOS(COS(N*T)))
   LET Y=200*SIN(T)*COS(A)/COS(A-1/N*ACOS(COS(N*T)))
   PLOT LINES:X+300,Y+300;
NEXT T
END

EXTERNAL SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
SET WINDOW 0,XSIZE-1,YSIZE-1,0
SET POINT STYLE 1
SET COLOR MODE "REGULAR"
SET COLOR MIX(0) 0,0,0
SET COLOR MIX(1) 0,0,1
SET COLOR MIX(2) 1,0,0
SET COLOR MIX(3) 1,0,1
SET COLOR MIX(4) 0,1,0
SET COLOR MIX(5) 0,1,1
SET COLOR MIX(6) 1,1,0
SET COLOR MIX(7) 1,1,1
CLEAR
END SUB
 

多角形

 投稿者:しばっち  投稿日:2017年10月29日(日)14時54分21秒
  OPTION ARITHMETIC NATIVE
RANDOMIZE
OPTION ANGLE DEGREES
LET ZTH=0          ! z軸のまわりの回転角
LET XTH=0          ! x軸のまわりの回転角初期値
LET YTH=0          ! y軸のまわりの回転角初期値
LET N=30
DIM M(4,4),POINT(4),ROTX(4,4),ROTY(4,4)
DIM XX(0 TO N,0 TO N),YY(0 TO N,0 TO N),ZZ(0 TO N,0 TO N)
MAT M=ROTATE(ZTH)
SET POINT STYLE 1
DEF A(N)=360/N
DEF S1(X)=FP(X)
DEF CNP(N,T)=COS(A(N)*S1(T/A(N))-A(N)/2)
DEF PC(N,T)=COS(T)*COS(A(N)/2)/CNP(N,T)
DEF PS(N,T)=SIN(T)*COS(A(N)/2)/CNP(N,T)
DEF P3X(N,U,V)=PS(N,U)*PC(N,V)
DEF P3Y(N,U,V)=PS(N,U)*PS(N,V)
DEF P3Z(N,U)=PC(N,U)
INPUT  PROMPT "何角形 =":NN
FOR I=0 TO N
   FOR J=0 TO N
      LET ALPHA=I*180/N
      LET BETA=J*360/N
      LET XX(I,J)=P3X(NN,ALPHA,BETA)
      LET YY(I,J)=P3Y(NN,ALPHA,BETA)
      LET ZZ(I,J)=P3Z(NN,ALPHA)
      LET XMIN=MIN(XMIN,XX(I,J))
      LET XMAX=MAX(XMAX,XX(I,J))
      LET YMIN=MIN(YMIN,YY(I,J))
      LET YMAX=MAX(YMAX,YY(I,J))
      LET ZMIN=MIN(ZMIN,ZZ(I,J))
      LET ZMAX=MAX(ZMAX,ZZ(I,J))
   NEXT J
NEXT I
LET RANGE=MAX(XMAX-XMIN,MAX(YMAX-YMIN,ZMAX-ZMIN))
LET XDT=RND-.5
LET YDT=RND-.5
LET LMIN=1E+10
LET LMAX=-1E+10
LOCATE VALUE NOWAIT(1),RANGE 0 TO 2,AT 1:SCALE
LOCATE VALUE NOWAIT(2),RANGE-3 TO 5,AT 1:SPEED
LOCATE VALUE NOWAIT(3),RANGE-RANGE TO RANGE,AT 0:XMOVE
LOCATE VALUE NOWAIT(4),RANGE-RANGE TO RANGE,AT 0:YMOVE
LOCATE VALUE NOWAIT(5),RANGE-RANGE TO RANGE,AT 0:ZMOVE
DO
   LOCATE VALUE NOWAIT(1):SCALE
   LOCATE VALUE NOWAIT(2):SPEED
   LOCATE VALUE NOWAIT(3):XMOVE
   LOCATE VALUE NOWAIT(4):YMOVE
   LOCATE VALUE NOWAIT(5):ZMOVE
   MAT ROTX=IDN ! x軸のまわりの回転
   LET ROTX(2,2)=COS(XTH)
   LET ROTX(2,3)=SIN(XTH)
   LET ROTX(3,2)=-SIN(XTH)
   LET ROTX(3,3)=COS(XTH)
   MAT ROTY=IDN ! y軸のまわりの回転
   LET ROTY(1,1)=COS(YTH)
   LET ROTY(1,3)=-SIN(YTH)
   LET ROTY(3,1)=SIN(YTH)
   LET ROTY(3,3)=COS(YTH)
   MAT M=M*ROTX*ROTY
   SET DRAW MODE HIDDEN
   CLEAR
   FOR I=0 TO N
      FOR J=0 TO N
         CALL PLOT(XX(I,J),YY(I,J),ZZ(I,J))
      NEXT J
      PLOT LINES
   NEXT I
   FOR J=0 TO N
      FOR I=0 TO N
         CALL PLOT(XX(I,J),YY(I,J),ZZ(I,J))
      NEXT I
      PLOT LINES
   NEXT J
   IF FL=0 THEN
      SET WINDOW LMIN*1.2,LMAX*1.2,LMIN*1.2,LMAX*1.2
      LET WW=(LAMX-LMIN)*1.2
   END IF
   LET FL=1
   SET DRAW MODE EXPLICIT
   MOUSE POLL X,Y,L,R
   IF R<>0 THEN STOP
   LET XTH=0
   LET YTH=0
   IF L<>0 THEN
      DO WHILE L<>0 !'マウスでドラッグ
         MOUSE POLL X,Y,L,R
      LOOP
      LET XDT=-(Y-Y0)/WW*5
      LET YDT=(X-X0)/WW*5
      LET XDT=MAX(-5,MIN(5,XDT))
      LET YDT=MAX(-5,MIN(5,YDT))
   ELSE
      LET XTH=XTH+XDT*SPEED
      LET YTH=YTH+YDT*SPEED
   END IF
   LET X0=X
   LET Y0=Y
LOOP

SUB PLOT(X,Y,Z)
   LET POINT(1)=X+XMOVE
   LET POINT(2)=Y+YMOVE
   LET POINT(3)=Z+ZMOVE
   MAT POINT=POINT*M
   IF FL=0 THEN
      LET LMIN=MIN(LMIN,POINT(1))
      LET LMAX=MAX(LMAX,POINT(1))
      LET LMIN=MIN(LMIN,POINT(2))
      LET LMAX=MAX(LMAX,POINT(2))
   ELSE
      PLOT LINES:POINT(1)*SCALE,POINT(2)*SCALE;
   END IF
END SUB
END
 
 

戻る