Skip to content

Commit f79f1f2

Browse files
committed
graphics
1 parent 60b7216 commit f79f1f2

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

zella-graphics/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55

66
Home Page: [Python Programming: An Introduction to Computer Science](http://mcsp.wartburg.edu/zelle/python/)
77

8+
with [documentation](https://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html) and [examples](https://mcsp.wartburg.edu/zelle/python/ppics3/code/)
9+
810
There are links to three editions which have a little different code. Some functions from one edition don't exist in another.
911

1012
I use [Third Edition](http://mcsp.wartburg.edu/zelle/python/ppics3/index.html) (v.5)
1113

14+
[Source code](http://www.science.smith.edu/dftwiki/index.php/Zelle%27s_Graphics.py_for_Python_3) to see all classes and functions.
15+
1216
---
1317

14-
`Graphics` use `Tkinter` in background which has more usefull functions. But you have access to this functions too.
18+
`Graphics` uses `Tkinter` in background which has more useful functions. But you have access to this functions too.
19+
20+
---
1521

22+
Hands-on Python Tutorial >> [Graphics](http://anh.cs.luc.edu/handsonPythonTutorial/graphics.html)
1623

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
# date: 2020.05.29
4+
# It use after to animate point and you still can click window to close program
5+
6+
from graphics import * # PEP8: `import *` is not preferred
7+
import random
8+
9+
# --- functions ---
10+
11+
def move():
12+
dx = random.randint(-10, 10)
13+
dy = random.randint(-10, 10)
14+
pt.move(dx, dy)
15+
# move again after 100ms (0.1s)
16+
win.after(100, move)
17+
18+
# --- main ---
19+
20+
win = GraphWin("My Window",500,500)
21+
win.setBackground(color_rgb(0,0,0))
22+
23+
pt = Point(250, 250)
24+
pt.setOutline(color_rgb(255,255,0))
25+
pt.draw(win)
26+
27+
# move first time after 100ms (0.1s)
28+
win.after(100, move)
29+
30+
#win.mainloop()
31+
win.getMouse()
32+
33+
win.close()

zella-graphics/animation/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
# date: 2020.05.29
4+
# It use normal loop to animate point and checkMouse to close program on click
5+
6+
from graphics import * # PEP8: `import *` is not preferred
7+
import random
8+
import time
9+
10+
# --- main ---
11+
12+
win = GraphWin("My Window",500,500)
13+
win.setBackground(color_rgb(0,0,0))
14+
15+
pt = Point(250, 250)
16+
pt.setOutline(color_rgb(255,255,0))
17+
pt.draw(win)
18+
19+
while True:
20+
if win.checkMouse():
21+
break
22+
dx = random.randint(-10, 10)
23+
dy = random.randint(-10, 10)
24+
pt.move(dx, dy)
25+
time.sleep(0.1)
26+
27+
win.close()

0 commit comments

Comments
 (0)