ça fait des plombes que je ne suis pas passé. Et pour cause, je suis bien occupée dans ma maison (c'est tout neuf et c'est plein de truc à faire)
Bref, un petit code qui permet d'enrouler une image, dis comme ça, ça semble pas très clair.
En gros, vous dessiner une flèche toute droite et vous obtenez une flèche enroulée dont le nez touche le c... hum. Pas mieux
Vous lancer le code et pis zou, ce sera mieux

Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 5.0
; Explication du programme :
; Enrouler une image
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
; Création de la fenêtre
If OpenWindow(0, 0, 0, 600, 300, "Transformation coordonnée polaire", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0
End
EndIf
Largeur = 32
Hauteur = 256
CreateImage(0, Largeur, Hauteur, 32 | #PB_Image_Transparent)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For i = 0 To Hauteur - 1 Step 16
Box(2, i, 26, 4, $FF000000)
Line(7, i, 1, 8, $FFFF0000)
Line(8, i, 1, 8, $FF0000FF)
Next
Line(12, 0, 1, Hauteur, $FF000000)
Line(16, 0, 1, Hauteur * 3 / 4, $FF000000)
Line(20, 0, 1, Hauteur * 2 / 4, $FF000000)
Line(24, 0, 1, Hauteur * 1 / 4, $FF000000)
StopDrawing()
ImageGadget(0, 10, 10, 0, 0, ImageID(0))
RollUpImage(0, 1)
ImageGadget(1, 110, 10, 0, 0, ImageID(1))
Largeur = 48
Hauteur = 256
CreateImage(2, Largeur, Hauteur, 32 | #PB_Image_Transparent)
StartDrawing(ImageOutput(2))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(2, 0, Largeur - 2, Hauteur, $50660048)
Line(4, 8, 1, Hauteur - 16, $FF000000)
Line(10, 4, 1, Hauteur - 8, $FF000000)
For i = 0 To Hauteur Step 32
Circle(24, i + 16, 8, RGBA(i, 0, 0, 255))
Next
StopDrawing()
ImageGadget(2, 210, 10, 0, 0, ImageID(2))
RollUpImage(2, 3)
ImageGadget(3, 310, 10, 0, 0, ImageID(3))
Largeur = 32
Hauteur = 256
CreateImage(4, Largeur, Hauteur, 32 | #PB_Image_Transparent)
StartDrawing(ImageOutput(4))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For i = 0 To Hauteur - 1
Line(8, i, 2, 1, RGBA(0, 0, 0, 255 - i))
Next
Line(9, 0, 5, 10, $FF000000)
Line(9, 1, 5, 10, $FF000000)
Line(8, 0, -5, 10, $FF000000)
Line(8, 1, -5, 10, $FF000000)
StopDrawing()
ImageGadget(4, 410, 10, 0, 0, ImageID(4))
Angle.d = #PI / 2
RollUpImage(4, 5, Angle)
AddWindowTimer(0, 1, 25)
ImageGadget(5, 510, 10, 0, 0, ImageID(5))
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Timer
Select EventTimer() ; Menus
Case 1
Angle + #PI / 40
If Angle > #PI
Angle - 2 * #PI
EndIf
RollUpImage(4, 5, Angle)
SetGadgetState(5, ImageID(5))
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow