Il y avait un bout de temps que j'avais l'idée de faire un test de sélecteur de couleur en cercle (et cela fait quelques temps que je n'avais pas fait de code en PB). Je me suis enfin mis dessus ce soir et cela donne ce test (code sale, pas optimisé, etc...), mais je vous le partage pour avoir vos avis.
Ce n'est pas encore un sélecteur de couleur mais juste l'affichage du cercle (je précise on sais jamais ^^).
Code : Tout sélectionner
EnableExplicit
; ****************************************************************************
Enumeration
#Window
#Canvas
#Track
EndEnumeration
; ****************************************************************************
#DEFINE_SINCOS_MAX = 359
Define.i i
Global Dim _Sin.f (#DEFINE_SINCOS_MAX)
Global Dim _Cos.f (#DEFINE_SINCOS_MAX)
For i=0 To #DEFINE_SINCOS_MAX
_Sin(i) = Sin((i / 180) * #PI)
_Cos(i) = Cos((i / 180) * #PI)
Next i
; ****************************************************************************
Procedure.l _CONVERTRM(fM1.f, fM2.f, fCH.f)
If fCH > 360
fCH - 360
ElseIf fCH < 0
fCH + 360
EndIf
If fCH < 60
fM1 = fM1 + (fM2 - fM1) * fCH / 60
ElseIf fCH < 180
fM1 = fM2
ElseIf fCH < 240
fM1 = fM1 + (fM2 - fM1) * (240 - fCH) / 60
EndIf
ProcedureReturn fM1 * 255
EndProcedure
Procedure _HSL_TO_RGB(fCH.f, fCL.f, fCS.f, *bCR, *bCG, *bCB)
Protected.f fM1, fM2
fCH = fCH * 360 / 255
fCL = fCL / 255
fCS = fCS / 255
If fCL < 0.5
fM2 = fCL + fCL * fCS
Else
fM2 = fCL + fCS - fCL * fCS
EndIf
fM1 = 2 * fCL - fM2
If fCS = 0
PokeL(*bCR, fCL * 255)
PokeL(*bCG, fCL * 255)
PokeL(*bCB, fCL * 255)
Else
PokeL(*bCR, _CONVERTRM(fM1, fM2, fCH + 120))
PokeL(*bCG, _CONVERTRM(fM1, fM2, fCH ))
PokeL(*bCB, _CONVERTRM(fM1, fM2, fCH - 120))
EndIf
EndProcedure
; ****************************************************************************
Procedure DrawCircular(radius, cs.l = 255)
Define.l i, j, k, x, y, x1, y1, x2, y2, x3, y3, x4, y4
Define.l cr, cg, cb, cl, ch
radius / 2
Define.f fpas = 255 / radius
Define.f dpas = 255 / #DEFINE_SINCOS_MAX
If StartVectorDrawing(CanvasVectorOutput(#Canvas))
For j = 0 To radius
cl = j * fpas
For i = 0 To #DEFINE_SINCOS_MAX Step #DEFINE_SINCOS_MAX / 48
ch = i * dpas
x1 = radius + _Sin(i) * (radius - j)
y1 = radius + _Cos(i) * (radius - j)
x2 = radius + _Sin((i + (#DEFINE_SINCOS_MAX) / 48) % #DEFINE_SINCOS_MAX) * (radius - j)
y2 = radius + _Cos((i + (#DEFINE_SINCOS_MAX) / 48) % #DEFINE_SINCOS_MAX) * (radius - j)
x3 = radius + _Sin(i) * (radius - j - (radius / (24 - 1)))
y3 = radius + _Cos(i) * (radius - j - (radius / (24 - 1)))
x4 = radius + _Sin((i + ((#DEFINE_SINCOS_MAX) / 48) + 2) % #DEFINE_SINCOS_MAX) * (radius - j - 1 - (radius / (24 - 1)))
y4 = radius + _Cos((i + ((#DEFINE_SINCOS_MAX) / 48) + 2) % #DEFINE_SINCOS_MAX) * (radius - j - 1 - (radius / (24 - 1)))
_HSL_TO_RGB (ch, cl, cs , @cr, @cg, @cb)
VectorSourceColor(RGBA(cr, cg, cb, 255))
MovePathCursor (x1, y1)
AddPathLine (x3, y3)
AddPathLine (x4, y4)
AddPathLine (x2, y2)
FillPath ()
Next i
j + ((radius / 24) - 1)
Next j
StopVectorDrawing ()
EndIf
EndProcedure
; ****************************************************************************
Define.i save, event, eveng, radius = 600
If OpenWindow(#Window, 0, 0, radius + 1, radius + 50, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(#Canvas, 0, 0, radius, radius, #PB_Canvas_Keyboard)
TrackBarGadget(#Track, 0, radius + 10, radius, 30, 0, 255)
SetGadgetState(#Track, 255)
DrawCircular(radius)
Repeat
event = WaitWindowEvent()
eveng = EventGadget()
Select eveng
Case #Canvas
Case #Track
If save <> GetGadgetState(#Track)
save = GetGadgetState(#Track)
DrawCircular(radius, GetGadgetState(#Track))
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End
GallyHC