Module de dessin dépixelisé

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Module de dessin dépixelisé

Message par Ollivier »

Source : Anti-Aliasing ( AA ) Drawing Module (AlphaBlend supported)
Auteur du sujet : Eddy
Auteurs du code : Eddy / LSI

Code : Merci encore à Taz pour le code plus bas.

(Ça va me casser les bonbons mais je crois que je vais devoir faire un presse-papier digne de ce nom sur le mobile...)

Explications :
Ce code fait suite à un code initial de LSI (Le Soldat Inconnu) sur ce topic pour dessiner des formes de manière "Anti-Aliasée" (bords lissés)
Le Soldat Inconnu a écrit :Il permet de dessiner des lignes, des ellipses, des triangles avec bordure ou pas, et de différentes épaisseurs
Ce code a été complété par Eddy, auquel il a ajouté :
Eddy a écrit : - original thread : http://www.purebasic.fr/english/viewtop ... t=CircleAA
- Added: alphablend mode support
Eddy traduit a écrit : - Topic d'origine : http://www.purebasic.fr/english/viewtop ... t=CircleAA
- Ajouté: support du mode "alphablend"
[/quote]
Dernière modification par Ollivier le dim. 16/août/2015 1:44, modifié 1 fois.
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Module de dessin dépixelisé

Message par SPH »

Erreur ligne 25 :

Code : Tout sélectionner

Blend two colors (using AlphaBlend If enabled)
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
TazNormand
Messages : 1294
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: Module de dessin dépixelisé

Message par TazNormand »

A priori on dirait un problème de "copier-coller", les lignes sont "coupées", ce qui génère des commentaires sans ";", et des calculs sur 2 lignes

code "à peu près remis en forme" à la "mano" :

Code : Tout sélectionner

