メビウスの帯

 投稿者:しばっち  投稿日:2013年 9月 2日(月)20時00分1秒
  SAMPLEフォルダ内 Lorenz_attractor.BAS を改造してみた
マウスでドラッグすると回転の向きや速度が変化します
右クリックで終了します

RANDOMIZE
OPTION ARITHMETIC NATIVE
OPTION ANGLE DEGREES
LET ZTH=0          ! z軸のまわりの回転角
LET XTH=0          ! x軸のまわりの回転角初期値
LET YTH=0          ! y軸のまわりの回転角初期値
DIM M(4,4),POINT(4),ROTX(4,4),ROTY(4,4),X1(0 TO 360),Y1(0 TO 360),Z1(0 TO 360),X2(0 TO 360),Y2(0 TO 360),Z2(0 TO 360)
MAT M=ROTATE(ZTH)
SET POINT STYLE 1
LET LMIN=1E+10
LET LMAX=-1E+10
LET  A=INT(RND*7)+1
DO
   LET  B=INT(RND*7)+1
LOOP UNTIL A<>B
LET  R=INT(RND*10)+3
FOR I=0 TO 360
   LET ALPHA=I*2
   LET  X1(I)=(A+R*SIN(ALPHA/2))*COS(ALPHA)
   LET  Z1(I)=(A+R*SIN(ALPHA/2))*SIN(ALPHA)
   LET  Y1(I)=A+R*COS(ALPHA/2)
   LET  X2(I)=(B+R*SIN(ALPHA/2))*COS(ALPHA)
   LET  Z2(I)=(B+R*SIN(ALPHA/2))*SIN(ALPHA)
   LET  Y2(I)=B+R*COS(ALPHA/2)
   LET XMIN=MIN(XMIN,X1(I))
   LET XMAX=MAX(XMAX,X1(I))
   LET YMIN=MIN(YMIN,Y1(I))
   LET YMAX=MAX(YMAX,Y1(I))
   LET ZMIN=MIN(ZMIN,Z1(I))
   LET ZMAX=MAX(ZMAX,Z1(I))
   LET XMIN=MIN(XMIN,X2(I))
   LET XMAX=MAX(XMAX,X2(I))
   LET YMIN=MIN(YMIN,Y2(I))
   LET YMAX=MAX(YMAX,Y2(I))
   LET ZMIN=MIN(ZMIN,Z2(I))
   LET ZMAX=MAX(ZMAX,Z2(I))
NEXT I
FOR I=0 TO 359  !'重心計算
   LET MX=MX+X1(I)+X2(I)
   LET MY=MY+Y1(I)+Y2(I)
   LET MZ=MZ+Z1(I)+Z2(I)
NEXT I
LET RANGE=MAX(XMAX-XMIN,MAX(YMAX-YMIN,ZMAX-ZMIN))
LET XDT=RND-.5 !'回転初期値
LET YDT=RND-.5
LET MX=MX/360/2
LET MY=MY/360/2
LET MZ=MZ/360/2
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 359
      CALL PLOT(X1(I),Y1(I),Z1(I))
      CALL PLOT(X2(I),Y2(I),Z2(I))
      CALL PLOT(X2(I+1),Y2(I+1),Z2(I+1))
      CALL PLOT(X1(I+1),Y1(I+1),Z1(I+1))
      CALL PLOT(X1(I),Y1(I),Z1(I))
      PLOT LINES
   NEXT I
   IF FL=0 THEN
      SET WINDOW LMIN*1.5,LMAX*1.5,LMIN*1.5,LMAX*1.5
      LET WW=(LMAX-LMIN)*1.5
   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-MX+XMOVE
   LET POINT(2)=Y-MY+YMOVE
   LET POINT(3)=Z-MZ+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
 

戻る