DiFi: Fast Distance Field Computation using Graphics Hardware
Turtle Graphics - poullis.orgFunctions from the turtle Module •Functions provided –t.up( ),...
Transcript of Turtle Graphics - poullis.orgFunctions from the turtle Module •Functions provided –t.up( ),...
An Introduction to Programming Using PythonDavid I. Schneider
Turtle Graphics
Section 3Chapter 6
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Coordinates
• Objects and methods from the module named "turtle."
• Given statements,window appears
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
FIGURE 6.12 Turtle graphics
window.
Coordinates
FIGURE 6.13 Coordinate system for canvas.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Coordinates
• Think of the chevron as a small turtle with a pen attached to its tail
• Python statements– Raise, lower “tail”– Change color– Move turtle in variety of ways
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Functions from the turtle Module• Functions provided
– t.up( ), t.down( )– t.hideturtle( )– t.forward(distance), t.backward(distance)– t.goto(x,y)– t.pencolor(colorName)– t.setheading(deg)– t.left(deg), t.right(deg)– t.dot(diameter, colorName)
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Rectangles
FIGURE 6.14 A general rectangle.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Rectangles
• Two possible functions to draw rectangles
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Rectangles
• Two possible functions to draw rectangles
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Rectangles
• Example 1: Program draws a rectangle having a red border and a yellow interior.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Rectangles
• Example 1:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Flags
• Example 2: program draws flag shown on the right.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Flags
• Example 2:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Flags
• Example 2:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Flags
FIGURE 6.16 Five-Pointed Star
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Flags• Example 3: program draws the five-
pointed star in Fig. 6.16 (b).
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The write Method
• Given s, a string as argument in• Displays the string s
– Bottom left corner of the string approximately at current position of the pen
• Other options
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The write Method
• Example 4: Program displays the word Python with different alignments.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Bar Charts
• Example 5: Program creates bar chart on the right.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Bar Charts
• Example 5:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Bar Charts
• Example 5:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Bar Charts
• Example 5:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Line Charts
• Tabular data can be visually displayed it in a line chart.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 6.3 Percentage of college freshmen who smoke.
Line Charts
• Example 6: Program uses data in Table 6.3 to create the line chart on the right
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Line Charts
• Example 6:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Line Charts
• Example 6:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Line Charts
• Example 6:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Line Charts
• Example 6:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
An Introduction to Programming Using PythonDavid I. Schneider
End
Section 3Chapter 6
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.