first commit

This commit is contained in:
tymek 2026-05-17 19:55:12 +02:00
commit 8605e937a9
21 changed files with 2429 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View file

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="str.*" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10 (zolwik)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/zolwik.iml" filepath="$PROJECT_DIR$/.idea/zolwik.iml" />
</modules>
</component>
</project>

10
.idea/zolwik.iml Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

244
Nibypait.py Normal file
View file

@ -0,0 +1,244 @@
import random
import tkinter as tk
from tkinter import *
from tkinter.ttk import Combobox
from PIL import Image, ImageDraw
import os
promien = 5
punkty_do_zapisu = []
helped = False
def kolory():
lis = ["white", "white smoke", "gainsboro", "light gray", "silver", "gray", "dim gray", "black", "light slate gray",
"slate gray", "alice blue", "light steel blue", "cornflower blue", "royal blue", "blue", "medium blue",
"navy", "dark blue", "midnight blue", "light blue", "deep sky blue", "dodger blue", "powder blue",
"sky blue", "light sky blue", "steel blue", "azure", "light cyan", "cyan", "pale turquoise",
"dark turquoise", "turquoise", "medium turquoise", "light sea green", "cadet blue", "dark cyan", "teal",
"dark slate gray", "mint cream", "aquamarine", "medium aquamarine", "dark sea green", "medium sea green",
"sea green", "honeydew", "pale green", "light green", "medium spring green", "spring green", "lime green",
"green", "forest green", "dark green", "green yellow", "chartreuse", "lawn green", "lime", "yellow green",
"olive drab", "beige", "dark khaki", "olive", "dark olive green", "pale goldenrod", "khaki", "ivory",
"light yellow", "light goldenrod yellow", "cornsilk", "lemon chiffon", "yellow", "gold", "goldenrod",
"dark goldenrod", "wheat", "tan", "burlywood", "peru", "sienna", "saddle brown", "floral white", "old lace",
"navajo white", "moccasin", "sandy brown", "orange", "dark orange", "chocolate", "firebrick", "brown",
"dark red", "maroon", "antique white", "papaya whip", "blanched almond", "bisque", "peach puff",
"light salmon", "coral", "tomato", "orange red", "red", "crimson", "dark salmon", "salmon", "light coral",
"indian red", "rosy brown", "linen", "seashell", "misty rose", "pink", "light pink", "hot pink", "deep pink",
"snow", "lavender blush", "pale violet red", "violet red", "medium violet red", "purple", "dark magenta",
"violet", "magenta", "thistle", "plum", "orchid", "medium orchid", "dark orchid", "dark violet",
"blue violet", "medium purple", "rebecca purple", "indigo", "ghost white", "lavender", "light slate blue",
"medium slate blue", "slate blue", "dark slate blue"]
return lis[random.randrange(0, len(lis))]
def on_key_press(event):
print(f"Key pressed: {event.keysym}")
label = tk.Label(root, text=f"Key pressed: {event.keysym} ")
label.config(bg=kolory())
label.place(x=0, y=0)
if event.keysym == 'd':
canvas.move(kwadrat, 5, 0)
elif event.keysym == 'a':
canvas.move(kwadrat, -5, 0)
elif event.keysym == 'w':
canvas.move(kwadrat, 0, -5)
elif event.keysym == 's':
canvas.move(kwadrat, 0, 5)
# label.pack()
kolor()
def on_left_click(event):
print(f"Left click at ({event.x}, {event.y})")
global promien
aktualny_kolor = canvas.itemcget(podonzaj, "fill")
canvas.create_oval(event.x - promien, event.y - promien, event.x + promien, event.y + promien,
fill=aktualny_kolor, outline="")
punkty_do_zapisu.append((event.x, event.y, promien, aktualny_kolor))
def on_right_click(event):
print(f"Right click at ({event.x}, {event.y})")
def on_mouse_motion(event):
odswiez_pozycje_kropki(event.x, event.y)
def zapisz_obraz():
# 1. Znajdowanie wolnego numeru
licznik = 1
while os.path.exists(f"obraz_tk_{licznik}.png"):
licznik += 1
nazwa_pliku = f"obraz_tk_{licznik}.png"
# 2. Tworzenie i rysowanie obrazu (jak wcześniej)
szer = canvas.winfo_width()
wys = canvas.winfo_height()
obraz = Image.new("RGB", (szer, wys), "white")
rysuj = ImageDraw.Draw(obraz)
for x, y, r, kolor in punkty_do_zapisu:
rysuj.ellipse([x - r, y - r, x + r, y + r], fill=kolor)
# 3. Zapis pod nową nazwą
obraz.save(nazwa_pliku)
print(f"Zapisano jako {nazwa_pliku}")
def zmien_promien(wartosc):
global promien
promien = int(wartosc)
skrajny_x = root.winfo_pointerx()
skrajny_y = root.winfo_pointery()
canvas_x = skrajny_x - canvas.winfo_rootx()
canvas_y = skrajny_y - canvas.winfo_rooty()
odswiez_pozycje_kropki(canvas_x, canvas_y)
def odswiez_pozycje_kropki(x, y):
global promien
canvas.coords(podonzaj, x - promien, y - promien, x + promien, y + promien)
def relly():
rel = Button(root, text="Are you sure???", width=20, bg="red", command=root.destroy)
niet = Button(root, text="no", width=20, fg="black", command=lambda: [rel.place_forget(), niet.place_forget()])
rel.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
niet.place(relx=1.0, rely=1.0, anchor='se', x=-10, y=-10)
root.bind("<Return>", lambda e: root.destroy)
root.bind("<Escape>", lambda e: [rel.place_forget(), niet.place_forget()])
# return 0
def skroluj_suwak(event):
obecna = vertical_scale.get()
if event.num == 4:
nowa = obecna + 1
elif event.num == 5:
nowa = obecna - 1
else:
nowa = obecna
vertical_scale.set(nowa)
def kolor(val=None):
r = red.get()
g = green.get()
b = blue.get()
kolor_hex = f"#{r:02x}{g:02x}{b:02x}"
canvas.itemconfig(podonzaj, fill=kolor_hex)
def r_up(event):
aktualna = red.get()
if aktualna < 255:
red.set(aktualna + 5)
def r_down(event):
aktualna = red.get()
if aktualna > 0:
red.set(aktualna - 5)
def g_up(event):
aktualna = green.get()
if aktualna < 255:
green.set(aktualna + 5)
def g_down(event):
aktualna = green.get()
if aktualna > 0:
green.set(aktualna - 5)
def b_up(event):
aktualna = blue.get()
if aktualna < 255:
blue.set(aktualna + 5)
def b_down(event):
aktualna = blue.get()
if aktualna > 0:
blue.set(aktualna - 5)
def helpp():
global helped
helped = not helped
if helped:
helplist.place(relx=1.0, y=60, anchor='ne')
else:
helplist.place_forget()
# global promien
root = Tk()
canvas = tk.Canvas(root, bg="white", highlightthickness=0)
canvas.pack(fill="both", expand=True)
kwadrat = canvas.create_rectangle(50, 50, 100, 100, fill="blue")
podonzaj = canvas.create_oval(100, 100, 110, 110, fill="green")
root.bind("<KeyPress>", on_key_press)
root.bind("<B1-Motion>", on_left_click)
root.bind("<Button-3>", on_right_click)
root.bind("<Motion>", on_mouse_motion)
root.bind_all("<Button-4>", skroluj_suwak)
root.bind_all("<Button-5>", skroluj_suwak)
root.bind("r", r_down)
root.bind("t", r_up)
root.bind("f", g_down)
root.bind("g", g_up)
root.bind("v", b_down)
root.bind("b", b_up)
stop = Button(root, text="Escape", width=20, bg="red", fg="black", command=relly)
stop.place(relx=0.5, rely=0, anchor='n', y=0)
root.bind("<Escape>", lambda e: relly())
przycisk_zapis = Button(root, text="Zapisz PNG", bg="green", fg="white", command=zapisz_obraz)
przycisk_zapis.place(relx=1.0, rely=0.0, anchor='ne')
vertical_scale = Scale(root, from_=1, to=50, command=zmien_promien)
vertical_scale.place(x=0, rely=0.5, anchor='sw')
vertical_scale.set(5)
blue = Scale(root, from_=0, to=255, command=kolor, orient=tk.HORIZONTAL)
blue.place(x=0, rely=1, anchor='sw')
blue.set(0)
green = Scale(root, from_=0, to=255, command=kolor, orient=tk.HORIZONTAL)
green.place(x=0, rely=1, anchor='sw', y=-40)
green.set(0)
red = Scale(root, from_=0, to=255, command=kolor, orient=tk.HORIZONTAL)
red.place(x=0, rely=1, anchor='sw', y=-80)
red.set(0)
rgb = Label(root, text="\nRed \n\n\nGreen \n\nBlue\n")
rgb.place(x=102, rely=1, anchor='nw', y=-122)
helpbuton = Button(root, text=" Help ", bg="lightblue", fg="blue", command=helpp)
helpbuton.place(relx=1.0, y=30, anchor='ne')
helplist = Listbox(root, bg="lightblue", fg="blue")
instrukcje = ["Scroll - size", "r - red-5", "t - red+5", "f - green-5", "g - green+5", "v - blue-5", "b - blue+5"]
for opcja in instrukcje:
helplist.insert(tk.END, opcja)
wszystkie_teksty = helplist.get(0, tk.END)
najdluzsza_dlugosc = 0
for tekst in wszystkie_teksty:
najdluzsza_dlugosc = max(najdluzsza_dlugosc, len(tekst))
helplist.config(width=12, height=helplist.size())
root.mainloop()

