Alors donc, il restait encore quelques cas (3 pour être précis) où ma formule était fausse. C'est réglé :3
Après, j'ai bricolé un truc (mais j'avais pas d'idée précise, alors ça rend pas forcément terrible). Ça utilise un code du Soldat Inconnu (
) pour faire une projection radiale; j'ai pas vraiment étudié si la projection était valide, donc ça reste très pifometré. Note: la fonction du Soldat est lente (surtout avec le debuger en marche).
En théorie, pour obtenir ce que tu veux, faudrait plutot chercher du coté de la trigo, mais bon, je déteste ce sujet et j'ai pas envie de réfléchir maintenant, donc si tu veux un truc plus efficace, faut se sortir les doigts du cul et lire ça :
Code : Tout sélectionner
Procedure Max(A,B)
If A > B
ProcedureReturn A
Else
ProcedureReturn B
EndIf
EndProcedure
Procedure Min(A,B)
If A < B
ProcedureReturn A
Else
ProcedureReturn B
EndIf
EndProcedure
Procedure.f Hue(RGB)
Protected R, G, B, nImax, nImin, Hue.f
If RGB < = $FFFFFF Or RGB > = 0
R = Red(RGB)
G = Green(RGB)
B = Blue(RGB)
nImax = Max(Max(r,b),g)
nImin = Min(Min(r,b),g)
If(nImax = r)
Hue=60*(g-b)/(nImax-nImin)
ElseIf nImax = g
Hue=60*(b-r)/(nImax-nImin)+120
ElseIf nImax = b
Hue=60*(r-g)/(nImax-nImin)+240
EndIf
If Hue<0
Hue = 360 + Hue
EndIf
EndIf
ProcedureReturn Hue
EndProcedure
Procedure.f Brightness(RGB)
Protected R, G, B, nImax, Brightness.f
If RGB < = $FFFFFF Or RGB > = 0
R = Red(RGB)
G = Green(RGB)
B = Blue(RGB)
nImax = Max(Max(r,b),g)
Brightness = nImax/255
EndIf
ProcedureReturn Brightness * 100
EndProcedure
Procedure.f Saturation(RGB)
Protected R, G, B, nImax, nImin, Saturation.f
If RGB < = $FFFFFF Or RGB > = 0
R = Red(RGB)
G = Green(RGB)
B = Blue(RGB)
nImax = Max(Max(r,b),g)
nImin = Min(Min(r,b),g)
Saturation = 1 - nImin / nImax
EndIf
ProcedureReturn Saturation * 100
EndProcedure
Procedure HSBToRGB(Hue.f,Saturation.f,Brightness.f)
Protected R,G,B
Protected TopColor = Round(Brightness*255/100,#PB_Round_Nearest)
Protected MinColor = Round((Saturation/100 -1)*-1*TopColor,#PB_Round_Nearest)
If Hue > = 60 And Hue < 180
G = TopColor
Hue = Round((Hue -120) * (TopColor - MinColor) / 60,#PB_Round_Nearest)
If Hue > 0
R = MinColor
B = hue + R
Else
B = MinColor
R = (hue - B) * -1
EndIf
ElseIf Hue > = 180 And Hue < 300
B = TopColor
Hue = Round((Hue -240) * (TopColor - MinColor) / 60,#PB_Round_Nearest)
If Hue > 0
G = MinColor
R = hue + G
Else
R = MinColor
G = (hue - R) * -1
EndIf
Else
R = TopColor
If hue >= 300
Hue - 360
EndIf
Hue = Round(Hue * (TopColor - MinColor) / 60,#PB_Round_Nearest)
If hue > 0
B = MinColor
G = hue + B
Else
G = MinColor
B = (Hue - G) *-1
EndIf
EndIf
ProcedureReturn RGB(R,G,B)
EndProcedure
;{ Code du Soldat Inconnu :
Procedure.i RollUpImage(ImageSource.i, ImageDestination.i, StartAngle.d = 0)
EnableExplicit
Protected Largeur.i, Hauteur.i
Protected Retour.i
Protected i.i, ii.i, j.i
Protected Angle.d, x.d, x_droit.i, x_droit_pourcentage.d, x_gauche.i, x_gauche_pourcentage.d, y.d, y1.d, y1_debut.i, y1_debut_pourcentage.d, y2.d, y2_fin.i, y2_fin_pourcentage.d, Plage.d
Protected Quantite.d, Rouge.d, Vert.d, Bleu.d, Alpha.d
Largeur = ImageWidth(ImageSource)
Hauteur = ImageHeight(ImageSource)
Protected Dim Image(Largeur, Hauteur * 3)
StartDrawing(ImageOutput(ImageSource))
DrawingMode(#PB_2DDrawing_AlphaBlend)
; Lecture de l'image
For i = 0 To Largeur - 1
For ii = 0 To Hauteur - 1
Image(i, ii) = Point(i, ii)
Image(i, ii + Hauteur) = Image(i, ii)
Image(i, ii + 2 * Hauteur) = Image(i, ii)
Next
Next
StopDrawing()
; Création de li'mage en coordonnées polaires
Retour = CreateImage(ImageDestination, Largeur * 2 - 1, Largeur * 2 - 1, 32 , #PB_Image_Transparent)
If ImageDestination = #PB_Any
ImageDestination = Retour
EndIf
StartDrawing(ImageOutput(ImageDestination))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For i = 0 To Largeur * 2 - 2
For ii = 0 To Largeur * 2 - 2
x.d = Largeur - 1 - i
y.d = ii - Largeur + 1
; Calcul de l'angle
If x > 0 And y >= 0
Angle.d = ATan(y / x)
ElseIf x < 0 And y >= 0
Angle.d = #PI - ATan(-y / x)
ElseIf x < 0 And y < 0
Angle.d = #PI + ATan(y / x)
ElseIf x > 0 And y < 0
Angle.d = 2 * #PI - ATan(-y / x)
ElseIf y > 0
Angle.d = #PI / 2
Else
Angle.d = 3 * #PI / 2
EndIf
Angle + StartAngle
; Debug "Position = " + Str(x) + " ; " + Str(y)
x.d = Sqr(x * x + y * y) ; Rayon qui donne la position en x en partant de la droite de l'image d'origine
; Debug "Rayon = " + StrD(x, 3)
; Debug "Angle = " + StrD(Angle, 3)
If x <= Largeur - 2
x_droit = Largeur - Int(x) - 1
x_droit_pourcentage.d = 1 - x + Int(x) ; Répartion du rayon sur les pixels
x_gauche = x_droit - 1
x_gauche_pourcentage.d = 1 - x_droit_pourcentage
y.d = Hauteur + Hauteur * Angle / (2 * #PI) ; Position en y dans l'image d'origine, elle dépend de l'angle
Plage.d = Hauteur / (Largeur * 2 * #PI) * (Largeur / x) ; Plage sur laquelle il faut fusionner les pixels pour obtenir la couleur finale
If Plage > Hauteur
Plage = Hauteur
EndIf
; Debug "Hauteur = " + StrD(y, 3)
; Debug "Plage = " + StrD(Plage, 3)
y1.d = y - Plage / 2
y1_debut = Round(y1, #PB_Round_Down)
y1_debut_pourcentage.d = 1 - y1 + y1_debut
y2.d = y + Plage / 2
y2_fin = Round(y2, #PB_Round_Up)
y2_fin_pourcentage.d = 1 - y2_fin + y2
Quantite.d = 0
Rouge.d = 0
Vert.d = 0
Bleu.d = 0
Alpha.d = 0
For j = 0 To 3 * Hauteur - 1
If j >= y1 And j <= y2
Quantite + 1
Rouge + (Red(Image(x_droit, j)) * x_droit_pourcentage + Red(Image(x_gauche, j)) * x_gauche_pourcentage)
Vert + (Green(Image(x_droit, j)) * x_droit_pourcentage + Green(Image(x_gauche, j)) * x_gauche_pourcentage)
Bleu + (Blue(Image(x_droit, j)) * x_droit_pourcentage + Blue(Image(x_gauche, j)) * x_gauche_pourcentage)
Alpha + (Alpha(Image(x_droit, j)) * x_droit_pourcentage + Alpha(Image(x_gauche, j)) * x_gauche_pourcentage)
ElseIf j >= y1_debut And j < y1
Quantite + y1_debut_pourcentage
Rouge + (Red(Image(x_droit, j)) * x_droit_pourcentage + Red(Image(x_gauche, j)) * x_gauche_pourcentage) * y1_debut_pourcentage
Vert + (Green(Image(x_droit, j)) * x_droit_pourcentage + Green(Image(x_gauche, j)) * x_gauche_pourcentage) * y1_debut_pourcentage
Bleu + (Blue(Image(x_droit, j)) * x_droit_pourcentage + Blue(Image(x_gauche, j)) * x_gauche_pourcentage) * y1_debut_pourcentage
Alpha + (Alpha(Image(x_droit, j)) * x_droit_pourcentage + Alpha(Image(x_gauche, j)) * x_gauche_pourcentage) * y1_debut_pourcentage
ElseIf j <= y2_fin And j > y2
Quantite + y2_fin_pourcentage
Rouge + (Red(Image(x_droit, j)) * x_droit_pourcentage + Red(Image(x_gauche, j)) * x_gauche_pourcentage) * y2_fin_pourcentage
Vert + (Green(Image(x_droit, j)) * x_droit_pourcentage + Green(Image(x_gauche, j)) * x_gauche_pourcentage) * y2_fin_pourcentage
Bleu + (Blue(Image(x_droit, j)) * x_droit_pourcentage + Blue(Image(x_gauche, j)) * x_gauche_pourcentage) * y2_fin_pourcentage
Alpha + (Alpha(Image(x_droit, j)) * x_droit_pourcentage + Alpha(Image(x_gauche, j)) * x_gauche_pourcentage) * y2_fin_pourcentage
EndIf
Next
Rouge / Quantite
Vert / Quantite
Bleu / Quantite
Alpha / Quantite
If Rouge > 255
Rouge = 255
EndIf
If Bleu > 255
Bleu = 255
EndIf
If Vert > 255
Vert = 255
EndIf
If Alpha > 255
Alpha = 255
EndIf
Plot(i, ii, RGBA(Rouge, Vert, Bleu, Alpha))
Else
Plot(i, ii, $00FFFFFF)
EndIf
; Debug ""
Next
Next
StopDrawing()
ProcedureReturn Retour
DisableExplicit
EndProcedure
;}
OpenWindow(0,0,0,280,280,"Color Gradiant",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;CanvasGadget(0,0,0,101,361)
CreateImage(0,201,721,32)
StartDrawing(ImageOutput(0))
For loopY = 0 To 720
For loopX = 0 To 200
Plot(loopX,loopY,HSBToRGB(loopY/2,100 - loopX/2,100))
Next
Next
StopDrawing()
RollUpImage(0,1)
GrabImage(1,0,60,59,280,280)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver