Skip to content

Commit 63002d5

Browse files
committed
graphics
1 parent c1e3261 commit 63002d5

File tree

9 files changed

+134
-47
lines changed

9 files changed

+134
-47
lines changed

pygame/set-window-position/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
`PyGame` which uses `SDL 1.2` doesn't have function to set window position.
2+
3+
And you can't move window which can't have frame.
4+
5+
import os
6+
import pygame
7+
8+
pygame.init()
9+
10+
os.environ['SDL_VIDEO_WINDOW_POS'] = '50, 500'
11+
screen = pygame.display.set_mode((300,300), 32, pygame.NOFRAME)
12+
13+
(2)
14+
pygame.quit()
15+
16+
To move to new place you can change `SDL_VIDEO_WINDOW_POS` but you have to use `set_mode()` again.
17+
18+
To center window you can use `SDL_VIDEO_CENTERED`
19+
20+
import os
21+
import pygame
22+
23+
pygame.init()
24+
25+
os.environ['SDL_VIDEO_CENTERED'] = '1'
26+
screen = pygame.display.set_mode((300,300), 32, pygame.NOFRAME)
27+
28+
time.sleep(2)
29+
pygame.quit()
30+
31+
If you used `SDL_VIDEO_WINDOW_POS` then you have to delete this to use `SDL_VIDEO_CENTERED`
32+
33+
del os.environ['SDL_VIDEO_WINDOW_POS']
34+
os.environ['SDL_VIDEO_CENTERED'] = '1'
35+
36+
---
37+
38+
SDL doc: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlenvvars.html
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Bartłomiej "furas" Burek
5+
#
6+
# doc: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlenvvars.html
7+
#
8+
9+
import os
10+
import pygame
11+
12+
pygame.init()
13+
14+
# ---
15+
16+
print('pos: 50, 500')
17+
18+
os.environ['SDL_VIDEO_WINDOW_POS'] = '50, 500'
19+
20+
screen = pygame.display.set_mode((300,300), 32, pygame.NOFRAME)
21+
22+
pygame.time.delay(2000)
23+
24+
# ---
25+
26+
print('pos: 500, 50')
27+
28+
os.environ['SDL_VIDEO_WINDOW_POS'] = '500, 50'
29+
30+
screen = pygame.display.set_mode((300,300), 32, pygame.NOFRAME)
31+
32+
pygame.time.delay(2000)
33+
34+
# ---
35+
36+
print('pos: center')
37+
38+
del os.environ['SDL_VIDEO_WINDOW_POS']
39+
os.environ['SDL_VIDEO_CENTERED'] = '1'
40+
41+
screen = pygame.display.set_mode((300,300), 32, pygame.NOFRAME)
42+
43+
pygame.time.delay(2000)
44+
45+
# ---
46+
47+
pygame.quit()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11

2+
`Graphics` use `Tkinter` in background which has more usefull functions.
3+
4+
It can draw `arc`, `chord`, `pie`.
5+
6+
Tkinter: [Canvas](http://effbot.org/tkinterbook/canvas.htm) and [more](http://effbot.org/tkinterbook/tkinter-index.htm)
7+
8+
## example-1.py
9+
10+
![#3](screenshots/arc-chord-pie-1.png?raw=true)
11+
12+
## example-2.py
13+
14+
The same as `example-1` but it uses `after()` to animate - move around center.
15+
16+
![#3](screenshots/arc-chord-pie-1.png?raw=true)
17+
18+
## eye.py
19+
20+
![#1](screenshots/eye.png?raw=true)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from graphics import *
2+
3+
# --- constants ---
4+
5+
WIDTH = 300
6+
HEIGHT = 300
7+
8+
# --- main ----
9+
10+
win = GraphWin("Patch", WIDTH, HEIGHT)
11+
12+
# area used by full circle
13+
bbox = (5, 5, WIDTH-5, HEIGHT-5)
14+
15+
# create parts of circle - arc, chord, pieslice
16+
win.create_arc(bbox, fill="red", outline='green', width=3, start=0, extent=90, style='arc')
17+
win.create_arc(bbox, fill="red", outline='green', width=3, start=95, extent=90, style='chord')
18+
win.create_arc(bbox, fill="red", outline='green', width=3, start=190, extent=90, style='pieslice')
19+
20+
#win.getKey()
21+
win.getMouse()
22+
23+
win.close()

zella-graphics/arc-chord-pie/main.py renamed to zella-graphics/arc-chord-pie/example-2.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
def moves():
1111

12-
# move figure 1
12+
# move figure 1
1313
s = win.itemcget(fig1, 'start')
1414
win.itemconfig(fig1, start=float(s)+5)
15-
15+
1616
# move figure 2
1717
s = win.itemcget(fig2, 'start')
1818
win.itemconfig(fig2, start=float(s)+5)
@@ -30,15 +30,12 @@ def moves():
3030

3131
bbox = (5, 5, WIDTH-5, HEIGHT-5)
3232

33-
#fig1 = win.create_arc(bbox, fill="red", outline='green', width=3, start=0, extent=90, style='arc')
34-
#fig2 = win.create_arc(bbox, fill="red", outline='green', width=3, start=95, extent=90, style='chord')
35-
#fig3 = win.create_arc(bbox, fill="red", outline='green', width=3, start=190, extent=90, style='pieslice')
36-
37-
win.create_arc((0, -75, 300, 225), fill="blue", outline="blue", extent=120, style='chord', start=30+180)
38-
win.create_arc((0, 75, 300, 375), fill="blue", outline="blue", extent=120, style='chord', start=30)
33+
fig1 = win.create_arc(bbox, fill="red", outline='green', width=3, start=0, extent=90, style='arc')
34+
fig2 = win.create_arc(bbox, fill="red", outline='green', width=3, start=95, extent=90, style='chord')
35+
fig3 = win.create_arc(bbox, fill="red", outline='green', width=3, start=190, extent=90, style='pieslice')
3936

40-
# run first time
41-
#moves()
37+
# run first time - to start animation
38+
moves()
4239

4340
#win.getKey()
4441
win.getMouse()

zella-graphics/arc-chord-pie/eye-2.py

Lines changed: 0 additions & 37 deletions
This file was deleted.
-4 KB
Binary file not shown.

0 commit comments

Comments
 (0)