Sign in Join
Wiki copytemporary

Drawing with canvas: what changed

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

OldNewLine
1-**Drawing with canvas** can be done using several procedures e.g.
2-
3-- [[Canvas line]], draws a line from coordinates (x1,y1) to (x2,y2)
4-- [[Canvas rectangle]], draws a rectangle from upper left (x1,y1) to lower right (x2,y2)
5-- [[Canvas ellipse]], draws an ellipse in a rectangle defined by (x1,y1) and (x2,y2). If x2-x1 = y2-y1, the ellipse will be a circle with radius (x2-x1)/2.
1+**Drawing with canvas** can be done using several procedures e.g.
62
7-In the Canvas object the `Brush` and `Pen` objects are defined, both with a `Color` property, which indicate the color that makes the fill and stroke of the various objects that are drawn. To paint an object of one color, the first thing is to change the brush and color, before giving the instruction to draw, the order of the statements is important. This would be the code, notice how the color is changed before drawing the ellipse:
3+ * [[Canvas line]], draws a line from coordinates (x1,y1) to (x2,y2)
4+ * [[Canvas rectangle]], draws a rectangle from upper left (x1,y1) to lower right (x2,y2)
5+ * [[Canvas ellipse]], draws an ellipse in a rectangle defined by (x1,y1) and (x2,y2). If x2-x1 = y2-y1, the ellipse will be a circle with radius (x2-x1)/2.
6+ * [[Canvas Arc]], Draws an arc of an ellipse.
7+ * [[Canvas Polygon]], Draws a filled polygon.
8+ * [[Canvas TextOut]], Draws text at a specified position.
9+ * [[Canvas DrawText]], Draws text with additional formatting options.
810
9-``` pascal
10- Canvas.Brush.Color:= clRed;
11- Canvas.Ellipse(195, 117, 205, 128);
12- Canvas.Brush.Color:= clBlue;
13- Canvas.Rectangle (192, 130,208,160);
14- Canvas.Brush.Color:= clGreen;
15- Canvas.Rectangle (187, 130,191,162);
16- Canvas.Brush.Color:= clYellow;
17- Canvas.Rectangle (209, 130,213,162);
18- Canvas.Brush.Color:= clMaroon;
19- Canvas.Rectangle (193,161,199,200);
20- Canvas.Brush.Color:= clPurple;
21- Canvas.Rectangle (201,161,207,200);
11+In the Canvas object the `Brush` and `Pen` objects are defined, both with a `Color` property, which indicate the color that makes the fill and stroke of the various objects that are drawn. To paint an object of one color, the first thing is to change the brush and color, before giving the instruction to draw, the order of the statements is important. This would be the code, notice how the color is changed before drawing the ellipse:
2212```
23-
24-or shorter:
13+Canvas.Brush.Color:= clRed;
14+ Canvas.Ellipse(195, 117, 205, 128);
15+ Canvas.Brush.Color:= clBlue;
16+ Canvas.Rectangle (192, 130,208,160);
17+ Canvas.Brush.Color:= clGreen;
18+ Canvas.Rectangle (187, 130,191,162);
19+ Canvas.Brush.Color:= clYellow;
20+ Canvas.Rectangle (209, 130,213,162);
21+ Canvas.Brush.Color:= clMaroon;
22+ Canvas.Rectangle (193,161,199,200);
23+ Canvas.Brush.Color:= clPurple;
24+ Canvas.Rectangle (201,161,207,200);
25+```
2526
26-``` pascal
27- with Canvas do begin
28- Brush.Color:= clRed;
29- Ellipse(195, 117, 205, 128);
30- Brush.Color:= clBlue;
31- Rectangle (192, 130,208,160);
32- Brush.Color:= clGreen;
33- Rectangle (187, 130,191,162);
34- Brush.Color:= clYellow;
35- Rectangle (209, 130,213,162);
36- Brush.Color:= clMaroon;
37- Rectangle (193,161,199,200);
38- Brush.Color:= clPurple;
39- Rectangle (201,161,207,200);
40- end;
27+or shorter:
4128```
29+with Canvas do begin
30+ Brush.Color:= clRed;
31+ Ellipse(195, 117, 205, 128);
32+ Brush.Color:= clBlue;
33+ Rectangle (192, 130,208,160);
34+ Brush.Color:= clGreen;
35+ Rectangle (187, 130,191,162);
36+ Brush.Color:= clYellow;
37+ Rectangle (209, 130,213,162);
38+ Brush.Color:= clMaroon;
39+ Rectangle (193,161,199,200);
40+ Brush.Color:= clPurple;
41+ Rectangle (201,161,207,200);
42+ end;
43+```
4244
43-This will give something like this: ![](/wiki-images/d/dd/Canvas.png)
45+This will give something like this: [![canvas.png](/wiki-images/d/d1/canvas.png)](</File:canvas.png>)
4446
4547---
46-*From the Free Pascal wiki, page "Drawing with canvas", as it stood on 2021-02-27 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).*
48+*From the Free Pascal wiki, page "Drawing with canvas", as the Internet Archive kept it on 2024-09-13, last changed on 2024-08-25. 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