|
グラデーションライン
単色ではなく、グラデーションをかけながら
直線を引く
直線の場合
始点(XS,YS)から終点(XE,YE)までを
線形補間式により求め、同時にR,G,B値についても
高次補間式(3次)により求めプロットしていく。
SET COLOR MODE "NATIVE"
RANDOMIZE
SET LINE WIDTH 30
DIM R(5),G(5),B(5)
FOR I=1 TO 19
FOR J=1 TO 5
LET R(J)=INT(RND*255)
LET G(J)=INT(RND*255)
LET B(J)=INT(RND*255)
NEXT J
LET XS=.1
LET XE=.9
LET YS=YS+1/20
LET YE=YS+1/20
CALL LINE(XS,YS,XE,YE,R,G,B)
NEXT I
END
EXTERNAL SUB LINE(XS,YS,XE,YE,R(),G(),B())
FOR T=0 TO 1 STEP 1/128
LET RR=Y3(T,R)
LET GG=Y3(T,G)
LET BB=Y3(T,B)
LET RR=MAX(0,MIN(INT(RR),255))
LET GG=MAX(0,MIN(INT(GG),255))
LET BB=MAX(0,MIN(INT(BB),255))
SET LINE COLOR 65536*BB+256*GG+RR
LET X=XE*T+(1-T)*XS
LET Y=YE*T+(1-T)*YS
PLOT LINES:X,Y;
NEXT T
PLOT LINES
END SUB
EXTERNAL FUNCTION Y1(T,X()) !'1次補間式
LET A=-X(1)+X(2) !'T=0...X(1)
LET B=X(1) !'T=1...X(2)
LET Y1=A*T+B
END FUNCTION
EXTERNAL FUNCTION Y2(T,X()) !'2次補間式
!' C=X(1)
!'1/4*A+1/2*B+C=X(2)
!' A+ B+C=X(3)
LET A=2*X(1)-4*X(2)+2*X(3) !'T=0/2...X(1)
LET B=-3*X(1)+4*X(2)-X(3) !'T=1/2...X(2)
LET C=X(1) !'T=2/2...X(3)
LET Y2=A*T^2+B*T+C
END FUNCTION
EXTERNAL FUNCTION Y3(T,X()) !'3次補間式
!' D=X(1)
!'1/27*A+1/9*B+1/3*C+D=X(2)
!'8/27*A+4/9*B+2/3*C+D=X(3)
!' A+ B+ C+D=X(4)
LET A=-9/2*X(1)+27/2*X(2)-27/2*X(3)+9/2*X(4) !'T=0/3...X(1)
LET B=9*X(1)-45/2*X(2)+18*X(3)-9/2*X(4) !'T=1/3...X(2)
LET C=-11/2*X(1)+9*X(2)-9/2*X(3)+X(4) !'T=2/3...X(3)
LET D=X(1) !'T=3/3...X(4)
LET Y3=A*T^3+B*T^2+C*T+D
END FUNCTION
EXTERNAL FUNCTION Y4(T,X()) !'4次補間式
!' E=X(1)
!' 1/256*A+ 1/64*B+1/16*C+1/4*D+E=X(2)
!'16/256*A+ 8/64*B+4/16*C+2/4*D+E=X(3)
!'81/256*A+27/64*B+9/16*C+3/4*D+E=X(4)
!' A+ B+ C+ D+E=X(5)
LET A=32/3*X(1)-128/3*X(2)+64*X(3)-128/3*X(4)+32/3*X(5) !'T=0/4...X(1)
LET B=-80/3*X(1)+96*X(2)-128*X(3)+224/3*X(4)-16*X(5) !'T=1/4...X(2)
LET C=70/3*X(1)-208/3*X(2)+76*X(3)-112/3*X(4)+22/3*X(5) !'T=2/4...X(3)
LET D=-25/3*X(1)+16*X(2)-12*X(3)+16/3*X(4)-X(5) !'T=3/4...X(4)
LET E=X(1) !'T=4/4...X(5)
LET Y4=A*T^4+B*T^3+C*T^2+D*T+E
END FUNCTION
------------------------------------------------------
曲線の場合
SET COLOR MODE "NATIVE"
RANDOMIZE
SET LINE WIDTH 30
LET N=INT(RND*3)+3
DIM R(N),G(N),B(N),X(N),Y(N)
FOR J=1 TO N
LET R(J)=INT(RND*255)
LET G(J)=INT(RND*255)
LET B(J)=INT(RND*255)
LET X(J)=RND
LET Y(J)=RND
NEXT J
CALL LINE(N,X,Y,R,G,B)
END
EXTERNAL FUNCTION LARGRANGE(X(),Y(),N,T) !'ラグランジュ補間
FOR I=1 TO N
LET R=Y(I)
FOR J=1 TO N
IF J<>I THEN LET R=R*(T-X(J))/(X(I)-X(J))
NEXT J
LET S=S+R
NEXT I
LET LARGRANGE=S
END FUNCTION
EXTERNAL SUB LINE(N,X(),Y(),R(),G(),B())
DIM TT(N)
FOR I=1 TO N
LET TT(I)=(I-1)/(N-1)
NEXT I
FOR T=0 TO 1 STEP 1/128
LET RR=LARGRANGE(TT,R,N,T)
LET GG=LARGRANGE(TT,G,N,T)
LET BB=LARGRANGE(TT,B,N,T)
LET XX=LARGRANGE(TT,X,N,T)
LET YY=LARGRANGE(TT,Y,N,T)
LET RR=MAX(0,MIN(INT(RR),255))
LET GG=MAX(0,MIN(INT(GG),255))
LET BB=MAX(0,MIN(INT(BB),255))
SET LINE COLOR 65536*BB+256*GG+RR
PLOT LINES:XX,YY;
NEXT T
PLOT LINES
END SUB
------------------------------------------------------
円の場合
SET COLOR MODE "NATIVE"
RANDOMIZE
SET LINE WIDTH 10
DIM R(10),G(10),B(10)
SET WINDOW -1,1,-1,1
FOR RR=.1 TO 1 STEP 1/10
LET N=INT(RND*4)+3
FOR J=1 TO N-1
LET R(J)=INT(RND*255)
LET G(J)=INT(RND*255)
LET B(J)=INT(RND*255)
NEXT J
LET R(N)=R(1)
LET G(N)=G(1)
LET B(N)=B(1)
CALL CIRCLE(N,0,0,RR,R,G,B)
NEXT RR
END
EXTERNAL FUNCTION LARGRANGE(X(),Y(),N,T)
FOR I=1 TO N
LET R=Y(I)
FOR J=1 TO N
IF J<>I THEN LET R=R*(T-X(J))/(X(I)-X(J))
NEXT J
LET S=S+R
NEXT I
LET LARGRANGE=S
END FUNCTION
EXTERNAL SUB CIRCLE(N,XX,YY,R0,R(),G(),B())
DIM TT(N)
FOR I=1 TO N
LET TT(I)=(I-1)/(N-1)
NEXT I
FOR T=0 TO 1 STEP 1/128
LET RR=LARGRANGE(TT,R,N,T)
LET GG=LARGRANGE(TT,G,N,T)
LET BB=LARGRANGE(TT,B,N,T)
LET RR=MAX(0,MIN(INT(RR),255))
LET GG=MAX(0,MIN(INT(GG),255))
LET BB=MAX(0,MIN(INT(BB),255))
SET LINE COLOR 65536*BB+256*GG+RR
PLOT LINES:XX+R0*COS(2*PI*T),YY+R0*SIN(2*PI*T);
NEXT T
PLOT LINES
END SUB
|
|