@@ -243,7 +243,7 @@ context
243
243
244
244
### Color
245
245
246
- You can select different color styles to paint your path: a color, a linear gradient, a radial gradient and a bitmap .
246
+ You can select different color styles to paint your path: a color, a linear gradient, a radial gradient a bitmap and a mesh gradient .
247
247
248
248
#### Single color.
249
249
@@ -253,6 +253,10 @@ context sourceColor: (Color yellow alpha: 0.2);
253
253
254
254
#### Linear gradient.
255
255
256
+ Generally speaking, a gradient is a smooth transition of colors defined by two
257
+ or more stop-colors. In the case of a linear gradient, this transition is defined
258
+ by a straight line.
259
+
256
260
``` smalltalk
257
261
gradient := AeCairoLinearGradientPattern
258
262
from: 0 @ 0
@@ -265,6 +269,16 @@ context source: gradient;
265
269
266
270
#### Radial gradient.
267
271
272
+ In the case of a radial gradient, the transition is defined by a center and a
273
+ radius, between the two circles defined by innerCirle and outer circle
274
+ Colors expand evenly in all directions from the inner center of the inner circle
275
+ to outside of the outer circle. Before using the gradient pattern, a number of
276
+ color stops should be defined
277
+
278
+ The coordinates here are in pattern space. For a new pattern, pattern space is
279
+ identical to user space, but the relationship between the spaces can be changed
280
+ with ` AeCairoPattern >> matrix: ` .
281
+
268
282
``` smalltalk
269
283
gradient := AeCairoRadialGradientPattern
270
284
innerCenter: 50 @ 50
@@ -277,6 +291,72 @@ gradient := AeCairoRadialGradientPattern
277
291
context source: gradient.
278
292
```
279
293
294
+ ### Mesh gradient
295
+
296
+ A mesh gradient is defined by a set of colors and control points. The most basic
297
+ type of mesh gradient is a Gouraud-shading triangle mesh.
298
+
299
+ ``` smalltalk
300
+ | aSurface aContext aMeshPattern |
301
+ aSurface := AeCairoImageSurface extent: 100 @ 100.
302
+ aContext := aSurface newContext.
303
+
304
+ aMeshPattern := AeCairoMeshPattern new.
305
+ aMeshPattern
306
+ beginPatch;
307
+ moveTo: 50 @ 0;
308
+ lineTo: 100 @ 100;
309
+ lineTo: 0 @ 100;
310
+ cornerColors: {
311
+ Color red alpha: 0.5.
312
+ Color green.
313
+ Color blue };
314
+ endPatch.
315
+
316
+ aContext
317
+ sourceColor: Color yellow;
318
+ paint;
319
+ source: aMeshPattern;
320
+ paint.
321
+
322
+ ^ aSurface
323
+ ```
324
+
325
+ A more sophisticated patch of mesh gradient is a Coons patch. A Coons patch is
326
+ a quadrilateral defined by 4 cubic Bézier curve and 4 colors, one for each vertex.
327
+ A Bézier curve is defined by 4 points, so we have a total of 12 control points
328
+ (and 4 colors) in a Coons patch.
329
+
330
+ ``` smalltalk
331
+ | aSurface aContext aMeshPattern |
332
+ aSurface := AeCairoImageSurface extent: 150 @ 110.
333
+ aContext := aSurface newContext.
334
+
335
+ aMeshPattern := AeCairoMeshPattern new.
336
+ aMeshPattern
337
+ beginPatch;
338
+ moveTo: 45 @ 12;
339
+ curveVia: 69 @ 24 via: 173 @ -15 to: 115 @ 50;
340
+ curveVia: 127 @ 66 via: 174 @ 47 to: 148 @ 104;
341
+ curveVia: 65 @ 58 via: 70 @ 69 to: 18 @ 103;
342
+ curveVia: 42 @ 43 via: 63 @ 45 to: 45 @ 12;
343
+ cornerColors: {
344
+ Color red.
345
+ Color green.
346
+ Color blue.
347
+ Color red alpha: 0.5 };
348
+ endPatch.
349
+
350
+ aContext
351
+ sourceColor: Color yellow;
352
+ paint;
353
+ translateByX: -15 y: 0;
354
+ source: aMeshPattern;
355
+ paint.
356
+
357
+ ^ aSurface
358
+ ```
359
+
280
360
#### Bitmap.
281
361
282
362
``` smalltalk
0 commit comments