Binary file not shown.

Binary file not shown.

Binary file not shown.

1296
fraktele.py Normal file

File diff suppressed because it is too large Load diff

17
mist.py Normal file
View file

@ -0,0 +1,17 @@
n = int(input())
s = 10
while s >= 10:
s = 0
while n >= 10:
s += n % 10
n /= 10
s += n
if s > 9:
n = s
s = 10
s=int(s)
if s != 1:
print(s)
else:
print("Szczesliwego Nowego Roku")

0
nbkalkulator.py Normal file
View file

17
pilka.py Normal file
View file

@ -0,0 +1,17 @@
from turtle import *
vy = int(input())
vx = int(input())
waga = int(input())
opur=waga/10
while ycor() >= 0:
vy -= waga - opur
if vx - opur >= 0:
vx -= opur
else:
vx = 0
goto(vx + xcor(), vy + ycor())
print(vx, vy)
mainloop()

28
pilka1.py Normal file
View file

@ -0,0 +1,28 @@
from turtle import *
import turtle as t
n = int(input())
speed(1)
lt(90)
def uno(n):
f = n
for i in range(n):
f -= 1
fd(f)
if f != 0:
rt(90 / n)
for i in range(n):
f += 1
if f != 0:
rt(90 / n)
fd(f)
if n > 2:
rt(180)
uno(int(n / 2))
uno(n)
t.mainloop()

