Sign in Join
Wiki copytemporary

BGRABitmap tutorial 11/fr: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Ce tutoriel montre comment combiner les transformations.
22
33### Transformation affine d'un dégradé radial
44
55Voici une transformation affine appliquée à un dégradé de la même façon qu'avec les textures :
66
77``` pascal
88uses BGRAGradientScanner, BGRATransform;
99
1010procedure TForm1.FormPaint(Sender: TObject);
1111var image: TBGRABitmap;
1212 grad: TBGRAGradientScanner;
1313 affine: TBGRAAffineScannerTransform;
1414begin
1515 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
1616
1717 grad := TBGRAGradientScanner.Create(BGRA(0,0,255),BGRAWhite,gtRadial,PointF(0,0),PointF(1,0),True,True);
1818
1919 affine := TBGRAAffineScannerTransform.Create(grad);
2020 affine.Scale(150,80);
2121 affine.RotateDeg(-30);
2222 affine.Translate(ClientWidth/2, ClientHeight/2);
2323
2424 image.Fill(affine);
2525
2626 affine.free;
2727 grad.free;
2828
2929 image.Draw(Canvas,0,0,True);
3030 image.free;
3131end;
3232```
3333
3434Le dégradé de base est radial, centré à l'origine (0,0) et de rayon 1.
3535
3636La transformation affine effectue les actions suivantes :
3737
3838- étirer le dégradé à une taille de 150x80 ;
3939- tourner de 30 degrés dans le sens inverse des aiguilles d'une montre ;
4040- centrer sur la fenêtre.
4141
4242L'instruction *Fill* dessine le résultat sur l'image.
4343
4444### Exécution du programme
4545
4646Vous devriez obtenir une ellipse avec un dégradé bleu et blanc.
4747
48-<figure>
49-<img src="BGRATutorial11a.png" title="BGRATutorial11a.png" />
50-<figcaption>BGRATutorial11a.png</figcaption>
51-</figure>
48+![](/wiki-images/a/a9/BGRATutorial11a.png)
5249
5350### Combiner avec un twirl
5451
5552Vous pouvez ajouter une autre transformation comme cela :
5653
5754``` pascal
5855var image: TBGRABitmap;
5956 grad: TBGRAGradientScanner;
6057 affine: TBGRAAffineScannerTransform;
6158 twirl: TBGRATwirlScanner;
6259begin
6360 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
6461
6562 grad := TBGRAGradientScanner.Create(BGRA(0,0,255),BGRAWhite,gtRadial,PointF(0,0),PointF(1,0),True,True);
6663
6764 affine := TBGRAAffineScannerTransform.Create(grad);
6865 affine.Scale(150,80);
6966 affine.RotateDeg(-30);
7067 affine.Translate(ClientWidth/2, ClientHeight/2);
7168
7269 twirl := TBGRATwirlScanner.Create(affine,Point(ClientWidth div 2, ClientHeight div 2),100);
7370 image.Fill(twirl);
7471 twirl.Free;
7572
7673 affine.free;
7774 grad.free;
7875
7976 image.Draw(Canvas,0,0,True);
8077 image.free;
8178end;
8279```
8380
8481Ici, vous créez une transformation de twirl et l'appliquez à la précédente.
8582
8683### Exécution du programme
8784
8885A présent, le centre du dégradé est tourbillonnant.
8986
90-<figure>
91-<img src="BGRATutorial11b.png" title="BGRATutorial11b.png" />
92-<figcaption>BGRATutorial11b.png</figcaption>
93-</figure>
87+![](/wiki-images/b/b0/BGRATutorial11b.png)
9488
9589### Utiliser un scanner personnalisé
9690
9791Vous pouvez avoir besoin de créer votre propre générateur de dégradés. Voici par exemple un dégradé multiplicateur :
9892
9993``` pascal
10094type
10195 { TBGRAMultiplyScanner }
10296
10397 TBGRAMultiplyScanner = class(TBGRACustomScanner)
10498 function ScanAt(X, Y: Single): TBGRAPixel; override;
10599 end;
106100
107101{ TBGRAMultiplyScanner }
108102
109103function TBGRAMultiplyScanner.ScanAt(X, Y: Single): TBGRAPixel;
110104 function cycle512(value: integer): integer; inline;
111105 begin
112106 result := value and 511;
113107 if result >= 256 then result := 511-result;
114108 end;
115109
116110var
117111 mul: integer;
118112begin
119113 mul := cycle512(round(x*y));
120114 result := BGRA(mul,mul,mul,255);
121115end;
122116```
123117
124118Il est dérivé de *TBGRACustomScanner* afin d'être utilisé pour le remplissage, et la fonction *ScanAt* est remplacée (*override*). Elle calcule le produit des deux coordonnées et fait un cycle de 512 (de 0 à 255 puis de 255 à 0).
125119
126120Dessinez-le à l'écran avec une simple transformation affine :
127121
128122``` pascal
129123var image: TBGRABitmap;
130124 grad: TBGRAMultiplyScanner;
131125 affine: TBGRAAffineScannerTransform;
132126begin
133127 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
134128
135129 grad := TBGRAMultiplyScanner.Create;
136130 affine := TBGRAAffineScannerTransform.Create(grad);
137131 affine.Scale(6,4);
138132 affine.Translate(ClientWidth/2, ClientHeight/2);
139133 image.Fill(affine);
140134 affine.free;
141135 grad.free;
142136
143137 image.Draw(Canvas,0,0,True);
144138 image.free;
145139end;
146140```
147141
148142### Exécution du programme
149143
150144Le résultat devrait ressembler à cela :
151145
152-<figure>
153-<img src="BGRATutorial11c.png" title="BGRATutorial11c.png" />
154-<figcaption>BGRATutorial11c.png</figcaption>
155-</figure>
146+![](/wiki-images/e/e0/BGRATutorial11c.png)
156147
157148### Rendons l'ensemble joli
158149
159150Ajoutez des couleurs en modifiant la procédure *ScanAt* du dégradé multiplicateur :
160151
161152``` pascal
162153var
163154 mul: integer;
164155begin
165156 mul := round(x*y);
166157 result := BGRA(cycle512(round(x*10)),cycle512(mul),cycle512(round(y*10)),255);
167158end;
168159```
169160
170161Les intensités rouge et bleue sont définies avec un cycle des positions x et y.
171162
172163Enfin, ajoutez une rotation :
173164
174165``` pascal
175166 affine := TBGRAAffineScannerTransform.Create(grad);
176167 affine.Scale(6,4);
177168 affine.RotateDeg(-30);
178169 affine.Translate(ClientWidth/2, ClientHeight/2);
179170```
180171
181-<figure>
182-<img src="BGRATutorial11d.png" title="BGRATutorial11d.png" />
183-<figcaption>BGRATutorial11d.png</figcaption>
184-</figure>
172+![](/wiki-images/e/e8/BGRATutorial11d.png)
185173
186174[[BGRABitmap tutorial 10/fr|Tutoriel précédent (plaquage de texture)]] [[BGRABitmap tutorial 12/fr|Tutoriel suivant (fonctions texte)]]
187175
188176---
189177*From the Free Pascal wiki, page "BGRABitmap tutorial 11/fr", as it stood on 2020-02-09 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).*

Back to history