Extension package for tkintertools to simple 3D drawings
Project description
tkintertools-3d
https://xiaokang2022.github.io/tkintertools/
Extension package of tkintertools for simple 3D drawings
📦 Installation
pip install tkintertools-3d
👀 Preview
import itertools
import math
import statistics
import tkintertools as tkt
from tkintertools import theme, three
tk = tkt.Tk(title="tkintertools-3d")
space = three.Space(auto_zoom=True, free_anchor=True, keep_ratio="min")
space.light.update(bg="white")
space.dark.update(bg="black")
space.configure(bg="black" if theme.get_color_mode() == "dark" else "light")
space.place(width=1280, height=720, x=640, y=360, anchor="center")
space.update() # NOTE: This line is very important!
### Inside ###
m = 150 * math.sqrt(50 - 10*math.sqrt(5)) / 10
n = 150 * math.sqrt(50 + 10*math.sqrt(5)) / 10
points = []
dis_side = (
150
* (3 * math.sqrt(3) + math.sqrt(15))
/ 12
/ ((math.sqrt(10 + 2 * math.sqrt(5))) / 4)
)
count, color_lst = 0, ["00", "77", "FF"]
colors = [f"#{r}{g}{b}" for r in color_lst for g in color_lst for b in color_lst]
for i in m, -m:
for j in n, -n:
points.append([0, j, i])
points.append([i, 0, j])
points.append([j, i, 0])
for p in itertools.combinations(points, 3):
dis = math.hypot(*[statistics.mean(c[i] for c in p) for i in range(3)])
if math.isclose(dis, dis_side):
three.Plane(space, *p, fill=colors[count], outline="grey")
count += 1
### Outside ###
r = 250
O = three.Point(space, (0, 0, 0), fill='white', size=3)
X = three.Line(space, (0, 0, 0), (1, 0, 0), fill='')
Y = three.Line(space, (0, 0, 0), (0, 1, 0), fill='')
Z = three.Line(space, (0, 0, 0), (0, 0, 1), fill='')
ring: dict[str, list[three.Text3D]] = {'x': [], 'y': [], 'z': []}
line: dict[str, list[three.Text3D]] = {'x': [], 'y': [], 'z': []}
for i in range(26):
t = chr(65+i)
φ = i/26 * math.tau
c1 = r * math.sin(φ)
c2 = r * math.cos(φ)
ring['x'].append(three.Text3D(space, (0, c1, c2), text=t, fill='#FF0000'))
ring['y'].append(three.Text3D(space, (c1, 0, c2), text=t, fill='#00FF00'))
ring['z'].append(three.Text3D(space, (c1, c2, 0), text=t, fill='#0000FF'))
for i in range(10):
t = str(i)
c = (i+1) * 500/11 - r
line['x'].append(three.Text3D(space, (c, 0, 0), text=t, fill='#00FFFF'))
line['y'].append(three.Text3D(space, (0, c, 0), text=t, fill='#FF00FF'))
line['z'].append(three.Text3D(space, (0, 0, c), text=t, fill='#FFFF00'))
def text_animation() -> None:
"""Make the Text spin."""
for obj3D in ring['x']:
obj3D.rotate(0.05, axis=X.coordinates)
for obj3D in ring['y']:
obj3D.rotate(0.05, axis=Y.coordinates)
for obj3D in ring['z']:
obj3D.rotate(0.05, axis=Z.coordinates)
for obj3D in line['x']:
obj3D.rotate(-0.05, axis=Y.coordinates)
for obj3D in line['y']:
obj3D.rotate(-0.05, axis=Z.coordinates)
for obj3D in line['z']:
obj3D.rotate(-0.05, axis=X.coordinates)
for obj3D in space.components:
obj3D.rotate(0, -0.01, 0.01, center=O.center())
obj3D.update()
space.space_sort()
tk.after(10, text_animation)
text_animation()
tk.mainloop()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tkintertools_3d-1.0.3.tar.gz
(12.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tkintertools_3d-1.0.3.tar.gz.
File metadata
- Download URL: tkintertools_3d-1.0.3.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30532c4a3bdce0c8b5bf71174c356e4ecb2c3debf85def523b3c00ca1775bc94
|
|
| MD5 |
cba03356df861021a92841e4f29c5906
|
|
| BLAKE2b-256 |
b73d68cd0ea02fca73fb8de04b52514ea3b41e2abecd8f100483a29aaa0f2f2a
|
File details
Details for the file tkintertools_3d-1.0.3-py3-none-any.whl.
File metadata
- Download URL: tkintertools_3d-1.0.3-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb153108c0fc055ea785113be73a75364e0073e2b7cc197c80f436bd5775a493
|
|
| MD5 |
a3c95fdb877ad3e4a0bdbe9565d9e973
|
|
| BLAKE2b-256 |
cc577b6b321a5ded8637d787ef814f5a6ce11d04dae7bc05d47586ebea724033
|