- Python 2.6 Graphics Cookbook
- Mike Ohlson de Fine
- 252字
- 2021-04-09 22:39:37
Draw a five-pointed star using named variables to specify the polygon attributes so that all the points or vertexes or tips of the star are defined with reference to a single start position. We refer to this position as the anchor position.
The instructions used in recipe 1 should be used.
Just use the name star_polygon.py
when you write, save, and execute this program.
# star_polygon.py #>>>>>>>>>>>> from Tkinter import * root = Tk() root.title(Polygon') cw = 140 # canvas width ch = 80 # canvas height canvas_1 = Canvas(root, width=cw, height=ch, background="white") canvas_1.grid(row=0, column=1) # blue star, anchored to an anchor point. x_anchor = 15 y_anchor = 50 canvas_1.create_polygon(x_anchor, y_anchor,\ x_anchor + 20, y_anchor - 40,\ x_anchor + 30, y_anchor + 10,\ x_anchor, y_anchor - 30,\ x_anchor + 40, y_anchor - 20,\ fill="blue") root.mainloop() #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The results are given in the next screenshot, a polygon star.

The first position of the star is the point [x_anchor, y_anchor]
. All the other points are positive or negative additions to the position of the anchor point. This concept was introduced in the recipes for the three superimposed rectangles. This idea of drawing complicated shapes with reference to a point defined as a pair of named variables is very useful and is used extensively in the second half of this book.
To improve code readability, the pairs of x and y variables defining each point are laid out vertically making use of the line continuation character \ (backslash).
- vtiger CRM Beginner's Guide
- User Training for Busy Programmers
- 詳解AutoCAD 2022建筑設計(第6版)
- ChronoForms 3.1 for Joomla! site Cookbook
- 平面設計綜合教程:Photoshop+Illustrator+CorelDRAW +InDesign(微課版)
- 新編三維CAD習題集
- SolidWorks2014基礎實例教程
- Photoshop CC入門與進階
- Flash Facebook Cookbook
- 深入理解OpenCV:實用計算機視覺項目解析(原書第3版)
- Photoshop CS6標準教程(全視頻微課版)
- Implementing SugarCRM 5.x
- Liferay Portal Systems Development
- 高等院校電腦美術教材:CorelDRAW X7中文版基礎教程
- NetSuite OneWorld Implementation 2011 R2