☰ Contents · Computing

Text and shapes

Lessons 63–64 · 2 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 10, 1st edition. “Extremum-Press”, Tashkent, 2017
63

Placing other objects in a picture

Textbook: pp. 144–148
GoalPlaces text in a picture with TextOut, sets the font and uses and distinguishes the Arc (arc), Chord (segment) and Pie (sector) methods.
New words
TextOut: a method that writes text on the canvas at a given point · TextOutArc: an arc of an ellipse · ArcChord: an ellipse segment cut off by a straight line joining the ends of an arc · ChordPie: a sector, bounded by an arc and two radii · Pie
Explanation

To put text in a picture, Canvas.TextOut(x, y, 'text') is used: (x, y) are the coordinates of the upper left corner of the text. The look of the text is set with the Canvas.Font properties: Font.Size, Font.Color, Font.Name; the standard brush paints the background of the text, so for text without a background set Brush.Style := bsClear; Canvas.TextWidth('text') gives the width of the text and is used to centre it. For parts of an ellipse there are three methods that take eight numbers: Arc(x1, y1, x2, y2, x3, y3, x4, y4), Chord(…) and Pie(…). The first four numbers give the rectangle around the ellipse; (x3, y3) is a point on the starting ray from the centre and (x4, y4) a point on the ending ray. The line is drawn from the starting ray to the ending ray counterclockwise, so the order of the points matters. Arc draws only the arc, Chord draws the arc and the segment joining its ends, Pie draws the arc and two radii (a sector); Chord and Pie fill the inside with the brush.

Worked examples
An arc and a sector: Image1.Canvas.Arc(0, 0, 100, 100, 100, 50, 50, 0); – the centre is (50, 50); the starting ray goes east (100, 50), the ending ray north (50, 0): the upper right quarter arc. Image1.Canvas.Pie(0, 0, 100, 100, 50, 0, 100, 50); – the starting ray goes north and the ending ray east: counterclockwise it is three quarters, that is a 270° sector.
Text: Image1.Canvas.Font.Size := 14; Image1.Canvas.Font.Color := clRed; Image1.Canvas.Brush.Style := bsClear; Image1.Canvas.TextOut(20, 30, 'Salom'); – red text of size 14 starts at the point (20, 30). Chord(0, 0, 100, 100, 100, 50, 50, 0) draws and fills this quarter arc and the straight segment joining its ends.
Class activity

“The atlas of parts”: a pair draws 4 different parts of one circle with the three methods, writes the points of the starting and ending rays for each in advance and compares them with the picture.

Practice
1
What is the difference between Pie and Chord?
2
What are the semi-axes of the ellipse in Arc(0, 0, 100, 100, …)?
3
A full circle is 360°. How many degrees are three quarters?
4
Why is Brush.Style := bsClear written before TextOut?