HTML5 canvas filling and stroke (fill and stroke)
Demonstrate HTML5 canvas fill and stroke text effects, based on how to implement canvas
Current texture filling and stroke.
I. Color filling and stroke
Color filling can be achieved through fillstyle, and stroke color can be achieved through strokestyle. Simple Example
As follows:
// Fill and stroke text
CTX. font = '60pt calibri ';
CTX. linewidth = 3;
CTX. strokestyle =
'Green ';
CTX. stroketext ('Hello world! ', 20,100 );
CTX. fillstyle =
'Red ';
CTX. filltext ('Hello world! ', 20,100 );
2. Texture filling and stroke
HTML5 canvas also supports texture filling. By loading a texture image, you can create a paint brush mode and
The texture mode API is CTX. createpattern (imagetexture, "repeat"). The second parameter supports four
Values, which are "Repeat-X", "Repeat-y", "repeat", and "no-repeat" respectively indicate that the textures are
The X axis, Y axis, and XY are repeated or not repeated. The code for texture stroke and filling is as follows:
VaRWoodfill = CTX. createpattern (imagetexture, "repeat ");
CTX. strokestyle = woodfill;
CTX. stroketext ('Hello world! ', 20,200 );
// Fill rectangle
CTX. fillstyle = woodfill;
CTX. fillrect (60,240,260,440 );
Texture Image:
Iii. Running Effect
Code:
<!DOCTYPE html>