|
フラグメントシェーダー 五角形
五角形を定義しています。
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)
IF DISTANCE(ST)>0 THEN
CALL VEC3(C,0,0,0)
ELSE
CALL VEC3(C,1,0,0)
END IF
CALL SETCOLOR(C(1),C(2),C(3))
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL FUNCTION PENTAGON(P(),R) !距離関数 五角形
DIM K(3),P1(2),P2(2),PP(2)
CALL VEC3(K,.809016994,.587785252,.726542528)
CALL VEC2(P1,-K(1),K(2))
CALL VEC2(P2,K(1),K(2))
LET P(1)=ABS(P(1))
MAT PP=P
FOR I=1 TO 2
LET P(I)=P(I)-2*MIN(DOT(P1,PP),0)*P1(I)
NEXT I
MAT PP=P
FOR I=1 TO 2
LET P(I)=P(I)-2*MIN(DOT(P2,PP),0)*P2(I)
NEXT I
CALL VEC2(P1,CLAMP(P(1),-R*K(3),R*K(3)),R)
MAT P=P-P1
LET PENTAGON=LENGTH(P)*SIGN(P(2))
END FUNCTION
EXTERNAL FUNCTION DISTANCE(P())
LET DISTANCE=PENTAGON(P,.5)
!!LET DISTANCE=ABS(PENTAGON(P,.5))-.1 !くり抜き
!!LET DISTANCE=2*ABS(P(2))+ABS(SQR(3)*P(1)-P(2))+ABS(SQR(3)*P(1)+P(2))-2*SQR(3) !6角形
END FUNCTION
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 LENGTH(A())
LET LENGTH=SQR(A(1)^2+A(2)^2)
END FUNCTION
EXTERNAL FUNCTION SIGN(X)
IF X<0 THEN
LET SIGN=-1
ELSEIF X>0 THEN
LET SIGN=1
ELSE
LET SIGN=0
END IF
END FUNCTION
|
|