|
フラグメントシェーダー ハート
ハート型を定義しています。
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)
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)
!! MAT P=2*P
IF DISTANCE(P)<0 THEN
CALL VEC3(COL,1,0,0)
ELSE
CALL VEC3(COL,0,0,0)
END IF
CALL SETCOLOR(COL(1),COL(2),COL(3))
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL FUNCTION HEART(P()) !距離関数 ハート
DIM P1(2),P2(2),P3(2)
CALL VEC2(P1,.25,.75)
CALL VEC2(P2,0,1)
LET P(1)=ABS(P(1))
IF P(2)+P(1)>1 THEN
MAT P1=P-P1
LET HEART=SQR(DOT(P1,P1))-SQR(2)/4
ELSE
MAT P2=P-P2
FOR I=1 TO 2
LET P3(I)=P(I)-.5*MAX(P(1)+P(2),0)
NEXT I
LET HEART=SQR(MIN(DOT(P2,P2),DOT(P3,P3)))*SIGN(P(1)-P(2))
END IF
END FUNCTION
EXTERNAL FUNCTION DISTANCE(P())
DIM P1(2)
CALL VEC2(P1,0,-.5)
MAT P=P-P1
LET DISTANCE=HEART(P)
!!LET DISTANCE=(P(1)^2+P(2)^2-1)^3-P(1)^2*P(2)^3
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 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
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
|
|