Sign in Join
Wiki copytemporary

Drawing with canvas

Deutsch · English · Français · 中文(中国)

Drawing with canvas can be done using several procedures e.g.

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:

pascal
Canvas.Brush.Color:= clRed;
      Canvas.Ellipse(195, 117, 205, 128);
      Canvas.Brush.Color:= clBlue;
      Canvas.Rectangle (192, 130,208,160);
      Canvas.Brush.Color:= clGreen;
      Canvas.Rectangle (187, 130,191,162);
      Canvas.Brush.Color:= clYellow;
      Canvas.Rectangle (209, 130,213,162);
      Canvas.Brush.Color:= clMaroon;
      Canvas.Rectangle (193,161,199,200);
      Canvas.Brush.Color:= clPurple;
      Canvas.Rectangle (201,161,207,200);

or shorter:

pascal
with Canvas do begin
        Brush.Color:= clRed;
        Ellipse(195, 117, 205, 128);
        Brush.Color:= clBlue;
        Rectangle (192, 130,208,160);
        Brush.Color:= clGreen;
        Rectangle (187, 130,191,162);
        Brush.Color:= clYellow;
        Rectangle (209, 130,213,162);
        Brush.Color:= clMaroon;
        Rectangle (193,161,199,200);
        Brush.Color:= clPurple;
        Rectangle (201,161,207,200);
      end;

This will give something like this: canvas.png


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.

Revision 2, last changed by WikiArchive .

Edited on wiki.freepascal.org by 10 people, 2010–2021

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
Leo tecnologicaNew page: '''Line''' (x1, y1, x2, y2)-> draw a line from point (x1, y1) to (x2, y2) '''Rectangle''' (x1, y1, x2, y2)-> draw a rectangle with a vertex at the point (x1, y1) and the opposite at the p...
Leo tecnologica
Leo tecnologica
Leo tecnologica
Leo tecnologica
Chronoscategory
VincentText replace - "delphi>" to "syntaxhighlight>" (minor)
Jwdietrich
Swen (minor)
BigChimp
FTurtle
FTurtlearticle is not part of Tao Yue's Tuturial
BlaiseP
BlaiseP
WpDon't paint in OnClickCode! Fix coordinate of bottom right pixel of form. Avoid using form variable in form code.
TrevFixed syntax highlighting (minor)
TrevFixed typos (minor)
TrevFix broken page link - removed duped content at that link
TrevCorrect canvas image (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.