| | |
Tkinter Triangle Art (Python)
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Another exercise in applied geometry. This time we use the Tkinter GUI canvas and its create_line() function to draw a triangle, or a series of connected triangles to create something that looks like fancy art work. You might be able to impress grandmama with that one!
# draw triangles with Tkinter canvas.create_line() # creates a fancy geometric design # tested with Python24 vegaseat 26jun2006 from Tkinter import * from math import sin, cos import time root = Tk() # set width and height of canvas w = 600 h = 350 # create the canvas for drawing c = Canvas(width=w, height=h, bg='yellow') c.pack() color_list = ['blue', 'red', 'black'] # accumulate the spokes drawings for spokes in range(3, 16): # loop through the color list color = color_list[spokes % 3] root.title("Spokes = " + str(spokes)) radians = 360 / (spokes * 57.29578) for x in range(spokes): for y in range(spokes): c.create_line((int)(sin(y * radians) * 225 + 300),(int)(cos(y * radians) * 145 + 170), (int)(sin(x * radians) * 225 + 300),(int)(cos(x * radians) * 145 + 170), fill=color) root.update() # delay each drawing a few seconds time.sleep(3) root.mainloop()
Similar Threads
- Code Snippet: Tkinter Sound (Python) (Python)
- Editing Album Art with python (Python)
- Python/Tkinter and the Web (Python)
- Listbox in Tkinter python (Python)
- 6 art domains , art-picasso.com art-monet.com art-dali.com art-matisse.com ... [ebay] (Domain Names for Sale)
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied alarm aliased basic beginner casino character code corners cx-freeze definedlines development dictionary digital dynamic editing error events examples excel exe file filename float format ftp function graphics gui handling homework ideas iframe import input java line linux list lists logging loop matching mouse newb number numbers numeric output parameters parsing path port prime program programming progressbar projects py py2exe pygame pyglet pyqt pysimplewizard python random recursion recursive return reverse schedule scrolledtext searchingfile shebang skinning sprite ssh statistics stdout string strings table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 variable voip windows wxpython



