|
フラグメントシェーダー 市松模様
市松模様を描いています。
https://junk-box.net/kuyo/index.php/2020/11/29/material_part1/
※「鬼滅の刃」竈門炭治郎のイメージ ?
DIM ST(2),C(3)
ASK BITMAP SIZE XSIZE,YSIZE
SET COLOR MODE "NATIVE"
SET POINT STYLE 1
SET WINDOW -XSIZE/MIN(XSIZE,YSIZE),XSIZE/MIN(XSIZE,YSIZE),-YSIZE/MIN(XSIZE,YSIZE),YSIZE/MIN(XSIZE,YSIZE)
FOR YY=0 TO YSIZE-1
FOR XX=0 TO XSIZE-1
LET X=(XX*2-XSIZE)/MIN(XSIZE,YSIZE)
LET Y=(YY*2-YSIZE)/MIN(XSIZE,YSIZE)
CALL VEC2(ST,X,Y)
!! CALL ROTATE(ST,RAD(25)) !注釈を外すと傾けることができます。
MAT ST=5*ST
FOR I=1 TO 2
LET ST(I)=FRACT(ST(I))
NEXT I
MAT ST=2*ST
LET INDEX=0
LET INDEX=INDEX+STEP(1,MOD(ST(1),2))
LET INDEX=INDEX+STEP(1,MOD(ST(2),2))*2
IF INDEX=1 OR INDEX=2 THEN
CALL VEC3(C,0,1,0)
ELSE
CALL VEC3(C,0,0,0)
END IF
CALL SETCOLOR(C(1),C(2),C(3))
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL SUB ROTATE(A(),T)
DIM M(2,2)
LET S=SIN(T)
LET C=COS(T)
LET M(1,1)=C
LET M(1,2)=S
LET M(2,1)=-S
LET M(2,2)=C
MAT A=A*M
END SUB
EXTERNAL SUB SETCOLOR(R,G,B)
SET COLOR COLORINDEX(CLAMP(R,0,1),CLAMP(G,0,1),CLAMP(B,0,1))
END SUB
EXTERNAL FUNCTION FRACT(X)
LET FRACT=X-INT(X)
END FUNCTION
EXTERNAL FUNCTION STEP(A,X)
IF X0 THEN
LET SIGN=1
ELSE
LET SIGN=0
END IF
END FUNCTION
-----------------------------------------------------------------------------------------------------------
円形にしてみた
DIM P(2),COL(3)
ASK BITMAP SIZE XSIZE,YSIZE
SET COLOR MODE "NATIVE"
SET POINT STYLE 1
SET WINDOW -XSIZE/MIN(XSIZE,YSIZE),XSIZE/MIN(XSIZE,YSIZE),-YSIZE/MIN(XSIZE,YSIZE),YSIZE/MIN(XSIZE,YSIZE)
LET N=20
LET SIZE=2/N
LET NN=2
FOR YY=0 TO YSIZE-1
FOR XX=0 TO XSIZE-1
LET X=(XX*2-XSIZE)/MIN(XSIZE,YSIZE)
LET Y=(YY*2-YSIZE)/MIN(XSIZE,YSIZE)
CALL VEC2(P,X,Y)
LET D=NLENGTH(P,NN)
IF X=0 AND Y=0 THEN LET TH=0 ELSE LET TH=ANGLE(X,Y)
LET D=INT(D/SIZE)
LET TH=INT(TH/SIZE/PI)
IF MOD(D+TH,2)=0 THEN
CALL VEC3(COL,0,0,0)
ELSE
CALL VEC3(COL,0,1,0)
END IF
CALL SETCOLOR(COL(1),COL(2),COL(3))
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL SUB SETCOLOR(R,G,B)
SET COLOR COLORINDEX(CLAMP(R,0,1),CLAMP(G,0,1),CLAMP(B,0,1))
END SUB
EXTERNAL SUB VEC2(A(),X,Y)
LET A(1)=X
LET A(2)=Y
END SUB
EXTERNAL SUB VEC3(A(),X,Y,Z)
LET A(1)=X
LET A(2)=Y
LET A(3)=Z
END SUB
EXTERNAL FUNCTION CLAMP(X,A,B)
LET CLAMP=MIN(B,MAX(X,A))
END FUNCTION
EXTERNAL FUNCTION NLENGTH(P(),N)
LET NLENGTH=(ABS(P(1))^N+ABS(P(2))^N)^(1/N)
END FUNCTION
|
|