BGRABitmap tutorial 7/fr: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 1 | + | Ce tutoriel montre comment utiliser les splines et les courbes de Bézier. | |
| 13 | 2 | ||
| 14 | 3 | ### Création d'un nouveau projet | |
| 15 | 4 | ||
| 16 | - | ||
| 5 | + | Créez un nouveau projet et ajoutez la référence à [[BGRABitmap]], de la même façon que dans [[BGRABitmap tutorial/fr|le premier tutoriel]]. | |
| 17 | 6 | ||
| 18 | 7 | ### Dessiner une spline ouverte | |
| 19 | 8 | ||
| 20 | - | ||
| 21 | - | ||
| 9 | + | Avec l'inspecteur d'objet, ajoutez un gestionnaire *OnPaint* avec : | |
| 10 | + | ||
| 11 | + | ``` pascal | |
| 22 | 12 | procedure TForm1.FormPaint(Sender: TObject); | |
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 13 | + | var | |
| 14 | + | image: TBGRABitmap; | |
| 15 | + | pts: array of TPointF; | |
| 16 | + | storedSpline: array of TPointF; | |
| 17 | + | c: TBGRAPixel; | |
| 18 | + | ||
| 19 | + | begin | |
| 20 | + | image := TBGRABitmap.Create(ClientWidth,ClientHeight,ColorToBGRA(ColorToRGB(clBtnFace))); | |
| 21 | + | c := ColorToBGRA(ColorToRGB(clWindowText)); | |
| 22 | + | ||
| 23 | + | //rectangular polyline | |
| 24 | + | setlength(pts,4); | |
| 25 | + | pts[0] := PointF(50,50); | |
| 26 | + | pts[1] := PointF(150,50); | |
| 27 | + | pts[2] := PointF(150,150); | |
| 28 | + | pts[3] := PointF(50,150); | |
| 29 | + | image.DrawPolylineAntialias(pts,BGRA(255,0,0,150),1); | |
| 30 | + | ||
| 31 | + | //compute spline points and draw as a polyline | |
| 32 | + | storedSpline := image.ComputeOpenedSpline(pts); | |
| 33 | + | image.DrawPolylineAntialias(storedSpline,c,1); | |
| 34 | + | ||
| 35 | + | image.Draw(Canvas,0,0,True); | |
| 36 | + | image.free; | |
| 37 | + | end; | |
| 48 | 38 | ``` | |
| 49 | 39 | ||
| 50 | - | ||
| 40 | + | Il y a deux lignes qui dessinent la spline. La première calcule les points de la spline et la seconde les dessine. Notez qu'il y a une fonction spécifique pour les splines ouvertes. | |
| 51 | 41 | ||
| 52 | 42 | ### Dessiner une spline fermée | |
| 53 | 43 | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 44 | + | Avant *image.Draw*, ajoutez ces lignes : | |
| 45 | + | ||
| 46 | + | ``` pascal | |
| 47 | + | for i := 0 to 3 do | |
| 48 | + | pts[i].x += 200; | |
| 49 | + | image.DrawPolylineAntialias(pts,BGRA(255,0,0,150),1); | |
| 50 | + | ||
| 51 | + | storedSpline := image.ComputeClosedSpline(pts); | |
| 52 | + | image.DrawPolygonAntialias(storedSpline,c,1); | |
| 62 | 53 | ``` | |
| 63 | 54 | ||
| 64 | - | ||
| 55 | + | Allez avec le curseur texte sur l'identifiant 'i' et appuyez *Ctrl-Shift-C* pour ajouter la déclaration de la variable. Cette boucle déplace les points vers la droite. | |
| 65 | 56 | ||
| 66 | - | ||
| 57 | + | Les deux nouvelles lignes dessinent une spline fermée. Notez la fonction spécifique pour calculer une spline fermée et l'appel à *DrawPolygonAntialias*. | |
| 67 | 58 | ||
| 68 | - | ||
| 69 | - | ||
| 59 | + | Vous pouvez éviter d'utiliser une variable pour stocker les points de la spline comme cela : | |
| 60 | + | ||
| 61 | + | ``` pascal | |
| 70 | 62 | image.DrawPolygonAntialias(image.ComputeClosedSpline(pts),c,1); | |
| 71 | 63 | ``` | |
| 72 | 64 | ||
| 73 | - | ||
| 65 | + | Cependant, si vous procédez ainsi, vous ne pouvez pas utiliser les points calculés plus d'une fois : ils devront être recalculés à chaque fois que vous les utiliser. | |
| 74 | 66 | ||
| 75 | 67 | ### Exécution du programme | |
| 76 | 68 | ||
| 77 | - | ||
| 69 | + | Le programme dessine deux splines : une ouverte à gauche et une fermée à droite. | |
| 78 | 70 | ||
| 79 | - | ||
| 71 | + |  | |
| 80 | 72 | ||
| 81 | - | ||
| 73 | + | Notez que la spline passe par tous les points. Si vous voulez que la courbe reste à l'intérieur, ou définir des tangentes, vous devez définir des points de contrôle qui sont disponibles avec les courbes de Bézier. | |
| 82 | 74 | ||
| 83 | 75 | ### Utiliser les courbes de Bézier | |
| 84 | 76 | ||
| 85 | - | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - | ||
| 77 | + | Avant image.Draw, ajoutez ces lignes : | |
| 78 | + | ||
| 79 | + | ``` pascal | |
| 80 | + | storedSpline := image.ComputeBezierSpline([BezierCurve(PointF(50,50),PointF(150,50),PointF(150,100)), | |
| 81 | + | BezierCurve(PointF(150,100),PointF(150,150),PointF(50,150))]); | |
| 82 | + | image.DrawPolylineAntialias(storedSpline,c,2); | |
| 90 | 83 | ``` | |
| 91 | 84 | ||
| 92 | - | ||
| 85 | + | La fonction *BezierCurve* définit une courbe avec une origine et une destination, et un ou deux points de contrôle. Dans l'exemple, il n'y a qu'un point de contrôle. Les points de contrôles sont définis de telle façon que la courbe soit tangente au rectangle défini précédemment. | |
| 93 | 86 | ||
| 94 | - | ||
| 87 | + | Une spline Bézier est simplement une suite de courbes de Bézier. Ainsi la fonction *ComputeBezierSpline* concatène un tableau de courbes de Bézier. Ici, vous construisez un joli demi-tour avec deux courbes. | |
| 95 | 88 | ||
| 96 | 89 | ### Exécution du programme | |
| 97 | 90 | ||
| 98 | - | ||
| 91 | + | Vous devriez voir une courbe de Bézier en gras à l'intérieur du rectangle gauche. | |
| 99 | 92 | ||
| 100 | - | ||
| 93 | + |  | |
| 101 | 94 | ||
| 102 | 95 | [[BGRABitmap tutorial 6/fr|Tutoriel précédent (styles de lignes)]] [[BGRABitmap tutorial 8/fr|Tutoriel suivant (textures)]] | |
| 103 | 96 | ||
| 104 | 97 | --- | |
| 105 | - | ||
| 98 | + | *From the Free Pascal wiki, page "BGRABitmap tutorial 7/fr", as it stood on 2020-02-10 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
