en ce qui te concerne, sur la droite y'a 3 petits avions coloré de différentes manieres : blend, add, sub (il manque l’addition signée)
note :en déplaçant le scrollbar vertical a droite tu change la composante teinte
Code : Tout sélectionner
Procedure limite(v,min=0,max=255)
If v<min:v=min:EndIf
If v>max:v=max:EndIf
ProcedureReturn v
EndProcedure
Global Dim l255.a(256*3-1):For i=0 To 255:l255(i+256)=i:l255(i+512)=255:Next
Procedure ColorBlend(color1.l, color2.l, blend.f=0.5)
Protected r.w,g.w,b.w,a.w
r= Red(color1) + (Red(color2) - Red(color1)) * blend
g=Green(color1) + (Green(color2) - Green(color1)) * blend
b= Blue(color1) + (Blue(color2) - Blue(color1)) * blend
a=Alpha(color1) + (Alpha(color2) - Alpha(color1)) * blend
ProcedureReturn RGBA(r,g,b,a)
EndProcedure
Procedure ColorAdd(color1.l, color2.l, blend.f=1)
Protected r.w,g.w,b.w,a.w
r= Red(color1) + Red(color1) * blend
g=Green(color1) + Green(color1) * blend
b= Blue(color1) + Blue(color1) * blend
a=Alpha(color1) + Alpha(color1) * blend
ProcedureReturn RGBA(l255(r+256),l255(g+256),l255(b+256),l255(a+256))
EndProcedure
Procedure ColorSub(color1.l, color2.l, blend.f=1)
Protected r.w,g.w,b.w,a.w
r= Red(color1) - Red(color1) * blend
g=Green(color1) - Green(color1) * blend
b= Blue(color1) - Blue(color1) * blend
a=Alpha(color1) - Alpha(color1) * blend
ProcedureReturn RGBA(l255(r+256),l255(g+256),l255(b+256),l255(a+256))
EndProcedure
Procedure DrawingFilter_add(X, Y, cs.l, cd.l)
ProcedureReturn RGBA(l255(Red(cd)+Red(cs)+256),l255(Green(cd)+Green(cs)+256),l255(Blue(cd)+Blue(cs)+256),l255(Alpha(cd)+Alpha(cs)+256))
;ProcedureReturn RGBA(limite(Red(cd)+Red(cs)),limite(Green(cd)+Green(cs)),limite(Blue(cd)+Blue(cs)),limite(Alpha(cd)+Alpha(cs)))
EndProcedure
Procedure DrawingFilter_sub(X, Y, cs, cd)
ProcedureReturn RGBA(l255(Red(cd)-Red(cs)+256),l255(Green(cd)-Green(cs)+256),l255(Blue(cd)-Blue(cs)+256),l255(Alpha(cd)-Alpha(cs)+256))
;ProcedureReturn RGBA(limite(Red(cd)-Red(cs)),limite(Green(cd)-Green(cs)),limite(Blue(cd)-Blue(cs)),limite(Alpha(cd)-Alpha(cs)))
EndProcedure
Procedure.l HSLToRGB(hue.a, saturation.a, lightness.a, alpha=0)
Protected.f h=hue *6/256
Protected.f s=saturation/255
Protected.f l=lightness/255
Protected.f c,x,r_,v_,b_,m
c=(1-Abs(2*l-1))*s
x=c*(1-Abs(Mod(h, 2) -1))
Select Int(h)
Case 0:r_=c:v_=x
Case 1:r_=x:v_=c
Case 2:v_=c:b_=x
Case 3:v_=x:b_=c
Case 4:r_=x:b_=c
Case 5:r_=c:b_=x
EndSelect
m=l-c/2
Protected r,v,b
r=Int((r_+m)*255)
v=Int((v_+m)*255)
b=Int((b_+m)*255)
ProcedureReturn RGBA(r,v,b,alpha)
EndProcedure
Procedure.l RGBToHSL(red.a, green.a, blue.a, alpha=0)
Protected.f r=red/255
Protected.f g=green/255
Protected.f b=blue/255
Protected.f cmax, cmin, h_,c,m,h,s,l
Protected.l imax,imin
If r>=g And r>=b:imax=1:cmax=r:EndIf
If g>=r And g>=b:imax=2:cmax=g:EndIf
If b>=r And b>=g:imax=3:cmax=b:EndIf
If r<=g And r<=b:imin=1:cmin=r:EndIf
If g<=r And g<=b:imin=2:cmin=g:EndIf
If b<=r And b<=g:imin=3:cmin=b:EndIf
c=cmax-cmin
Select imax
Case 1:h_=Mod((g-b)/c+6,6)
Case 2:h_=(b-r)/c+2
Case 3:h_=(r-g)/c+4
EndSelect
h=h_/6
l=(cmax+cmin)/2
If l<>1:s=c/(1-Abs(2*l-1)):Else:s=0:EndIf
ProcedureReturn RGBA(h*255,s*255,l *255,alpha)
EndProcedure
; ==================================== exemple ====================================
Procedure affiche_exemple()
StartDrawing(CanvasOutput(0))
;--------------------- palette HSL
Box(0, 0, 512, 512, $888888)
For j=0 To 255
For i = 0 To 255
Plot(i,j, HSLToRGB(i,j,128))
Next
Next
;--------------------- spheres
DrawingMode(#PB_2DDrawing_Gradient)
Macro sphere
ResetGradientColors()
GradientColor(0.0,HSLToRGB(h,64,200))
GradientColor(0.3,HSLToRGB(h,64,128))
GradientColor(1.0,HSLToRGB(h,64,64))
CircularGradient(x-r*0.3, y+r*1.2+r*0.5,r)
Circle(x,y+r*1.2,r)
ResetGradientColors()
GradientColor(0.0,HSLToRGB(h,255,255))
GradientColor(0.3,HSLToRGB(h,255,128))
GradientColor(1.0,HSLToRGB(h,255,64))
CircularGradient(x-r*0.3, y-r*0.3,r)
Circle(x,y,r)
EndMacro
For j=1 To 4
n=1<<j
For i=0 To n-1
h=(0.5+i)/n*256
r=50/Sqr(n)
r=120/n
x=256+h
y=16*(i & 1)+330-420/Sqr(n)
sphere
Next
Next
;--------------------- filtres blend, add, sub
DrawImage(ImageID(0), 0, 256, 512, 256)
For j=0 To 2
Select j
Case 0:dm.s="Blend":DrawingMode(#PB_2DDrawing_Gradient |#PB_2DDrawing_AlphaBlend)
Case 1:dm.s="Add" :DrawingMode(#PB_2DDrawing_Gradient |#PB_2DDrawing_CustomFilter):CustomFilterCallback(@ DrawingFilter_add())
Case 2:dm.s="Sub" :DrawingMode(#PB_2DDrawing_Gradient |#PB_2DDrawing_CustomFilter):CustomFilterCallback(@ DrawingFilter_sub())
EndSelect
For i=0 To 2
x=64+(512-128)*j/2
y=64+256+64*i
ResetGradientColors()
GradientColor(0,$ff000000 |$88<<(i*8))
GradientColor(1,$ff000000)
CircularGradient(x,y,64)
Circle(x,y,64)
Next
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(x,256,dm)
Next
StopDrawing()
EndProcedure
Procedure affiche_geebee()
hue=GetGadgetState(1)
StartDrawing(CanvasOutput(0))
For i=0 To 2
DrawingMode(#PB_2DDrawing_Default )
DrawImage(ImageID(1),512,i*128)
Select i
Case 0:dm.s="Blend":DrawingMode(#PB_2DDrawing_AlphaBlend)
Case 1:dm.s="Add" :DrawingMode(#PB_2DDrawing_CustomFilter):CustomFilterCallback(@ DrawingFilter_add())
Case 2:dm.s="Sub" :DrawingMode(#PB_2DDrawing_CustomFilter):CustomFilterCallback(@ DrawingFilter_sub())
EndSelect
Box(512,i*128,128,128,HSLToRGB(hue,255,127,127))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(512,i*128,dm)
Next
StopDrawing()
EndProcedure
OpenWindow(0, 0, 0, 512+128+16, 512, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 512+128, 512)
ScrollBarGadget(1,512+128,0,16,512,0,255,1,#PB_ScrollBar_Vertical)
BindGadgetEvent(1,@ affiche_geebee())
UseJPEGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "Examples/3D/Data/Textures/dirt.jpg")
LoadImage(1, #PB_Compiler_Home + "Examples/3D/Data/Textures/geebee2.bmp")
affiche_exemple()
affiche_geebee()
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow