せん断変換

 投稿者:しばっち  投稿日:2015年 5月30日(土)22時02分47秒
  !'せん断変換
FILE GETNAME F$,"BMP,JPG,GIF,PNGファイル|*.BMP;*.JPG;*.GIF;*.PNG"
CALL PICTURELOAD(F$,XSIZE,YSIZE)
DIM M(0 TO XSIZE-1,0 TO YSIZE-1)
ASK PIXEL ARRAY (0,0) M
INPUT  PROMPT "角度α(0 - 40)=":ALPHA
LET KX=TAN(RAD(ALPHA))
INPUT  PROMPT "角度β(0 - 40)=":BETA
LET KY=TAN(RAD(BETA))
LET XA=XSIZE-1+INT(KX*(YSIZE-1))
LET YA=YSIZE-1+INT(KY*(XSIZE-1))
CALL GINIT(XA,YA)
!'せん断変換
!' X'=X+KX*Y
!' Y'=Y+KY*X
!'逆変換
!' X=(X'-KX*Y')/(KX*KY-1)
!' Y=(X'*KY-Y')/(KX*KY-1)
FOR YS=0 TO YA-1
   LET Y=YS-YA/2
   FOR XS=0 TO XA-1
      LET X=XS-XA/2
      LET XX=(Y*KX-X)/(KX*KY-1)
      LET YY=(X*KY-Y)/(KX*KY-1)
      IF XX>=-XSIZE/2 AND XX<=XSIZE/2-1 AND YY>=-YSIZE/2 AND YY<=YSIZE/2-1 THEN
         LET C=M(INT(XX+XSIZE/2),INT(YY+YSIZE/2))
         CALL RGB(C,R,G,B)
         CALL PSET(X+XA/2,Y+YA/2,R,G,B)
      END IF
   NEXT XS
NEXT YS
END

EXTERNAL SUB RGB(X,R,G,B)
LET B=MOD(INT(X/65536),256)
LET G=MOD(INT(X/256),256)
LET R=MOD(X,256)
END SUB

EXTERNAL SUB GETPOINT(X,Y,R,G,B)
ASK PIXEL VALUE(X,Y) C
CALL RGB(C,R,G,B)
END SUB

EXTERNAL SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
SET COLOR MODE "NATIVE"
CLEAR
SET POINT STYLE 1
SET WINDOW 0,XSIZE-1,YSIZE-1,0
END SUB

EXTERNAL SUB PSET(X,Y,R,G,B)
SET COLOR COLORINDEX(R/255,G/255,B/255)
PLOT POINTS:X,Y
END SUB

EXTERNAL SUB PICTURELOAD(N$,XSIZE,YSIZE)
SET COLOR MODE "NATIVE"
CLEAR
SET POINT STYLE 1
IF N$="" THEN STOP
GLOAD N$
LET XSIZE=PIXELX(1)+1
LET YSIZE=PIXELY(1)+1
SET BITMAP SIZE XSIZE,YSIZE
SET WINDOW 0,XSIZE-1,YSIZE-1,0
END SUB
 

戻る