DeclareModule DrawingAA
  ; Original Author : Le Soldat Inconnu
  ; Modified by: Eddy
  ; supported PB version : 5.30+
  ;
  ; Program purpose : Smooth drawing
  Declare DrawingModeAA(Thickness=1, Mode=#PB_Ignore)
  Declare LineAA(X, Y, Width, Height, Color)
  Declare CircleAA(X, Y, Radius, Color)
  Declare EllipseAA(X, Y, RadiusX, RadiusY, Color)
  Declare TriangleAA(x1, y1, x2, y2, x3, y3, Color)
EndDeclareModule
Module DrawingAA
  EnableExplicit
  Global AA_Thickness=1
  Global AA_Mode=#PB_2DDrawing_Default
  Procedure DrawingModeAA(Thickness=1, Mode=#PB_Ignore)
    If Mode<>#PB_Ignore
      DrawingMode(Mode)
      AA_Mode=Mode
    EndIf
    AA_Thickness=Thickness
  EndProcedure
  Procedure.i BlendColors(FrontColor, BackColor, Factor.f) ;
    ;Blend two colors (using AlphaBlend If enabled)
    Protected R=Red(FrontColor)
    Protected G=Green(FrontColor)
    Protected B=Blue(FrontColor)
    If AA_Mode & #PB_2DDrawing_AlphaBlend
      ProcedureReturn RGBA(R, G, B, Alpha(FrontColor)*Factor)
    Else
      R=R * Factor + (1-Factor) * Red(BackColor)
      G=G * Factor + (1-Factor) * Green(BackColor)
      B=B * Factor + (1-Factor) * Blue(BackColor)
      ProcedureReturn RGB(R, G, B)
    EndIf
  EndProcedure
  Procedure CircleAA(X, Y, Radius, Color)
    Protected n, nn, Distance.f, Factor.f, Background
    If AA_Mode & #PB_2DDrawing_Outlined ; Cercle vide
      ; on dessine 1/4 du
      ;cercle et on duplique pour le reste
      For n=0 To Radius
        For nn=0 To Radius
          Distance.f=Sqr(n * n + nn * nn)
          If Distance<=Radius And Distance>Radius - 1
            Factor.f=1-Abs(Radius - 1 - Distance)
            Background=Point(X + n, Y + nn) : Plot(X + n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y + nn) : Plot(X - n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X + n, Y - nn) : Plot(X + n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y - nn) : Plot(X - n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
          ElseIf Distance<=Radius - AA_Thickness And
                 Distance>Radius - AA_Thickness - 1
            Factor.f=1-Abs(Radius - AA_Thickness -Distance)
            Background=Point(X + n, Y + nn) : Plot(X + n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y + nn) : Plot(X - n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X + n, Y - nn) : Plot(X + n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y - nn) : Plot(X - n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
          ElseIf Distance<=Radius - 1 And Distance>Radius -AA_Thickness
            Plot(X + n, Y + nn, Color)
            Plot(X - n, Y + nn, Color)
            Plot(X + n, Y - nn, Color)
            Plot(X - n, Y - nn, Color)
          EndIf
        Next
      Next
    Else ; Cercle plein
      ; on dessine 1/4 du cercle et on duplique pour lereste
      For n=0 To Radius
        For nn=0 To Radius
          Distance.f=Sqr(n * n + nn * nn)
          If Distance<=Radius And Distance>Radius - 1
            Factor.f=(Radius - Distance)
            Background=Point(X + n, Y + nn) : Plot(X + n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y + nn) : Plot(X - n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X + n, Y - nn) : Plot(X + n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y - nn) : Plot(X - n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
          ElseIf Distance<=Radius - 1
            Plot(X + n, Y + nn, Color)
            Plot(X - n, Y + nn, Color)
            Plot(X + n, Y - nn, Color)
            Plot(X - n, Y - nn, Color)
          EndIf
        Next
      Next
    EndIf
  EndProcedure
  Procedure EllipseAA(X, Y, RadiusX, RadiusY, Color)
    Protected n, nn, Distance.f, Factor.f, Background
    Protected Ellipse_CosAngle.f, Ellispse_Rayon.f, Ellipse_E.f
    ; Précacul de l'équation de l'ellipse
    If RadiusX>RadiusY
      Ellipse_E=Sqr(RadiusX * RadiusX - RadiusY * RadiusY) /RadiusX
    Else
      Ellipse_E=Sqr(RadiusY * RadiusY - RadiusX * RadiusX) /RadiusY
    EndIf
    Ellipse_E * Ellipse_E
    If AA_Mode & #PB_2DDrawing_Outlined ; ellipse vide
      ; on dessine 1/4 de
      ;l'ellipse et on duplique pour le reste
      For n=0 To RadiusX
        For nn=0 To RadiusY
          Distance.f=Sqr(n * n + nn * nn)
          If RadiusX>RadiusY
            If n
              Ellipse_CosAngle.f=n / Distance
              Ellispse_Rayon=Sqr(RadiusY * RadiusY / (1 -Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
            Else
              Ellispse_Rayon=RadiusY
            EndIf
          Else
            If nn
              Ellipse_CosAngle.f=nn / Distance
              Ellispse_Rayon=Sqr(RadiusX * RadiusX / (1 -Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
            Else
              Ellispse_Rayon=RadiusX
            EndIf
          EndIf
          If Distance<=Ellispse_Rayon And
             Distance>Ellispse_Rayon - 1
            Factor.f=1-Abs(Ellispse_Rayon - 1 - Distance)
            Background=Point(X + n, Y + nn) : Plot(X + n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y + nn) : Plot(X - n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X + n, Y - nn) : Plot(X + n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y - nn) : Plot(X - n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
          ElseIf Distance<=Ellispse_Rayon - AA_Thickness And
                 Distance>Ellispse_Rayon - AA_Thickness - 1
            Factor.f=1-Abs(Ellispse_Rayon - AA_Thickness -Distance)
            Background=Point(X + n, Y + nn) : Plot(X + n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y + nn) : Plot(X - n,
                                                   Y + nn, BlendColors(Color, Background, Factor))
            Background=Point(X + n, Y - nn) : Plot(X + n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
            Background=Point(X - n, Y - nn) : Plot(X - n,
                                                   Y - nn, BlendColors(Color, Background, Factor))
          ElseIf Distance<=Ellispse_Rayon - 1 And
                 Distance>Ellispse_Rayon - AA_Thickness
            Plot(X + n, Y + nn, Color)
            Plot(X - n, Y + nn, Color)
            Plot(X + n, Y - nn, Color)
            Plot(X - n, Y - nn, Color)
          EndIf
        Next
      Next
    Else ; ellipse pleine
      ; on dessine 1/4 de l'ellipse et on duplique pour le reste
      For n=0 To RadiusX
        For nn=0 To RadiusY
          Distance.f=Sqr(n * n + nn * nn)
          If RadiusX>RadiusY
            If n
              Ellipse_CosAngle.f=n / Distance
              Ellispse_Rayon=Sqr(RadiusY * RadiusY / (1 -Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
            Else
              Ellispse_Rayon=RadiusY
            EndIf
          Else
            If nn
              Ellipse_CosAngle.f=nn / Distance
              Ellispse_Rayon=Sqr(RadiusX * RadiusX / (1 -Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
            Else
              Ellispse_Rayon=RadiusX
            EndIf
          EndIf
          If Distance<=Ellispse_Rayon And
             Distance>Ellispse_Rayon - 1
            Factor.f=1 - (Ellispse_Rayon - Distance)
            Background=Point(X + n, Y + nn) : Plot(X + n,
                                                   Y + nn, BlendColors(Background, Color, Factor))
            Background=Point(X - n, Y + nn) : Plot(X - n,
                                                   Y + nn, BlendColors(Background, Color, Factor))
            Background=Point(X + n, Y - nn) : Plot(X + n,
                                                   Y - nn, BlendColors(Background, Color, Factor))
            Background=Point(X - n, Y - nn) : Plot(X - n,
                                                   Y - nn, BlendColors(Background, Color, Factor))
          ElseIf Distance<=Ellispse_Rayon - 1
            Plot(X + n, Y + nn, Color)
            Plot(X - n, Y + nn, Color)
            Plot(X + n, Y - nn, Color)
            Plot(X - n, Y - nn, Color)
          EndIf
        Next
      Next
    EndIf
  EndProcedure
  Procedure LineAA(X, Y, Width, Height, Color)
    Protected n, nn, Distance.f, Background, Factor.f
    Protected SensX, SensY, Epaisseur.f, x2.f, y2.f,
CosAngle.f, SinAngle.f
    ; On mets la droite toujours dans le même sens pour l'analyse
    ; La sauvegarde du sens permettra de dessiner la droite
    ;ensuite dans le bon sens
    If Width>=0
      SensX=1
    Else
      SensX=-1
      Width=- Width
    EndIf
    If Height>=0
      SensY=1
    Else
      SensY=-1
      Height=- Height
    EndIf
    ; Demi épaisseur de la ligne
    Epaisseur.f=AA_Thickness / 2
    ; calcul pour le changement de repère qui permet de
    ;connaitre l'épaisseur du trait et de gérer l'AA
    Distance.f=Sqr(Width * Width + Height * Height)
    CosAngle.f=Width / Distance
    SinAngle.f=-Sin(ACos(CosAngle))
    ; Dessin de la ligne
    For n=-AA_Thickness To Width + AA_Thickness
      For nn=-AA_Thickness To Height + AA_Thickness
        ; changement de base
        ; les y représentent l'épaisseur de la ligne
        x2=n * CosAngle - nn * SinAngle
        y2=Abs(n * SinAngle + nn * CosAngle)
        If y2<=Epaisseur + 0.5
          Factor=0.5 + Epaisseur - y2
          If Factor>1
            Factor=1
          EndIf
          If x2>-1 And x2<Distance + 1
            If x2<0
              Factor * (1 + x2)
            ElseIf x2>Distance
              Factor * (1 - x2 + Distance)
            EndIf
          Else
            Factor=0
          EndIf
          If Factor>0
            If Factor<1
              Background=Point(X + n * SensX, Y + nn *SensY)
              Plot(X + n * SensX, Y + nn * SensY,
                   BlendColors(Color, Background, Factor))
            Else
              Plot(X + n * SensX, Y + nn * SensY, Color)
            EndIf
          EndIf
        EndIf
      Next
    Next
  EndProcedure
  Procedure TriangleAA(x1, y1, x2, y2, x3, y3, Color)
    Protected n, nn, Background, Factor.f, Epaisseur.f, Zone_G,
Zone_D, Zone_H, Zone_B
    Protected Width12, Hight12, Distance12.f, CosAngle12.f,
SinAngle12.f, Sens12, y1_r2.f, Application1.f, Interieur1
    Protected Width23, Hight23, Distance23.f, CosAngle23.f,
SinAngle23.f, Sens23, y2_r2.f, Application2.f, Interieur2
    Protected Width31, Hight31, Distance31.f, CosAngle31.f,
SinAngle31.f, Sens31, y3_r2.f, Application3.f, Interieur3
    ; Demi épaisseur de la ligne
    Epaisseur.f=AA_Thickness / 2
    ; calcul pour le changement de repère qui permet de
    ;connaitre l'épaisseur du trait et de gérer l'AA
    ; Pour la ligne 12
    ; Le point de départ du repère est le point x1, y1
    Width12=x2 - x1
    Hight12=y2 - y1
    Distance12.f=Sqr(Width12 * Width12 + Hight12 * Hight12)
    CosAngle12.f=Width12 / Distance12
    SinAngle12.f=Sin(ACos(CosAngle12))
    If Hight12>0
      SinAngle12=-SinAngle12
    EndIf
    ; changement de base
    y3_r2=(x3 - x1) * SinAngle12 + (y3 - y1) * CosAngle12
    ; on regarde de quel coté de la ligne se trouve le triangle
    ;en regardant la position du point 3
    If y3_r2>0
      Sens12=1
    Else
      Sens12=-1
    EndIf
    ; Pour la ligne 23
    ; Le point de départ du repère est le point x2, y2
    Width23=x3 - x2
    Hight23=y3 - y2
    Distance23.f=Sqr(Width23 * Width23 + Hight23 * Hight23)
    CosAngle23.f=Width23 / Distance23
    SinAngle23.f=Sin(ACos(CosAngle23))
    If Hight23>0
      SinAngle23=-SinAngle23
    EndIf
    ; changement de base
    y1_r2=(x1 - x2) * SinAngle23 + (y1 - y2) * CosAngle23
    ; on regarde de quel coté de la ligne se trouve le triangle
    ;en regardant la position du point 3
    If y1_r2>0
      Sens23=1
    Else
      Sens23=-1
    EndIf
    ; Pour la ligne 31
    ; Le point de départ du repère est le point x3, y3
    Width31=x1 - x3
    Hight31=y1 - y3
    Distance31.f=Sqr(Width31 * Width31 + Hight31 * Hight31)
    CosAngle31.f=Width31 / Distance31
    SinAngle31.f=Sin(ACos(CosAngle31))
    If Hight31>0
      SinAngle31=-SinAngle31
    EndIf
    ; changement de base
    y2_r2=(x2 - x3) * SinAngle31 + (y2 - y3) * CosAngle31
    ; on regarde de quel coté de la ligne se trouve le triangle
    ;en regardant la position du point 3
    If y2_r2>0
      Sens31=1
    Else
      Sens31=-1
    EndIf
    ; Détermination de la zone de dessin
    Zone_G=x1
    Zone_D=x1
    Zone_B=y1
    Zone_H=y1
    If x2<Zone_G
      Zone_G=x2
    EndIf
    If x3<Zone_G
      Zone_G=x3
    EndIf
    If x2>Zone_D
      Zone_D=x2
    EndIf
    If x3>Zone_D
      Zone_D=x3
    EndIf
    If y2<Zone_B
      Zone_B=y2
    EndIf
    If y3<Zone_B
      Zone_B=y3
    EndIf
    If y2>Zone_H
      Zone_H=y2
    EndIf
    If y3>Zone_H
      Zone_H=y3
    EndIf
    Zone_B - AA_Thickness
    Zone_H + AA_Thickness
    Zone_G - AA_Thickness
    Zone_D + AA_Thickness
    ; Dessin du triangle
    If AA_Mode & #PB_2DDrawing_Outlined ; Triangle vide
      For n=Zone_G To Zone_D
        For nn=Zone_B To Zone_H
          y1_r2=(n - x1) * SinAngle12 + (nn - y1) *CosAngle12
          y1_r2 * Sens12
          If y1_r2>=-0.5 - Epaisseur
            Application1.f=0.5 + Epaisseur + y1_r2
            If Application1>1
              Application1=1 + 0.5 + Epaisseur -Application1
              If Application1<0
                Application1=0
              EndIf
              Interieur1=1
            Else
              Interieur1=0
            EndIf
            y2_r2=(n - x2) * SinAngle23 + (nn - y2) *CosAngle23
            y2_r2 * Sens23
            If y2_r2>=-0.5 - Epaisseur
              Application2.f=0.5 + Epaisseur + y2_r2
              If Application2>1
                Application2=1 + 0.5 + Epaisseur -Application2
                If Application2<0
                  Application2=0
                EndIf
                Interieur2=1
              Else
                Interieur2=0
              EndIf
              y3_r2=(n - x3) * SinAngle31 + (nn - y3) *CosAngle31
              y3_r2 * Sens31
              If y3_r2>=-0.5 - Epaisseur
                Application3.f=0.5 + Epaisseur + y3_r2
                If Application3>1
                  Application3=1 + 0.5 + Epaisseur -Application3
                  If Application3<0
                    Application3=0
                  EndIf
                  Interieur3=1
                Else
                  Interieur3=0
                EndIf
                If Interieur1 And Interieur2 And
                   Interieur3
                  Factor=Application1 + Application2 +
                         Application3
                Else
                  Factor=1
                  If Interieur1=0
                    Factor * Application1
                  EndIf
                  If Interieur2=0
                    Factor * Application2
                  EndIf
                  If Interieur3=0
                    Factor * Application3
                  EndIf
                EndIf
                If Factor>0
                  If Factor<1
                    Background=Point(n, nn)
                    Plot(n, nn, BlendColors(Color,
                                            Background, Factor))
                  Else
                    Plot(n, nn, Color)
                  EndIf
                EndIf
              EndIf
            EndIf
          EndIf
        Next
      Next
    Else ; Triangle plein
      For n=Zone_G To Zone_D
        For nn=Zone_B To Zone_H
          y1_r2=(n - x1) * SinAngle12 + (nn - y1) *CosAngle12
          y1_r2 * Sens12
          If y1_r2>=-0.5 - Epaisseur
            Application1.f=0.5 + Epaisseur + y1_r2
            If Application1>1
              Application1=1
            EndIf
            y2_r2=(n - x2) * SinAngle23 + (nn - y2) *CosAngle23
            y2_r2 * Sens23
            If y2_r2>=-0.5 - Epaisseur
              Application2.f=0.5 + Epaisseur + y2_r2
              If Application2>1
                Application2=1
              EndIf
              y3_r2=(n - x3) * SinAngle31 + (nn - y3) *CosAngle31
              y3_r2 * Sens31
              If y3_r2>=-0.5 - Epaisseur
                Application3.f=0.5 + Epaisseur + y3_r2
                If Application3>1
                  Application3=1
                EndIf
                Factor=Application1 * Application2 *Application3
                If Factor<1
                  Background=Point(n, nn)
                  Plot(n, nn, BlendColors(Color,
                                          Background, Factor))
                Else
                  Plot(n, nn, Color)
                EndIf
              EndIf
            EndIf
          EndIf
        Next
      Next
    EndIf
  EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
  UseModule DrawingAA
  ; ******************************************************
  ; EXAMPLE
  ; Test functions to draw with anti-aliasing ( AA )
  ; ******************************************************
  If OpenWindow(0, 0, 0, 500, 500, "Test", #PB_Window_SystemMenu| #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
    If CanvasGadget(0, 0, 0, 500, 500)
      StartDrawing(CanvasOutput(0))
      blackColor=RGBA(0, 0, 0, 255)
      ; Our fancy background
      #Carreau=25
      For n=0 To 500 Step #Carreau
        For nn=0 To 500 Step #Carreau
          If ((n + nn) / #Carreau) & %1=%1
            Box(n, nn, #Carreau, #Carreau, $FFFFFF)
          Else
            Box(n, nn, #Carreau, #Carreau, $0000FF)
          EndIf
        Next
      Next
      ; Drawing Circles
      DrawingModeAA(1, #PB_2DDrawing_AlphaBlend)
      CircleAA(100, 100, 70, blackColor)
      DrawingModeAA(1, #PB_2DDrawing_AlphaBlend |
                       #PB_2DDrawing_Outlined)
      CircleAA(250, 100, 50, blackColor)
      DrawingModeAA(3)
      CircleAA(250, 100, 70, blackColor)
      ; Drawing Ellipses
      DrawingModeAA(2, #PB_2DDrawing_AlphaBlend)
      EllipseAA(400, 100, 30, 20, blackColor)
      DrawingModeAA(2, #PB_2DDrawing_AlphaBlend |
                       #PB_2DDrawing_Outlined)
      EllipseAA(400, 100, 40, 60, blackColor)
      DrawingModeAA(1)
      EllipseAA(400, 100, 50, 70, blackColor)
      ; Drawing Lines
      DrawingModeAA(1);, #PB_2DDrawing_AlphaBlend)
      For n=0 To 150 Step 30
        LineAA(20, 200, 150, n, blackColor)
      Next
      For n=0 To 120 Step 30
        LineAA(20, 200, n, 150, blackColor)
      Next
      Thickness=2
      For n=0 To 150 Step 30
        DrawingModeAA(Thickness) : Thickness + 1
        LineAA(200, 200, 150, n, blackColor)
      Next
      Thickness=2
      For n=0 To 120 Step 30
        DrawingModeAA(Thickness) : Thickness + 1
        LineAA(200, 200, n, 150, blackColor)
      Next
      ; Drawing Triangles
      DrawingModeAA(1, #PB_2DDrawing_AlphaBlend)
      TriangleAA(420, 200, 480, 250, 370, 350, blackColor)
      Thickness=1
      DrawingModeAA(1, #PB_2DDrawing_AlphaBlend |
                       #PB_2DDrawing_Outlined)
      For n=0 To 30 Step 10
        DrawingModeAA(Thickness) : Thickness + 1
        TriangleAA(490 - n, 260 + n, 390 + n, 350, 460, 400- n, blackColor)
      Next
      StopDrawing()
    EndIf
    Repeat: Until WaitWindowEvent()=#PB_Event_CloseWindow
  EndIf
  End
CompilerEndIf 
Image
Image
Avatar de l’utilisateur
Ar-S
Messages : 9477
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Module de dessin dépixelisé

Message par Ar-S »

Le rendu est pas mal du tout sauf peut être l'ellipse centrale du dessin en haut à droite que je trouve un peu trop dentelée.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
blendman
Messages : 2017
Inscription : sam. 19/févr./2011 12:46

Re: Module de dessin dépixelisé

Message par blendman »

@Ar-s :
sur le code original de LSI, l'ellipse est lissé ;) :
http://www.purebasic.fr/english/viewtop ... t=CircleAA
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: Message à Djes, Flaith, LSI, Gnozal, etc... : ou êtes-vo

Message par Ollivier »

J'ai retrouvé ce code datant du 8 Février 2009.
LSI cherchait sûrement à se passer de GDI, et, comme moi, je cherchais idem, on s'est retrouvé à s'échanger une pincée d'infos à ce sujet.

Vous observerez le dernier résultat du "match" de performance que nous avions mené. Il a gagné. Je voulais mettre en place une usine à gaz de DrawAlphaImage() pour faire de l'anti-aliasing. Il n'était franchement pas chaud.

Code : Tout sélectionner

 ;____________________________________________________________ 
;������������������������������������������������������������ 
; Auteur(s) : Le Soldat Inconnu / Ollivier
; Versions du compilateur : 4.30
; Adressage : 32 bits
;
; Explication du programme :
; Dessin avec lissage / Lignes douces
;
; Pr�caution(s) d'emploi:
; /!\ /!\ /!\ /!\ /!\ /!\
; Il est IMPERATIF de terminer un programe avec un appel de
; la fonction SLineStop() si SLineStart() a �t� appel� durant
; l'ex�cution du programme.
; /!\ Sinon: risque de saturation de la m�moire.  
;____________________________________________________________ 
;������������������������������������������������������������ 
Structure SLINEHEADER ; Structure du bloc syst�me de SLine()
   *iMark ; Identificateur (Adresse du bloc syst�me)
   hQty.L ; Quantit� de d�grad�s horizontaux
   vQty.L ; Quantit� de d�grad�s verticaux
   *hData ; Adresse des donn�es horizontales
   *vData ; Adresse des donn�es verticales
EndStructure

Structure SLINEGRADE ; Structure de donn�es d'un d�grad�
   *GradeBmp     ; Adresse de l'image alpha
   HndGradeBmp.L ; Handle  de l'image alpha
EndStructure

Structure SLINEBODY ; Structure de donn�es des d�grad�s
   D.SLINEGRADE[65536]
EndStructure

;- Buffer et handle

Procedure.L AllocAlphaBuffer(W.L, H.L) 
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 
; Cr�e une zone m�moire pour l'�dition d'une image Alpha 
; ��������������������������������������; ������������������������������������������������������ 
; Entr�es W (LONG) Largeur de l'image 
; ������� H (LONG) Hauteur de l'image 
; 
; Sortie Retourne l'adresse pointant sur l'image 
; ������ 
; Remarque L'image poss�de une en-t�te dont la structure est comme suit: 
; �������� ___________________________ 
;          | $0 | Largeur de l'image | 
;          | $4 | Hauteur de l'image | 
;          ��������������������������� 
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 
    *Alpha = AllocateMemory(((W * H) << 2) + 8) 
    PokeL(*Alpha, W) 
    PokeL(*Alpha + 4, H) 
    
    ProcedureReturn *Alpha 
EndProcedure 



Procedure.L CreateAlphaHandle(*lpvBits) 
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 
; Cr�e une image Alpha de 32 bits de profondeur � partir d'une zone m�moire 
; ��������������������������������������; ������������������������������������������������������������������������� 
; Entr�e Adresse pointant sur l'image 
; ������ 
; Sortie Retourne le handle de l'image (= ImageID) 
; ������ 
; Remarque La zone m�moire doit poss�der une en-t�te dont la structure est 
; �������� comme suit: 
;          ___________________________ 
;          | $0 | Largeur de l'image | 
;          | $4 | Hauteur de l'image | 
;          ��������������������������� 
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 
    Protected nWidth.L = PeekL(*lpvBits) 
    Protected nHeight.L = PeekL(*lpvBits + 4) 
    Protected AlphaImage.L = CreateBitmap_(nWidth, nHeight, 1, 32, *lpvBits + 8)    
    ProcedureReturn AlphaImage 
EndProcedure 

;- Gestion

Procedure.L SLineStart(xFormat.L, yFormat.L)
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 
; Initialise la gestion des lignes douces
; ��������������������������������������; ���������������������������������������
; Entr�es : xFormat = Largeur maxi ( /!\ <> �paisseur )
; �������   yFormat = Hauteur maxi
;
; Sortie : Pointeur de gestion
; ������
; 
; Remarque : Surtout ne pas perdre ce pointeur sinon la 
; ��������   proc�dure SLineStop() ne peut s'ex�cuter
;            /!\ Risque de crash hard /!\
;
;            S'utilise UNE SEULE FOIS en d�but de programme.
;            (Comme InitSprite() etc...)
;
; Exemple : SLineStart(1024, 768) g�re une image ou un 
; �������   support de dessin de 1024 par 768 pixels avec
;           32 bits de profondeurs
;           L'allocation cons�quente est d'environ 8 Mo
;           r�partis en 1800 handles et 1800 blocs m�moire
;           d'o� la raison des pr�cautions
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 

   ; Pointeurs de bloc:
   
   ; 1) En-t�te
   Protected *SLH.SLINEHEADER
   
   ; 2) Donn�es des d�grad�s horizontaux
   Protected *SLHG.SLINEBODY

   ; 3) Donn�es des d�grad�s verticaux
   Protected *SLVG.SLINEBODY
   
   ; Variable locale pour les boucles
   Protected i.L
   Protected j.L
   Protected Attribut.L

      
   ; 1) Pr�paration du bloc d'en-t�te
   
   ; Allocation
   *SLH = AllocateMemory(SizeOf(SLINEHEADER) )

   With *SLH

      ; Marquage du bloc
      \iMark = *SLH
      
      ; Ecriture des dimensions g�r�es
      \hQty  = xFormat
      \vQty  = yFormat
      
      ; Ecriture et allocation des blocs de donn�es
      \hData = AllocateMemory(\hQty * SizeOf(SLINEGRADE) )      
      \vData = AllocateMemory(\vQty * SizeOf(SLINEGRADE) )

      ; R�partition des adresses
      *SLHG = \hData
      *SLVG = \vData      

   EndWith
;-
   ; 2) Pr�paration des d�grad�s horizontaux
   For i = 1 To xFormat
         
      With *SLHG\D[i - 1]
      
         ; On cr�e le tampon alpha
         \GradeBmp    = AllocAlphaBuffer(i, 2)
         ; On y dessine le d�grad�
            For j = 0 To (i - 1)
               Attribut = (256 / i) * j
               PokeL(\GradeBmp + 8 + (j * 4), $FFFFFF | (Attribut << 24) )
               PokeL((\GradeBmp + 8 + (j * 4) ) + (i * 4), $FFFFFF | ((Attribut ! $FF) << 24) )
            Next j
         ; Et on fabrique l'image 
         \HndGradeBmp = CreateAlphaHandle(\GradeBmp)
    
      EndWith
      
   Next i
   
   ; 3) Pr�paration des d�grad�s verticaux
   For i = 1 To yFormat
         
      With *SLVG\D[i - 1]
      
         ; On cr�e le tampon alpha
         \GradeBmp    = AllocAlphaBuffer(2, i)
         ; On y dessine le d�grad�
            For j = \GradeBmp + 8 To (\GradeBmp + 7) + ((4 * 2) * i) Step 4
               PokeL(j, $FFFFFFFF)
            Next j
         ; Et on fabrique l'image 
         \HndGradeBmp = CreateAlphaHandle(\GradeBmp)
    
      EndWith
      
   Next i
   
   ProcedureReturn *SLH
EndProcedure

Procedure SLineStop(*SLH.SLINEHEADER)
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 
; G�re la lib�ration m�moire de la gestion des lignes douces
; ��������������������������������������; ����������������������������������������������������������
; Entr�e : Pointeur de gestion
; ������   
;
; Remarque : Surtout ne pas se tromper de pointeur sinon la 
; ��������   proc�dure SLineStop() ne peut s'ex�cuter
;            correctement
;            /!\ Risque de crash hard /!\
;
;            S'utilise en fin de programme.
;____________________________________________________________________________ 
;���������������������������������������������������������������������������� 

   ; Pointeurs de bloc:      
   Protected *SLHG.SLINEBODY
   Protected *SLVG.SLINEBODY
   
   ; Variable locale pour la boucle
   Protected i.L

   If *SLH\iMark = *SLH ; V�rification d'identit�
     
      With *SLH
      
         ; R�partition des adresses
         *SLHG = \hData
         *SLVG = \vData      

      EndWith

      ; 3) Destruction des d�grad�s horizontaux
      For i = 1 To xFormat
         
         With *SLHG\D[i - 1]
      
            ; On lib�re le tampon alpha
            FreeMemory(\GradeBmp)
            ; Et on d�truit le handle
            DeleteObject_(\HndGradeBmp)
    
         EndWith
      
      Next i
   
      ; 2) Destruction des d�grad�s verticaux
      For i = 1 To yFormat
         
         With *SLVG\D[i - 1]
      
            ; On lib�re le tampon alpha
            FreeMemory(\GradeBmp)
            ; Et on d�truit le handle 
            DeleteObject_(\HndGradeBmp)
    
         EndWith
      
      Next i
     
      ; 1) Destruction de l'en-t�te
     
      With *SLH
       
         ; Destruction des blocs de donn�es
         FreeMemory(\hData)
         FreeMemory(\vData)
         
         ; Destruction du bloc d'en-t�te
         FreeMemory(\iMark)

      EndWith
   
   EndIf
     
EndProcedure


;- Fonction

Procedure SLine(*SLH.SLINEHEADER, x.L, y.L, dx.L, dy.L, c.L)
   Protected n.L
   Protected StepValue.L
   Protected RestValue.L
   Protected Value.L
   Protected *SLHG.SLINEBODY
   Protected *SLVG.SLINEBODY
   With *SLH      
      ; R�partition des adresses
      *SLHG = \hData
      *SLVG = \vData      
   EndWith   
   If dx > 0
      If dy < 0
         If dx > dy
            StepValue = Abs(dx / dy)
            RestValue = dx - (StepValue * dy)
            ;Debug StepValue
            ;End
            For n = y To (y + (dy + 1) ) Step -1
               If RestValue
                  RestValue - 1
                  Value = StepValue + 1
               Else
                  Value = StepValue
               EndIf
               DrawAlphaImage(*SLHG\D[Value]\HndGradeBmp, x, n)
               Line(x, n, Value, 0, #White)
               x + Value
            Next n
         EndIf
      Else
         If dy = 0
            Line(x, y, dx, dy, c)
         Else
            ; dy > 0
         EndIf
      EndIf
   EndIf
EndProcedure

;- Miscellaneous

ProcedureDLL.l ColorBlending(Couleur1.l, Couleur2.l, Echelle.f) ; M�langer 2 couleurs 
  Protected Rouge, Vert, Bleu, Rouge2, Vert2, Bleu2 
  
  Rouge = Couleur1 & $FF 
  Vert = Couleur1 >> 8 & $FF 
  Bleu = Couleur1 >> 16 
  Rouge2 = Couleur2 & $FF 
  Vert2 = Couleur2 >> 8 & $FF 
  Bleu2 = Couleur2 >> 16 
  
  Rouge = Rouge * Echelle + Rouge2 * (1-Echelle) 
  Vert = Vert * Echelle + Vert2 * (1-Echelle) 
  Bleu = Bleu * Echelle + Bleu2 * (1-Echelle) 
  
  ProcedureReturn (Rouge | Vert <<8 | Bleu << 16) 
EndProcedure

Procedure CircleAA(X, Y, Radius, Color, Thickness = 1, Mode = #PB_2DDrawing_Default) 
  Protected n, nn, Distance.f, Application.f, Couleur_Fond.l 
  If Mode & #PB_2DDrawing_Outlined ; Cercle vide 
    ; on dessine 1/4 du cercle et on duplique pour le reste 
    For n = 0 To Radius 
      For nn = 0 To Radius 
        Distance.f = Sqr(n * n + nn * nn) 
        If Distance <= Radius And Distance > Radius - 1 
          Application.f = Abs(Radius - 1 - Distance) 
          Couleur_Fond = Point(X + n, Y + nn) 
          Plot(X + n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y + nn) 
          Plot(X - n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X + n, Y - nn) 
          Plot(X + n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y - nn) 
          Plot(X - n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
        ElseIf Distance <= Radius - Thickness And Distance > Radius - Thickness - 1 
          Application.f = Abs(Radius - Thickness - Distance) 
          Couleur_Fond = Point(X + n, Y + nn) 
          Plot(X + n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y + nn) 
          Plot(X - n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X + n, Y - nn) 
          Plot(X + n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y - nn) 
          Plot(X - n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
        ElseIf Distance <= Radius - 1 And Distance > Radius - Thickness 
          Plot(X + n, Y + nn, Color) 
          Plot(X - n, Y + nn, Color) 
          Plot(X + n, Y - nn, Color) 
          Plot(X - n, Y - nn, Color) 
        EndIf 
      Next 
    Next 
  Else ; Cercle plein 
    ; on dessine 1/4 du cercle et on duplique pour le reste 
    For n = 0 To Radius 
      For nn = 0 To Radius 
        Distance.f = Sqr(n * n + nn * nn) 
        If Distance <= Radius And Distance > Radius - 1 
          Application.f = 1 - (Radius - Distance) 
          Couleur_Fond = Point(X + n, Y + nn) 
          Plot(X + n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y + nn) 
          Plot(X - n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X + n, Y - nn) 
          Plot(X + n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y - nn) 
          Plot(X - n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
        ElseIf Distance <= Radius - 1 
          Plot(X + n, Y + nn, Color) 
          Plot(X - n, Y + nn, Color) 
          Plot(X + n, Y - nn, Color) 
          Plot(X - n, Y - nn, Color) 
        EndIf 
      Next 
    Next 
  EndIf 
EndProcedure 

Procedure EllipseAA(X, Y, RadiusX, RadiusY, Color, Thickness = 1, Mode = #PB_2DDrawing_Default) 
  Protected n, nn, Distance.f, Application.f, Couleur_Fond.l, Ellispse_Rayon.f, Ellipse_E.f 
  ; Pr�cacul de l'�quation de l'ellipse 
  If RadiusX > RadiusY 
    Ellipse_E = Sqr(RadiusX * RadiusX - RadiusY * RadiusY) / RadiusX 
  Else 
    Ellipse_E = Sqr(RadiusY * RadiusY - RadiusX * RadiusX) / RadiusY 
  EndIf 
  Ellipse_E * Ellipse_E 
  If Mode & #PB_2DDrawing_Outlined ; ellipse vide 
    ; on dessine 1/4 de l'ellipse et on duplique pour le reste 
    For n = 0 To RadiusX 
      For nn = 0 To RadiusY 
        Distance.f = Sqr(n * n + nn * nn) 
        If RadiusX > RadiusY 
          If n 
            Ellipse_CosAngle.f = n / Distance 
            Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle)) 
          Else 
            Ellispse_Rayon = RadiusY 
          EndIf 
        Else 
          If nn 
            Ellipse_CosAngle.f = nn / Distance 
            Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle)) 
          Else 
            Ellispse_Rayon = RadiusX 
          EndIf 
        EndIf 
        If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1 
          Application.f = Abs(Ellispse_Rayon - 1 - Distance) 
          Couleur_Fond = Point(X + n, Y + nn) 
          Plot(X + n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y + nn) 
          Plot(X - n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X + n, Y - nn) 
          Plot(X + n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y - nn) 
          Plot(X - n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
        ElseIf Distance <= Ellispse_Rayon - Thickness And Distance > Ellispse_Rayon - Thickness - 1 
          Application.f = Abs(Ellispse_Rayon - Thickness - Distance) 
          Couleur_Fond = Point(X + n, Y + nn) 
          Plot(X + n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y + nn) 
          Plot(X - n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X + n, Y - nn) 
          Plot(X + n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y - nn) 
          Plot(X - n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
        ElseIf Distance <= Ellispse_Rayon - 1 And Distance > Ellispse_Rayon - Thickness 
          Plot(X + n, Y + nn, Color) 
          Plot(X - n, Y + nn, Color) 
          Plot(X + n, Y - nn, Color) 
          Plot(X - n, Y - nn, Color) 
        EndIf 
      Next 
    Next 
  Else ; ellipse pleine 
    ; on dessine 1/4 de l'ellipse et on duplique pour le reste 
    For n = 0 To RadiusX 
      For nn = 0 To RadiusY 
        Distance.f = Sqr(n * n + nn * nn) 
        If RadiusX > RadiusY 
          If n 
            Ellipse_CosAngle.f = n / Distance 
            Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle)) 
          Else 
            Ellispse_Rayon = RadiusY 
          EndIf 
        Else 
          If nn 
            Ellipse_CosAngle.f = nn / Distance 
            Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle)) 
          Else 
            Ellispse_Rayon = RadiusX 
          EndIf 
        EndIf 
        If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1 
          Application.f = 1 - (Ellispse_Rayon - Distance) 
          Couleur_Fond = Point(X + n, Y + nn) 
          Plot(X + n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y + nn) 
          Plot(X - n, Y + nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X + n, Y - nn) 
          Plot(X + n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
          Couleur_Fond = Point(X - n, Y - nn) 
          Plot(X - n, Y - nn, ColorBlending(Couleur_Fond, Color, Application)) 
        ElseIf Distance <= Ellispse_Rayon - 1 
          Plot(X + n, Y + nn, Color) 
          Plot(X - n, Y + nn, Color) 
          Plot(X + n, Y - nn, Color) 
          Plot(X - n, Y - nn, Color) 
        EndIf 
      Next 
    Next 
  EndIf 
EndProcedure 

Procedure LineAA(X, Y, Width, Hight, Color, Thickness = 1) 
  Protected SensX, SensY, n, nn, Epaisseur.f, x2.f, y2.f, Couleur_Fond.l, Application.f, Distance.f 
  ; On mets la droite toujours dans le m�me sens pour l'analyse 
  ; La sauvegarde du sens permettra de dessiner la droite ensuite dans le bon sens 
  If Width >= 0 
    SensX = 1 
  Else 
    SensX = -1 
    Width = - Width 
  EndIf 
  If Hight >= 0 
    SensY = 1 
  Else 
    SensY = -1 
    Hight = - Hight 
  EndIf 
  
  
  ; Demi �paisseur de la ligne 
  Epaisseur.f = Thickness / 2 
  
  ; calcul pour le changement de rep�re qui permet de connaitre l'�paisseur du trait et de g�rer l'AA 
  Distance.f = Sqr(Width * Width + Hight * Hight) 
  CosAngle.f = Width / Distance 
  SinAngle.f = -Sin(ACos(CosAngle)) 
  
  ; Dessin de la ligne 
  For n = -Thickness To Width + Thickness 
    For nn = -Thickness To Hight + Thickness 
      
      ; changement de base 
      ; les y repr�sentent l'�paisseur de la ligne 
      x2 = n * CosAngle - nn * SinAngle 
      y2 = Abs(n * SinAngle + nn * CosAngle) 
      
      If y2 <= Epaisseur + 0.5 
        Application =  0.5 + Epaisseur - y2 
        If Application > 1 
          Application = 1 
        EndIf 
        If x2 > -1 And x2 < Distance + 1 
          If x2 < 0 
            Application * (1 + x2) 
          ElseIf x2 > Distance 
            Application * (1 - x2 + Distance) 
          EndIf 
        Else 
          Application = 0 
        EndIf 
        If Application > 0 
          If Application < 1 
            Couleur_Fond = Point(X + n, Y + nn) 
            Plot(X + n * SensX, Y + nn * SensY, ColorBlending(Color, Couleur_Fond, Application)) 
          Else 
            Plot(X + n * SensX, Y + nn * SensY, Color) 
          EndIf 
        EndIf 
      EndIf 
      
    Next 
  Next 
  
EndProcedure 

;- D�marrage

Define *SmoothLine = SLineStart(64, 32)

;/ Test des fonctions de dessin avec Anti-Aliazing ( AA ) 
; Cr�ation de la fen�tre et de la GadgetList 
If OpenWindow(0, 0, 0, 500, 500, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0 ;Or CreateGadgetList(WindowID(0)) = 0 
  End 
EndIf 

BColor = #Black
FColor = #White

CreateImage(0, 500, 500) 
StartDrawing(ImageOutput(0)) 
  ; Un joli fond 
  #Carreau = 25 
  For n = 0 To 500 Step #Carreau 
    For nn = 0 To 500 Step #Carreau 
      If ((n + nn) / #Carreau) & %1 = %1 
        Box(n, nn, #Carreau, #Carreau, BColor) 
      Else 
        Box(n, nn, #Carreau, #Carreau, BColor) 
      EndIf 
    Next 
  Next 
  
  ; Dessin de Cercle 
  CircleAA(100, 100, 70, FColor) 
  CircleAA(250, 100, 50, FColor, 1, #PB_2DDrawing_Outlined) 
  CircleAA(250, 100, 70, FColor, 3, #PB_2DDrawing_Outlined) 
  
  ; Dessin d'une ellipse 
  EllipseAA(400, 100, 40, 60, FColor, 2, #PB_2DDrawing_Outlined) 
  EllipseAA(400, 100, 50, 70, FColor, 1, #PB_2DDrawing_Outlined) 
  EllipseAA(400, 100, 30, 20, FColor) 
  
  
  
  ; Dessin de ligne 
  For n = 0 To 150 Step 30 
    LineAA(20, 200, 150, n, FColor) 
  Next 
  For n = 0 To 120 Step 30 
    LineAA(20, 200, n, 150, FColor) 
  Next 
  Epaisseur = 2 
  For n = 0 To 150 Step 30 
    LineAA(200, 200, 150, n, FColor, Epaisseur) 
    Epaisseur + 1 
  Next 
  Epaisseur = 2 
  For n = 0 To 120 Step 30 
    LineAA(200, 200, n, 150, FColor, Epaisseur) 
    Epaisseur + 1 
  Next 
  LineAA(10, 10, 400, 1, FColor)
  Line(10, 20, 400, 1, FColor)  
;  LineAO(10, 30, 400, 1, FColor)
;  sprite()
t1 = ElapsedMilliseconds()
For i = 1 To 10
   ;For i = 0 To 89 Step 1
   ;   a.F = i * 2.0 * #PI / 360.0
   ;   Line(40, 400, Cos(a) * 320, 0 - Sin(a) * 320, #Red)
   ;Next i
   ;For i = 0 To 89 Step 1
   ;   a.F = i * 2.0 * #PI / 360.0
   ;   SLine(*SmoothLine, 40, 400, Cos(a) * 320, 0 - Sin(a) * 320, #White)
   ;Next i
   SLine(*SmoothLine, 40, 440, 320, 0 - 20, #White)
Next
t2 = ElapsedMilliseconds()
For i = 1 To 10
   LineAA(40, 420, 320, 0-10, #White)
Next
t3 = ElapsedMilliseconds()
StopDrawing() 

ImageGadget(0, 0, 0, 300, 300, ImageID(0)) 

MessageRequester("", "LSI:" + Str(t3 - t2) + "ms" + Chr(10) + "OLL:" + Str(t2 - t1) + "ms")
Repeat 
  Event = WaitWindowEvent() 
  
  Select Event 
    Case #PB_Event_Menu 
      Select EventMenu() ; Menus 
          
      EndSelect 
      
    Case #PB_Event_Gadget
Répondre