95
sand.py Normal file
View file

@ -0,0 +1,95 @@
from tkinter import *
from random import randrange
promien = 5
listapixeli = []
def zmien_promien(wartosc):
global promien
promien = int(wartosc)
skrajny_x = root.winfo_pointerx()
skrajny_y = root.winfo_pointery()
canvas_x = skrajny_x - canvas.winfo_rootx()
canvas_y = skrajny_y - canvas.winfo_rooty()
odswiez_pozycje_kropki(canvas_x, canvas_y)
def odswiez_pozycje_kropki(x, y):
global promien
canvas.coords(podonzaj, x - promien, y - promien, x + promien, y + promien)
def on_mouse_motion(event):
odswiez_pozycje_kropki(event.x, event.y)
def skroluj_suwak(event):
obecna = vertical_scale.get()
if event.num == 4:
nowa = obecna + 1
elif event.num == 5:
nowa = obecna - 1
else:
nowa = obecna
vertical_scale.set(nowa)
def lewywci(event):
canvas.create_rectangle(event.x, event.y, event.x + 1, event.y + 1)
listapixeli.append([event.x, event.y])
def czas(event=None):
canvas.delete("all")
global t
global listapixeli
for x, y in listapixeli:
listapixeli.remove([x, y])
if y == canvas.winfo_height() - 100:
listapixeli.append([x, y])
canvas.create_rectangle(x, y, x + 1, y + 1)
elif [x, y + 1] not in listapixeli:
listapixeli.append([x, y + 1])
canvas.create_rectangle(x, y + 1, x + 1, y + 2)
elif [x + 1, y + 1] not in listapixeli and [x - 1, y + 1] not in listapixeli:
if t:
listapixeli.append([x + 1, y + 1])
canvas.create_rectangle(x + 1, y + 1, x + 2, y + 2)
t=False
else:
listapixeli.append([x - 1, y + 1])
canvas.create_rectangle(x - 1, y + 1, x, y + 2)
t=True
elif [x + 1, y + 1] not in listapixeli:
listapixeli.append([x + 1, y + 1])
canvas.create_rectangle(x + 1, y + 1, x + 2, y + 2)
elif [x - 1, y + 1] not in listapixeli:
listapixeli.append([x - 1, y + 1])
canvas.create_rectangle(x - 1, y + 1, x, y + 2)
else:
listapixeli.append([x, y])
canvas.create_rectangle(x, y, x + 1, y + 1)
# print(listapixeli)
t = True
root = Tk()
canvas = Canvas(root, bg="white", highlightthickness=0)
canvas.pack(fill="both", expand=True)
vertical_scale = Scale(root, from_=1, to=50) # , command=zmien_promien)
vertical_scale.place(x=0, rely=0.5, anchor='sw')
vertical_scale.set(1)
podonzaj = canvas.create_rectangle(100, 100, 110, 110, fill="green")
root.bind("<Motion>", lambda e: [on_mouse_motion, czas])
# root.bind_all("<Button-4>", skroluj_suwak)
# root.bind_all("<Button-5>", skroluj_suwak)
root.bind("<B1-Motion>", lewywci)
root.bind("<KeyPress>", czas)
root.mainloop()

526
statek.py Normal file
View file

