My sample Python package
Project description
简介
世界景象创建工具
这是一个用于创建世界的Python工具,基于Pygame库实现。它允许用户创建不同模式的窗口,设置背景颜色或背景图像,绘制和更新图形等。
功能
- 创建不同模式的窗口(普通、无边框、全屏)
- 设置窗口背景颜色或背景图像
- 绘制矩形、圆形和线条等图形
- 更新图形位置和状态
- 支持多窗口创建
安装
确保你已经安装了Pygame库,如果没有安装,可以使用以下命令进行安装:
pip install pygame
使用方法:
创建窗口
from CreateWorld import create2dworld
# 创建一个2D世界对象
world = create2dworld(width=800, height=600, name="My 2D World")
# 运行窗口
world.run(mode='normal', color=(255, 255, 255))
设置背景
# 设置背景颜色
world.run(mode='normal', color=(255, 0, 0)) # 红色背景
# 设置背景图像
world.run(mode='normal', image_path='path/to/your/image.jpg')
绘制图形
# 定义图形
shapes = [
{'type': 'rectangle', 'color': (0, 255, 0), 'rect': (100, 100, 200, 150)},
{'type': 'circle', 'color': (0, 0, 255), 'center': (400, 300), 'radius': 50},
{'type': 'line', 'color': (255, 255, 0), 'start_pos': (0, 0), 'end_pos': (800, 600), 'width': 5}
]
# 绘制图形
world.run(mode='normal', color=(255, 255, 255), draw_shapes=True, shapes=shapes)
更新图形
# 定义更新函数
def update_shapes(shapes, dt):
for shape in shapes:
if shape['type'] == 'rectangle':
shape['rect'][0] += 1 # 移动矩形
# 运行窗口并更新图形
world.run(mode='normal', color=(255, 255, 255), draw_shapes=True, shapes=shapes, control_func=update_shapes)
示例:
以下是一个完整的示例,展示了如何创建一个带有背景颜色和图形的2D窗口:
from CreateWorld import create2dworld
# 创建2D世界对象
world = create2dworld(width=800, height=600, name="My 2D World")
# 定义图形
shapes = [
{'type': 'rectangle', 'color': (0, 255, 0), 'rect': (100, 100, 200, 150)},
{'type': 'circle', 'color': (0, 0, 255), 'center': (400, 300), 'radius': 50},
{'type': 'line', 'color': (255, 255, 0), 'start_pos': (0, 0), 'end_pos': (800, 600), 'width': 5}
]
# 定义更新函数
def update_shapes(shapes, dt):
for shape in shapes:
if shape['type'] == 'rectangle':
shape['rect'][0] += 1 # 移动矩形
# 运行窗口
world.run(mode='normal', color=(255, 255, 255), draw_shapes=True, shapes=shapes, control_func=update_shapes)
Introduction
World Scene Creation Tool
This is a Python tool for creating worlds, implemented based on the Pygame library. It allows users to create windows in different modes, set background colors or background images, draw and update graphics, etc.
Features
• Create windows in different modes (normal, borderless, fullscreen)
• Set window background color or background image• Draw rectangles, circles, and lines, etc.• Update the position and state of graphics
• Support for creating multiple windows
Installation:
Make sure you have the Pygame library installed. If not, you can install it using the following command:
pip install pygame
Usage:
• Creating a Window
from CreateWorld import create2dworld
# Create a 2D world object
world = create2dworld(width=800, height=600, name="My 2D World")
# Run the window
world.run(mode='normal', color=(255, 255, 255))
• Setting the Backgroundpython# Set background color
world.run(mode='normal', color=(255, 0, 0)) # Red background
# Set background image
world.run(mode='normal', image_path='path/to/your/image.jpg')
• Drawing Graphicspython# Define graphics
shapes = [
{'type': 'rectangle', 'color': (0, 255, 0), 'rect': (100, 100, 200, 150)},
{'type': 'circle', 'color': (0, 0, 255), 'center': (400, 300), 'radius': 50},
{'type': 'line', 'color': (255, 255, 0), 'start_pos': (0, 0), 'end_pos': (800, 600), 'width': 5}
]
# Draw graphics
world.run(mode='normal', color=(255, 255, 255), draw_shapes=True, shapes=shapes)
• Updating Graphicspython# Define update function
def update_shapes(shapes, dt):
for shape in shapes:
if shape['type'] == 'rectangle':
shape['rect'][0] += 1 # Move the rectangle
# Run the window and update graphics
world.run(mode='normal', color=(255, 255, 255), draw_shapes=True, shapes=shapes, control_func=update_shapes)
Example:• The following is a complete example showing how to create a 2D window with a background color and graphics:pythonfrom CreateWorld import create2dworld
# Create a 2D world object
world = create2dworld(width=800, height=600, name="My 2D World")
# Define graphics
shapes = [
{'type': 'rectangle', 'color': (0, 255, 0), 'rect': (100, 100, 200, 150)},
{'type': 'circle', 'color': (0, 0, 255), 'center': (400, 300), 'radius': 50},
{'type': 'line', 'color': (255, 255, 0), 'start_pos': (0, 0), 'end_pos': (800, 600), 'width': 5}
]
# Define update function
def update_shapes(shapes, dt):
for shape in shapes:
if shape['type'] == 'rectangle':
shape['rect'][0] += 1 # Move the rectangle
# Run the window
world.run(mode='normal', color=(255, 255, 255), draw_shapes=True, shapes=shapes, control_func=update_shapes)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
createworld-0.1.0.tar.gz
(4.7 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 createworld-0.1.0.tar.gz.
File metadata
- Download URL: createworld-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea7118142f60fb35a134ca7b66c263996f88c38c7522ed15824133d4ae80b67e
|
|
| MD5 |
d364b659284645098319309bc81017c5
|
|
| BLAKE2b-256 |
74f820b709799a2075512dbade92a43c31a36aed8f2d3144e965aab2b26b71ac
|
File details
Details for the file CreateWorld-0.1.0-py3-none-any.whl.
File metadata
- Download URL: CreateWorld-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8df28d4bd740536a2bbac899f5886ac2c872779de89d91818dc29efb1ddf2a10
|
|
| MD5 |
6d3b2ff3b2de8c3302a4a105e210b6c2
|
|
| BLAKE2b-256 |
7c7f2ca20e950822808a11f51c3807269df9093844651e4e41acc823441690f8
|