|
!'アフィン変換(回転変換)
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
LET XM=INT(XSIZE/2) !'回転中心
LET YM=INT(YSIZE/2)
INPUT PROMPT "回転角度=":TH
LET C=COS(RAD(TH))
LET S=SIN(RAD(TH))
LET XA=INT((0-XM)*C-(0-YM)*S+XM)
LET YA=INT((0-XM)*S+(0-YM)*C+YM)
LET XB=INT((0-XM)*C-(YSIZE-1-YM)*S+XM)
LET YB=INT((0-XM)*S+(YSIZE-1-YM)*C+YM)
LET XC=INT((XSIZE-1-XM)*C-(YSIZE-1-YM)*S+XM)
LET YC=INT((XSIZE-1-XM)*S+(YSIZE-1-YM)*C+YM)
LET XD=INT((XSIZE-1-XM)*C-(0-YM)*S+XM)
LET YD=INT((XSIZE-1-XM)*S+(0-YM)*C+YM)
LET XMIN=MIN(MIN(XA,XB),MIN(XC,XD))
LET YMIN=MIN(MIN(YA,YB),MIN(YC,YD))
LET XMAX=MAX(MAX(XA,XB),MAX(XC,XD))
LET YMAX=MAX(MAX(YA,YB),MAX(YC,YD))
CALL GINIT(XMAX-XMIN+1,YMAX-YMIN+1)
!' アフィン変換(回転変換)
!' X'=X*COS(T)-Y*SIN(T)
!' Y'=X*SIN(T)+Y*COS(T)
!' 逆変換
!' X=Y'*SIN(T)+X'*COS(T)
!' Y=Y'*COS(T)-X'*SIN(T)
FOR Y=YMIN TO YMAX
FOR X=XMIN TO XMAX
LET XA=(Y-YM)*SIN(RAD(TH))+(X-XM)*COS(RAD(TH))+XM
LET YA=(Y-YM)*COS(RAD(TH))-(X-XM)*SIN(RAD(TH))+YM
IF XA>=0 AND XA<=XSIZE-1 AND YA>=0 AND YA<=YSIZE-1 THEN
CALL RGB(M(INT(XA),INT(YA)),RR,GG,BB)
CALL PSET(X-XMIN,Y-YMIN,RR,GG,BB)
END IF
NEXT X
NEXT Y
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 GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
CLEAR
SET COLOR MODE "NATIVE"
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)
CLEAR
SET COLOR MODE "NATIVE"
SET POINT STYLE 1
GLOAD N$
LET XSIZE=PIXELX(1)
LET YSIZE=PIXELY(1)
SET BITMAP SIZE XSIZE,YSIZE
SET WINDOW 0,XSIZE-1,YSIZE-1,0
END SUB
|
|