@ -0,0 +1,526 @@
import math
from tkinter import *
from random import randrange
import tkinter.ttk as tk
def obroc_prostokat_o_2_stopnie_zg(canvas, element_id):
wspolrzedne = canvas.coords(element_id)
xs = [wspolrzedne[i] for i in range(0, len(wspolrzedne), 2)]
ys = [wspolrzedne[i] for i in range(1, len(wspolrzedne), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
radiany = math.radians(2)
cos_k = math.cos(radiany)
sin_k = math.sin(radiany)
nowe_wspolrzedne = []
for x_val, y_val in zip(xs, ys):
nx = cx + (x_val - cx) * cos_k - (y_val - cy) * sin_k
ny = cy + (x_val - cx) * sin_k + (y_val - cy) * cos_k
nowe_wspolrzedne.extend([nx, ny])
canvas.coords(element_id, nowe_wspolrzedne)
def obroc_prostokat_o_2_stopnie_prz(canvas, element_id):
wspolrzedne = canvas.coords(element_id)
xs = [wspolrzedne[i] for i in range(0, len(wspolrzedne), 2)]
ys = [wspolrzedne[i] for i in range(1, len(wspolrzedne), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
radiany = math.radians(-2)
cos_k = math.cos(radiany)
sin_k = math.sin(radiany)
nowe_wspolrzedne = []
for x_val, y_val in zip(xs, ys):
nx = cx + (x_val - cx) * cos_k - (y_val - cy) * sin_k
ny = cy + (x_val - cx) * sin_k + (y_val - cy) * cos_k
nowe_wspolrzedne.extend([nx, ny])
canvas.coords(element_id, nowe_wspolrzedne)
def rusz_w_strone_boku(canvas, element_id, dystans):
wspolrzedne = canvas.coords(element_id)
if len(wspolrzedne) < 8:
return
x1, y1 = wspolrzedne[4], wspolrzedne[5]
x2, y2 = wspolrzedne[2], wspolrzedne[3]
kat_krutkiego_boku = math.atan2(y2 - y1, x2 - x1)
kat_ruchu = kat_krutkiego_boku + (math.pi / 2)
dx = dystans * math.cos(kat_ruchu)
dy = dystans * math.sin(kat_ruchu)
canvas.move(element_id, dx, dy)
def klawisz_wcisniety(event):
key = event.keysym.lower()
if key in wcisniete_klawisze:
if key == "q":
global tempomat
tempomat = not tempomat
else:
wcisniete_klawisze[key] = True
def klawisz_puszczony(event):
key = event.keysym.lower()
if key in wcisniete_klawisze and key != "q":
wcisniete_klawisze[key] = False
def strzal_z_karabinu():
global firerate, magazynek, pelny
amo['value'] = magazynek
if firerate <= 0 < magazynek and pelny:
firerate = 5
magazynek -= 1
wspol = canvas.coords(dul)
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
dlugosc_lufy = 15
start_x = cx + dlugosc_lufy * math.cos(kat_myszy)
start_y = cy + dlugosc_lufy * math.sin(kat_myszy)
predkosc_karabinu = 12
dx = predkosc_karabinu * math.cos(kat_myszy)
dy = predkosc_karabinu * math.sin(kat_myszy)
r_karabinu = 1
id_karabinu = canvas.create_oval(start_x - r_karabinu, start_y - r_karabinu, start_x + r_karabinu, start_y + r_karabinu, fill="black", outline="")
karabiny.append({"id": id_karabinu, "dx": dx, "dy": dy})
def stzal_gluwny(event):
global ladowanie, pociski
if ladowanie == 300:
ladowanie = 0
wspol = canvas.coords(dul)
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
dlugosc_lufy = 15
start_x = cx + dlugosc_lufy * math.cos(kat_myszy)
start_y = cy + dlugosc_lufy * math.sin(kat_myszy)
predkosc_pocisku = 15
dx = predkosc_pocisku * math.cos(kat_myszy)
dy = predkosc_pocisku * math.sin(kat_myszy)
r_pocisku = 3
id_pocisku = canvas.create_oval(start_x - r_pocisku, start_y - r_pocisku, start_x + r_pocisku, start_y + r_pocisku, fill="red", outline="black")
pociski.append({"id": id_pocisku, "dx": dx, "dy": dy})
def aktualizuj_karabiny():
szerokosc_okna = canvas.winfo_width()
wysokosc_okna = canvas.winfo_height()
pociski_do_usuniecia = []
kamyki_do_usuniecia = []
for i in range(len(karabiny) - 1, -1, -1):
p = karabiny[i]
canvas.move(p["id"], p["dx"], p["dy"])
coords = canvas.coords(p["id"])
if coords:
px, py = coords[0], coords[1]
if px < 0 or px > szerokosc_okna or py < 0 or py > wysokosc_okna:
pociski_do_usuniecia.append(i)
continue
for idx, j in enumerate(kamycki):
if j["x"] <= px <= j["x"] + j["pr"] and j["y"] <= py <= j["y"] + j["pr"]:
pociski_do_usuniecia.append(i)
if idx not in kamyki_do_usuniecia and j["pr"] < 12:
kamyki_do_usuniecia.append(idx)
break
kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia:
kam = kamycki[idx]
srodek_x = kam["x"] + (kam["pr"] / 2)
srodek_y = kam["y"] + (kam["pr"] / 2)
promien_wybuchu = 10
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu, srodek_x + promien_wybuchu, srodek_y + promien_wybuchu, fill="yellow", outline="orange")
root.after(200, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 6
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu, srodek_x + promien_sladu, srodek_y + promien_sladu, fill="grey13", outline="")
canvas.tag_lower(slad_id)
canvas.delete(kam["id"])
kamycki.pop(idx)
pociski_do_usuniecia = list(set(pociski_do_usuniecia))
pociski_do_usuniecia.sort(reverse=True)
for idx in pociski_do_usuniecia:
c = karabiny[idx]
coords_pocisku = canvas.coords(c["id"])
if coords_pocisku:
pocisk_x = coords_pocisku[0]
pocisk_y = coords_pocisku[1]
if 0 <= pocisk_x <= szerokosc_okna and 0 <= pocisk_y <= wysokosc_okna:
promien_wybuchu = 2
wybuch_id = canvas.create_oval(pocisk_x - promien_wybuchu, pocisk_y - promien_wybuchu, pocisk_x + promien_wybuchu, pocisk_y + promien_wybuchu, fill="yellow", outline="orange")
root.after(400, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 1
slad_id = canvas.create_oval(pocisk_x - promien_sladu, pocisk_y - promien_sladu, pocisk_x + promien_sladu, pocisk_y + promien_sladu, fill="gold", outline="")
canvas.tag_lower(slad_id)
canvas.delete(c["id"])
karabiny.pop(idx)
def aktualizuj_pociski():
szerokosc_okna = canvas.winfo_width()
wysokosc_okna = canvas.winfo_height()
pociski_do_usuniecia = []
kamyki_do_usuniecia = []
for i in range(len(pociski) - 1, -1, -1):
p = pociski[i]
canvas.move(p["id"], p["dx"], p["dy"])
coords = canvas.coords(p["id"])
if coords:
px, py = coords[0], coords[1]
if px < 0 or px > szerokosc_okna or py < 0 or py > wysokosc_okna:
pociski_do_usuniecia.append(i)
continue
for idx, j in enumerate(kamycki):
if j["x"] <= px <= j["x"] + j["pr"] and j["y"] <= py <= j["y"] + j["pr"]:
pociski_do_usuniecia.append(i)
if idx not in kamyki_do_usuniecia:
kamyki_do_usuniecia.append(idx)
break
kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia:
kam = kamycki[idx]
srodek_x = kam["x"] + (kam["pr"] / 2)
srodek_y = kam["y"] + (kam["pr"] / 2)
promien_wybuchu = 24
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu, srodek_x + promien_wybuchu, srodek_y + promien_wybuchu, fill="yellow", outline="red", width=2)
root.after(500, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 16
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu, srodek_x + promien_sladu, srodek_y + promien_sladu, fill="black", outline="")
canvas.tag_lower(slad_id)
canvas.delete(kam["id"])
kamycki.pop(idx)
pociski_do_usuniecia.sort(reverse=True)
for idx in pociski_do_usuniecia:
canvas.delete(pociski[idx]["id"])
pociski.pop(idx)
def sprawdz_kolizje_czolgu():
global x, tempomat, hp
if x == 0:
return
wspol = canvas.coords(dul)
if len(wspol) < 8:
return
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
promien_czolgu = 18
for k in kamycki:
kx_srodek = k["x"] + (k["pr"] / 2)
ky_srodek = k["y"] + (k["pr"] / 2)
odleglosc = math.sqrt((cx - kx_srodek) ** 2 + (cy - ky_srodek) ** 2)
min_odleglosc = promien_czolgu + (k["pr"] / 2)
if odleglosc < min_odleglosc:
nakladanie = min_odleglosc - odleglosc
kat = math.atan2(cy - ky_srodek, cx - kx_srodek)
dx = nakladanie * math.cos(kat)
dy = nakladanie * math.sin(kat)
canvas.move(dul, dx, dy)
if x >= 0:
hp -= x * 10
else:
hp += x * 10
print(x)
hpbar['value'] = hp
hpile["text"] = str(int(hp))
x = 0
tempomat = False
break
def gluwna():
global x, tempomat, firerate, czekajmagazynek, pelny, magazynek, ladowanie, pzeladowanie
if wcisniete_klawisze["a"]:
obroc_prostokat_o_2_stopnie_prz(canvas, dul)
if wcisniete_klawisze["d"]:
obroc_prostokat_o_2_stopnie_zg(canvas, dul)
if wcisniete_klawisze["w"]:
x += 0.02
tempomat = False
if wcisniete_klawisze["s"]:
x -= 0.01
tempomat = False
if wcisniete_klawisze["space"]:
strzal_z_karabinu()
if x != 0:
rusz_w_strone_boku(canvas, dul, x)
if x > 0 and not tempomat:
x -= 0.003
if x < 0 and not tempomat:
x += 0.003
if x > 2:
x = 2
if x < -1:
x = -1
if x != 0:
rusz_w_strone_boku(canvas, dul, x)
sprawdz_kolizje_czolgu()
wspol = canvas.coords(dul)
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
r = 5
canvas.coords(wieza, cx - r, cy - r, cx + r, cy + r)
kxl = (wspol[2] * 3 + wspol[4]) / 4
kyl = (wspol[3] * 3 + wspol[5]) / 4
kxp = (wspol[2] + wspol[4] * 3) / 4
kyp = (wspol[3] + wspol[5] * 3) / 4
rk = 2
canvas.coords(swietlo_lewe, kxl - rk, kyl - rk, kxl + rk, kyl + rk)
canvas.coords(swietlo_prawe, kxp - rk, kyp - rk, kxp + rk, kyp + rk)
dlugosc_lufy = 15
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
lx = cx + dlugosc_lufy * math.cos(kat_myszy)
ly = cy + dlugosc_lufy * math.sin(kat_myszy)
canvas.coords(lufa, cx, cy, lx, ly)
canvas.tag_raise(wieza, dul)
canvas.tag_lower(swietlo_lewe, dul)
canvas.tag_lower(swietlo_prawe, dul)
canvas.tag_raise(temo, prtlo)
aktualizuj_karabiny()
aktualizuj_pociski()
if firerate > 0:
firerate -= 1
if magazynek == 0 and pelny:
czekajmagazynek = 320
pelny = False
if czekajmagazynek > 0:
czekajmagazynek = czekajmagazynek - 1
amo['value'] = 40 - (czekajmagazynek / 8)
if czekajmagazynek == 0:
magazynek = 40
pelny = True
amo['value'] = magazynek
pzeladowanie['value'] = ladowanie
if ladowanie < 300:
ladowanie += 1
aktualizuj_pozycje_figur()
rk_slad = 1.5
sxl = (wspol[0] * 3 + wspol[6]) / 4
syl = (wspol[1] * 3 + wspol[7]) / 4
sxp = (wspol[0] + wspol[6] * 3) / 4
syp = (wspol[1] + wspol[7] * 3) / 4
k1 = "#00" + str(randrange(4000, 6000, 100))
k2 = "#00" + str(randrange(4000, 6000, 100))
t1 = canvas.create_oval(sxl - rk_slad, syl - rk_slad, sxl + rk_slad, syl + rk_slad, fill=k1, outline="")
t2 = canvas.create_oval(sxp - rk_slad, syp - rk_slad, sxp + rk_slad, syp + rk_slad, fill=k2, outline="")
canvas.tag_lower(t1)
canvas.tag_lower(t2)
canvas.tag_lower(t1)
canvas.tag_lower(t2)
root.after(16, gluwna)
def ruch_myszy(event):
global mysz_x, mysz_y
mysz_x = event.x
mysz_y = event.y
def aktualizuj_pozycje_figur():
wysokosc_okna = canvas.winfo_height()
promien_tarczy = 150
cx_tarczy = 160
cy_tarczy = wysokosc_okna - 100
canvas.coords(prtlo, cx_tarczy - promien_tarczy, cy_tarczy - promien_tarczy, cx_tarczy + promien_tarczy, cy_tarczy + promien_tarczy)
canvas.coords(temo, cx_tarczy + 20, cy_tarczy - 20, cx_tarczy + 35, cy_tarczy - 35)
if tempomat:
canvas.itemconfig(temo, fill="green2")
else:
canvas.itemconfig(temo, fill="firebrick1")
maks_predkosc = 2.0
min_predkosc = -1.0
procent = (x - min_predkosc) / (maks_predkosc - min_predkosc)
stopnie = procent * 270
aktualny_kat = 225 - stopnie
radiany = math.radians(aktualny_kat)
dlugosc_wskazowki = promien_tarczy - 10
wx = cx_tarczy + dlugosc_wskazowki * math.cos(radiany)
wy = cy_tarczy - dlugosc_wskazowki * math.sin(radiany)
canvas.coords(prwska, cx_tarczy, cy_tarczy, wx, wy)
promien_tekstu = promien_tarczy - 20
for i, predkosc_punktu in enumerate(wartosci_predkosci):
proc = (predkosc_punktu - min_predkosc) / (maks_predkosc - min_predkosc)
stopn = proc * 270
kat_napisu = 225 - stopn
rad = math.radians(kat_napisu)
tx = cx_tarczy + promien_tekstu * math.cos(rad)
ty = cy_tarczy - promien_tekstu * math.sin(rad)
canvas.coords(napisy_ids[i], tx, ty)
root = Tk()
root.geometry("1000x700")
canvas = Canvas(root, bg="darkolivegreen", highlightthickness=0)
canvas.pack(fill="both", expand=True)
x1, y1 = 100, 100
x2, y2 = 130, 120
dul = canvas.create_polygon(x1, y1, x2, y1, x2, y2, x1, y2, fill="green", outline="black")
x = 0
mysz_x, mysz_y = 0, 0
wcisniete_klawisze = {"w": False, "s": False, "a": False, "d": False, "q": False, "space": False}
karabiny = []
pociski = []
firerate = 0
magazynek = 40
czekajmagazynek = 0
pelny = True
style = tk.Style()
style.theme_use('clam')
style.configure("szary.Horizontal.TProgressbar", troughcolor="grey15", background="grey61", thickness=20, borderwidth=0)
style.configure("zielony.Horizontal.TProgressbar", troughcolor="darkgreen", background="green3", thickness=50, borderwidth=0, lightcolor="green3", darkcolor="green3", bordercolor="green4")
amo = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=40)
amo.place(x=400, rely=1.0, y=-50)
amo['value'] = magazynek
ladowanie = 300
pzeladowanie = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=300)
pzeladowanie.place(x=400, rely=1.0, y=-80)
pzeladowanie['value'] = ladowanie
tempomat = False
temo = canvas.create_oval(0, 0, 0, 0, fill="firebrick1", outline="")
hp = 100
hpbar = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="zielony.Horizontal.TProgressbar", maximum=100)
hpbar.place(relx=0.5, y=0, x=-150)
hpbar['value'] = hp
hpile = Label(root, text=hp, background="green4", foreground="green3", font=("Arial", 9, "bold"))
hpile.place(relx=0.5, y=0, x=+150)
cx_poczatkowy = (x1 + x2) / 2
cy_poczatkowy = (y1 + y2) / 2
promien_kola = 5
wieza = canvas.create_oval(cx_poczatkowy - promien_kola, cy_poczatkowy - promien_kola, cx_poczatkowy + promien_kola, cy_poczatkowy + promien_kola, fill="darkgreen", outline="black")
kx_poczatkowe = x2
ky_poczatkowe = (y1 + y2) / 2
r_kropki = 2
swietlo_lewe = canvas.create_oval(kx_poczatkowe - r_kropki, ky_poczatkowe - r_kropki, kx_poczatkowe + r_kropki, ky_poczatkowe + r_kropki, fill="orange2", outline="black")
swietlo_prawe = canvas.create_oval(kx_poczatkowe - r_kropki, ky_poczatkowe - r_kropki, kx_poczatkowe + r_kropki, ky_poczatkowe + r_kropki, fill="orange2", outline="black")
lufa = canvas.create_line(0, 0, 0, 0, fill="black", width=3)
prtlo = canvas.create_oval(0, 0, 0, 0, fill="grey60", outline="black", width=2)
prwska = canvas.create_line(0, 0, 10, 10, width=5, fill="black")
wartosci_predkosci = [-1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
teksty_napisow = ["-1", "-0.75", "-0.5", "-0.25", "0", "0.25", "0.5", "0.75", "1", "1.25", "1.5", "1.75", "2"]
napisy_ids = []
for tekst in teksty_napisow:
id_tekstu = canvas.create_text(0, 0, text=tekst, font=("Arial", 10, "bold"), fill="black")
napisy_ids.append(id_tekstu)
kamycki = []
for i in range(60):
kax = randrange(0, 1900)
kay = randrange(0, 1000)
ka = "grey" + str(randrange(30, 40))
wt = randrange(7, 20)
t = canvas.create_oval(kax, kay, kax + wt, kay + wt, fill=ka, outline="")
canvas.tag_lower(t)
kamycki.append({"id": t, "x": kax, "y": kay, "pr": wt})
for i in range(1600):
trxx = randrange(0, 1900)
tryy = randrange(0, 1000)
tr = "#00" + str(randrange(40, 60))
tr += "00"
wt = randrange(3, 7)
t = canvas.create_oval(trxx, tryy, trxx + wt, tryy + wt, fill=tr, outline="")
canvas.tag_lower(t)
root.bind("<KeyPress>", klawisz_wcisniety)
root.bind("<KeyRelease>", klawisz_puszczony)
root.bind("<Motion>", ruch_myszy)
root.bind("<Button-1>", stzal_gluwny)
gluwna()
root.mainloop()

108
test.py Normal file
View file

@ -0,0 +1,108 @@
zawartosc = """======================================================================
LISTA ZNAKÓW, KLAWISZY I MYSZY W TKINTER (EVENT.KEYSYM / BIND)
======================================================================
1. LITERY I CYFRY
----------------------------------------------------------------------
Znak | Nazwa w Tkinter (event.keysym)
----------------------------------------------------------------------
a do z | "a" do "z" (zawsze małe przy <KeyPress>)
0 do 9 | "0" do "9"
2. KLAWISZE STERUJĄCE I SPECJALNE
----------------------------------------------------------------------
Znak / Klawisz | Nazwa w Tkinter (event.keysym)
----------------------------------------------------------------------
Spacja | "space"
Enter / Powrót | "Return"
Backspace | "BackSpace"
Tabulator | "Tab"
Caps Lock | "Caps_Lock"
Shift (lewy) | "Shift_L"
Shift (prawy) | "Shift_R"
Ctrl (lewy) | "Control_L"
Ctrl (prawy) | "Control_R"
Alt (lewy) | "Alt_L"
Alt Gr (prawy) | "Alt_R"
Escape | "Escape"
3. STRZAŁKI I NAWIGACJA
----------------------------------------------------------------------
Klawisz | Nazwa w Tkinter (event.keysym)
----------------------------------------------------------------------
Strzałka w górę | "Up"
Strzałka w dół | "Down"
Strzałka w lewo | "Left"
Strzałka w prawo| "Right"
Home | "Home"
End | "End"
Page Up | "Prior"
Page Down | "Next"
Insert | "Insert"
Delete | "Delete"
4. ZNAKI INTERPUNKCYJNE I MATEMATYCZNE
----------------------------------------------------------------------
Znak | Nazwa w Tkinter (event.keysym)
----------------------------------------------------------------------
. | "period"
, | "comma"
/ | "slash"
\\ | "backslash"
; | "semicolon"
' | "apostrophe"
[ | "bracketleft"
] | "bracketright"
- | "minus"
= | "equal"
` | "grave"
5. KLAWISZE NUMERYCZNE (KEYPAD)
----------------------------------------------------------------------
Klawisz (Num) | Nazwa w Tkinter (event.keysym)
----------------------------------------------------------------------
Cyfry 0 do 9 | "KP_0" do "KP_9"
+ | "KP_Add"
- | "KP_Subtract"
* | "KP_Multiply"
/ | "KP_Divide"
Enter | "KP_Enter"
. | "KP_Decimal"
6. PRZYCISKI MYSZY (KLIKNIĘCIA)
----------------------------------------------------------------------
Akcja myszy | Nazwa zdarzenia (root.bind)
----------------------------------------------------------------------
Lewy przycisk myszy | "<Button-1>" lub "<ButtonPress-1>"
Środkowy przycisk (rolka) | "<Button-2>" lub "<ButtonPress-2>"
Prawy przycisk myszy | "<Button-3>" lub "<ButtonPress-3>"
Puszczenie lewego przycisku | "<ButtonRelease-1>"
Puszczenie środkowego przycisku| "<ButtonRelease-2>"
Puszczenie prawego przycisku | "<ButtonRelease-3>"
Podwójne kliknięcie lewym | "<Double-Button-1>"
Potrójne kliknięcie lewym | "<Triple-Button-1>"
7. RUCH MYSZY I ZACHOWANIE
----------------------------------------------------------------------
Akcja myszy | Nazwa zdarzenia (root.bind)
----------------------------------------------------------------------
Ruch myszy bez klikania | "<Motion>"
Przeciąganie z wciśniętym lewym| "<B1-Motion>"
Przeciąganie z wciśniętym prawym| "<B3-Motion>"
Ruch rolką w górę / dół | "<MouseWheel>"
Wejście kursora w obszar okna | "<Enter>"
Opuszczenie obszaru okna | "<Leave>"
----------------------------------------------------------------------
"""
# Zapisywanie danych do pliku tekstowego z kodowaniem UTF-8 (w celu obsługi polskich znaków)
with open("lista_tkinter.txt", "w", encoding="utf-8") as plik:
plik.write(zawartosc)
print("Plik 'lista_tkinter.txt' został pomyślnie utworzony!")

15
testy.py Normal file
View file

@ -0,0 +1,15 @@
from turtle import *
import turtle as t
def cc(c):
if c <= 3:
o = 0
return
fd(c)
lt(30)
cc(c / 2)
cc(80)
t.mainloop()

32
vektory.py Normal file
View file

@ -0,0 +1,32 @@
from turtle import *
from itertools import permutations
def vektor(ile):
t = [[0 for _ in range(2)] for _ in range(ile)]
print(t)
for i in range(ile):
print(i + 1, end="")
t[i][0], t[i][1] = input(". wektor: ").split(" ")
t[i][0] = int(t[i][0])
t[i][1] = int(t[i][1])
print(t)
w = [list(p) for p in permutations(t)]
print(w)
pensize(2)
for i in range(ile):
goto(t[i][0], t[i][1])
penup()
goto(0, 0)
pendown()
pensize(1)
for i in range(len(w)):
for j in range(len(w[i])):
goto(w[i][j][0] + xcor(), w[i][j][1] + ycor())
penup()
goto(0, 0)
pendown()
mainloop()