Update
This commit is contained in:
parent
afd1a37c0c
commit
5519a8595b
52
auxiliary/aux.py
Normal file
52
auxiliary/aux.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
def selector():
|
||||||
|
pygame.init()
|
||||||
|
try:
|
||||||
|
width = int(input("Frame Width: "))
|
||||||
|
height = int(input("Frame Height: "))
|
||||||
|
except:
|
||||||
|
width = 800
|
||||||
|
height = 600
|
||||||
|
screen = pygame.display.set_mode((width, height))
|
||||||
|
pygame.display.set_caption("UI Design Auxiliary Tool")
|
||||||
|
selecting = False
|
||||||
|
start_pos = None
|
||||||
|
end_pos = None
|
||||||
|
running = True
|
||||||
|
screen.fill((0,0,0))
|
||||||
|
while running:
|
||||||
|
screen.fill((0,0,0))
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
if event.button == 1: # 左键
|
||||||
|
selecting = True
|
||||||
|
start_pos = event.pos
|
||||||
|
elif event.type == pygame.MOUSEMOTION:
|
||||||
|
if selecting:
|
||||||
|
end_pos = event.pos
|
||||||
|
elif event.type == pygame.MOUSEBUTTONUP:
|
||||||
|
if event.button == 1:
|
||||||
|
selecting = False
|
||||||
|
if start_pos and end_pos:
|
||||||
|
rect = pygame.Rect(
|
||||||
|
start_pos,
|
||||||
|
(end_pos[0] - start_pos[0], end_pos[1] - start_pos[1]),
|
||||||
|
)
|
||||||
|
|
||||||
|
if selecting and start_pos and end_pos:
|
||||||
|
rect = pygame.Rect(
|
||||||
|
start_pos, (end_pos[0] - start_pos[0], end_pos[1] - start_pos[1])
|
||||||
|
)
|
||||||
|
pygame.draw.rect(screen, (255, 0, 0), rect, 2) # 绘制选区矩形
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
28
auxiliary/index.html
Normal file
28
auxiliary/index.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>图形参数生成器</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>图形参数生成器</h1>
|
||||||
|
<label for="shape">图形类型:</label>
|
||||||
|
<select id="shape">
|
||||||
|
<option value="rect">矩形</option>
|
||||||
|
<option value="line">线条</option>
|
||||||
|
<option value="circle">圆形</option>
|
||||||
|
<option value="ellipse">椭圆</option>
|
||||||
|
<option value="polygon">多边形</option>
|
||||||
|
<option value="arc">弧形</option>
|
||||||
|
<option value="point">点</option>
|
||||||
|
<option value="lines">线段</option>
|
||||||
|
</select><br><br>
|
||||||
|
|
||||||
|
<div id="params"></div><br>
|
||||||
|
|
||||||
|
<button id="generate">生成图形参数</button><br><br>
|
||||||
|
|
||||||
|
<div id="result"></div>
|
||||||
|
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
152
auxiliary/script.js
Normal file
152
auxiliary/script.js
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
function generateShapeDict(shape, params) {
|
||||||
|
if (shape === 'rect') {
|
||||||
|
return {
|
||||||
|
method: 'rect',
|
||||||
|
pos: params.pos || [0, 0],
|
||||||
|
size: params.size || [1, 1],
|
||||||
|
color: params.color || [255, 255, 255],
|
||||||
|
width: params.width || 0
|
||||||
|
};
|
||||||
|
} else if (shape === 'line') {
|
||||||
|
return {
|
||||||
|
method: 'line',
|
||||||
|
start_pos: params.start_pos || [0, 0],
|
||||||
|
end_pos: params.end_pos || [1, 1],
|
||||||
|
color: params.color || [255, 255, 255]
|
||||||
|
};
|
||||||
|
} else if (shape === 'circle') {
|
||||||
|
return {
|
||||||
|
method: 'circle',
|
||||||
|
center: params.center || [0, 0],
|
||||||
|
radius: params.radius || 1,
|
||||||
|
color: params.color || [255, 255, 255]
|
||||||
|
};
|
||||||
|
} else if (shape === 'ellipse') {
|
||||||
|
return {
|
||||||
|
method: 'ellipse',
|
||||||
|
pos: params.pos || [0, 0],
|
||||||
|
size: params.size || [1, 1],
|
||||||
|
color: params.color || [255, 255, 255]
|
||||||
|
};
|
||||||
|
} else if (shape === 'polygon') {
|
||||||
|
return {
|
||||||
|
method: 'polygon',
|
||||||
|
pointlist: params.pointlist || [],
|
||||||
|
color: params.color || [255, 255, 255]
|
||||||
|
};
|
||||||
|
} else if (shape === 'arc') {
|
||||||
|
return {
|
||||||
|
method: 'arc',
|
||||||
|
pos: params.pos || [0, 0],
|
||||||
|
size: params.size || [1, 1],
|
||||||
|
color: params.color || [255, 255, 255],
|
||||||
|
start_angle: params.start_angle || 0,
|
||||||
|
stop_angle: params.stop_angle || 3.14
|
||||||
|
};
|
||||||
|
} else if (shape === 'point') {
|
||||||
|
return {
|
||||||
|
method: 'point',
|
||||||
|
pos: params.pos || [0, 0],
|
||||||
|
color: params.color || [255, 255, 255]
|
||||||
|
};
|
||||||
|
} else if (shape === 'lines') {
|
||||||
|
return {
|
||||||
|
method: 'lines',
|
||||||
|
pointlist: params.pointlist || [],
|
||||||
|
color: params.color || [255, 255, 255]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
throw new Error("Unsupported shape type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const shapeSelect = document.getElementById('shape');
|
||||||
|
const paramsDiv = document.getElementById('params');
|
||||||
|
const generateButton = document.getElementById('generate');
|
||||||
|
const resultDiv = document.getElementById('result');
|
||||||
|
|
||||||
|
function createInput(label, id, type = 'text') {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = type;
|
||||||
|
input.id = id;
|
||||||
|
const labelElement = document.createElement('label');
|
||||||
|
labelElement.textContent = label + ': ';
|
||||||
|
labelElement.setAttribute('for', id);
|
||||||
|
paramsDiv.appendChild(labelElement);
|
||||||
|
paramsDiv.appendChild(input);
|
||||||
|
paramsDiv.appendChild(document.createElement('br'));
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateParamsInputs() {
|
||||||
|
paramsDiv.innerHTML = '';
|
||||||
|
const shape = shapeSelect.value;
|
||||||
|
|
||||||
|
if (shape === 'rect') {
|
||||||
|
createInput('矩形位置 (x y)', 'pos');
|
||||||
|
createInput('矩形大小 (width height)', 'size');
|
||||||
|
createInput('矩形颜色 (R G B)', 'color');
|
||||||
|
createInput('矩形边框宽度', 'width', 'number');
|
||||||
|
} else if (shape === 'line') {
|
||||||
|
createInput('起始位置 (x y)', 'start_pos');
|
||||||
|
createInput('结束位置 (x y)', 'end_pos');
|
||||||
|
createInput('线条颜色 (R G B)', 'color');
|
||||||
|
} else if (shape === 'circle') {
|
||||||
|
createInput('圆心位置 (x y)', 'center');
|
||||||
|
createInput('圆的半径', 'radius', 'number');
|
||||||
|
createInput('圆的颜色 (R G B)', 'color');
|
||||||
|
} else if (shape === 'ellipse') {
|
||||||
|
createInput('椭圆位置 (x y)', 'pos');
|
||||||
|
createInput('椭圆大小 (width height)', 'size');
|
||||||
|
createInput('椭圆颜色 (R G B)', 'color');
|
||||||
|
} else if (shape === 'polygon') {
|
||||||
|
createInput('多边形的点 (x1 y1 x2 y2 ...)', 'pointlist');
|
||||||
|
createInput('多边形颜色 (R G B)', 'color');
|
||||||
|
} else if (shape === 'arc') {
|
||||||
|
createInput('弧的位置 (x y)', 'pos');
|
||||||
|
createInput('弧的大小 (width height)', 'size');
|
||||||
|
createInput('弧的颜色 (R G B)', 'color');
|
||||||
|
createInput('弧的起始角度 (弧度制)', 'start_angle', 'number');
|
||||||
|
createInput('弧的结束角度 (弧度制)', 'stop_angle', 'number');
|
||||||
|
} else if (shape === 'point') {
|
||||||
|
createInput('点的位置 (x y)', 'pos');
|
||||||
|
createInput('点的颜色 (R G B)', 'color');
|
||||||
|
} else if (shape === 'lines') {
|
||||||
|
createInput('线段的点 (x1 y1 x2 y2 ...)', 'pointlist');
|
||||||
|
createInput('线段颜色 (R G B)', 'color');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shapeSelect.addEventListener('change', updateParamsInputs);
|
||||||
|
updateParamsInputs();
|
||||||
|
|
||||||
|
generateButton.addEventListener('click', function() {
|
||||||
|
const shape = shapeSelect.value;
|
||||||
|
const params = {};
|
||||||
|
const inputs = paramsDiv.querySelectorAll('input');
|
||||||
|
|
||||||
|
inputs.forEach(input => {
|
||||||
|
if (input.id === 'pointlist') {
|
||||||
|
const points = input.value.split(' ').map(Number);
|
||||||
|
params.pointlist = [];
|
||||||
|
for (let i = 0; i < points.length; i += 2) {
|
||||||
|
params.pointlist.push([points[i], points[i + 1]]);
|
||||||
|
}
|
||||||
|
} else if (input.id === 'pos' || input.id === 'size' || input.id === 'start_pos' || input.id === 'end_pos' || input.id === 'center' || input.id === 'color') {
|
||||||
|
params[input.id] = input.value.split(' ').map(Number);
|
||||||
|
} else if (input.type === 'number') {
|
||||||
|
params[input.id] = parseFloat(input.value);
|
||||||
|
} else {
|
||||||
|
params[input.id] = input.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const shapeDict = generateShapeDict(shape, params);
|
||||||
|
resultDiv.innerHTML = '<pre>' + JSON.stringify(shapeDict, null, 2) + '</pre>';
|
||||||
|
} catch (error) {
|
||||||
|
resultDiv.innerHTML = '<p>错误: ' + error.message + '</p>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
59
pulsar/1.py
59
pulsar/1.py
@ -1,59 +0,0 @@
|
|||||||
import pygame
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# 初始化 Pygame
|
|
||||||
pygame.init()
|
|
||||||
|
|
||||||
# 设置窗口大小
|
|
||||||
width, height = 800, 600
|
|
||||||
screen = pygame.display.set_mode((width, height))
|
|
||||||
pygame.display.set_caption("Pygame Draw Example")
|
|
||||||
|
|
||||||
# 定义颜色
|
|
||||||
BLACK = (0, 0, 0)
|
|
||||||
WHITE = (255, 255, 255)
|
|
||||||
RED = (255, 0, 0)
|
|
||||||
GREEN = (0, 255, 0)
|
|
||||||
BLUE = (0, 0, 255)
|
|
||||||
YELLOW = (255, 255, 0)
|
|
||||||
|
|
||||||
# 主循环
|
|
||||||
running = True
|
|
||||||
while running:
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
# 填充背景
|
|
||||||
screen.fill(WHITE)
|
|
||||||
|
|
||||||
# 绘制线条
|
|
||||||
pygame.draw.line(screen, RED, (50, 50), (200, 50), 5)
|
|
||||||
pygame.draw.aaline(screen, BLUE, (50, 100), (200, 100))
|
|
||||||
|
|
||||||
# 绘制矩形
|
|
||||||
pygame.draw.rect(screen, GREEN, (50, 150, 150, 100), 0) # 填充矩形
|
|
||||||
pygame.draw.rect(screen, BLACK, (250, 150, 150, 100), 5) # 边框矩形
|
|
||||||
|
|
||||||
# 绘制圆形
|
|
||||||
pygame.draw.circle(screen, YELLOW, (400, 200), 50, 0) # 填充圆形
|
|
||||||
pygame.draw.circle(screen, BLACK, (500, 200), 50, 5) # 边框圆形
|
|
||||||
|
|
||||||
# 绘制椭圆
|
|
||||||
pygame.draw.ellipse(screen, BLUE, (50, 300, 200, 100), 0) # 填充椭圆
|
|
||||||
pygame.draw.ellipse(screen, BLACK, (300, 300, 200, 100), 5) # 边框椭圆
|
|
||||||
|
|
||||||
# 绘制多边形
|
|
||||||
points = [(600, 400), (700, 300), (800, 400), (700, 500)]
|
|
||||||
pygame.draw.polygon(screen, GREEN, points, 0) # 填充多边形
|
|
||||||
pygame.draw.polygon(screen, BLACK, points, 5) # 边框多边形
|
|
||||||
|
|
||||||
# 绘制弧
|
|
||||||
pygame.draw.arc(screen, RED, (50, 450, 200, 100), 0, 3.14, 5) # 弧
|
|
||||||
|
|
||||||
# 更新显示
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
# 退出 Pygame
|
|
||||||
pygame.quit()
|
|
||||||
sys.exit()
|
|
BIN
pulsar/__pycache__/graph_lib.cpython-312.pyc
Normal file
BIN
pulsar/__pycache__/graph_lib.cpython-312.pyc
Normal file
Binary file not shown.
@ -1,43 +0,0 @@
|
|||||||
import pygame
|
|
||||||
|
|
||||||
class Graph:
|
|
||||||
def rect(frame, position: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), width: int = 0):
|
|
||||||
pygame.draw.rect(frame.surface, color=color, rect=(position[0], position[1], size[0], size[1]), width=width)
|
|
||||||
|
|
||||||
def line(frame, start_pos: tuple, end_pos: tuple, color: tuple = (255, 255, 255)):
|
|
||||||
pygame.draw.aaline(frame.surface, color, start_pos, end_pos)
|
|
||||||
|
|
||||||
def circle(frame, center: tuple, radius: int, color: tuple = (255, 255, 255), width: int = 0):
|
|
||||||
pygame.draw.circle(frame.surface, color, center, radius, width)
|
|
||||||
|
|
||||||
def ellipse(frame, rect: tuple, color: tuple = (255, 255, 255), width: int = 0):
|
|
||||||
pygame.draw.ellipse(frame.surface, color, rect, width)
|
|
||||||
|
|
||||||
def polygon(frame, pointlist: list, color: tuple = (255, 255, 255), width: int = 0):
|
|
||||||
pygame.draw.polygon(frame.surface, color, pointlist, width)
|
|
||||||
|
|
||||||
def arc(frame, rect: tuple, color: tuple = (255, 255, 255), start_angle: float = 0, stop_angle: float = 3.14, width: int = 1):
|
|
||||||
pygame.draw.arc(frame.surface, color, rect, start_angle, stop_angle, width)
|
|
||||||
|
|
||||||
def points(frame, pos: tuple, color: tuple = (255, 255, 255)):
|
|
||||||
pygame.draw.point(frame.surface, color, pos)
|
|
||||||
|
|
||||||
def lines(frame, pointlist: list, color: tuple = (255, 255, 255), closed: bool = False):
|
|
||||||
pygame.draw.aalines(frame.surface, color, closed, pointlist)
|
|
||||||
|
|
||||||
class Frame(object):
|
|
||||||
name = None
|
|
||||||
size = None
|
|
||||||
surface = None
|
|
||||||
is_hide = False
|
|
||||||
def __init__(self, name: str, size: tuple):
|
|
||||||
self.name = name
|
|
||||||
self.surface = pygame.Surface(size, flags=pygame.HWSURFACE)
|
|
||||||
print("初始化子模块")
|
|
||||||
def show(self, window, position: tuple):
|
|
||||||
if not self.is_hide:
|
|
||||||
window.blit(self.surface, position)
|
|
||||||
def set_visible(self, newstat=True):
|
|
||||||
self.is_hide = newstat
|
|
||||||
def set_position(self, newposition):
|
|
||||||
self.position = newposition
|
|
1
testfield/vgl/README.md
Normal file
1
testfield/vgl/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# VGL - 矢量图形渲染库
|
113
testfield/vgl/aux.py
Normal file
113
testfield/vgl/aux.py
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
def generate_shape_dict(shape, **kwargs):
|
||||||
|
if shape == 'rect':
|
||||||
|
return {
|
||||||
|
'method': 'rect',
|
||||||
|
'pos': kwargs.get('pos', (0, 0)),
|
||||||
|
'size': kwargs.get('size', (1, 1)),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255)),
|
||||||
|
'width': kwargs.get('width', 0) # 添加边框宽度
|
||||||
|
}
|
||||||
|
elif shape == 'line':
|
||||||
|
return {
|
||||||
|
'method': 'line',
|
||||||
|
'start_pos': kwargs.get('start_pos', (0, 0)),
|
||||||
|
'end_pos': kwargs.get('end_pos', (1, 1)),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255))
|
||||||
|
}
|
||||||
|
elif shape == 'circle':
|
||||||
|
return {
|
||||||
|
'method': 'circle',
|
||||||
|
'center': kwargs.get('center', (0, 0)),
|
||||||
|
'radius': kwargs.get('radius', 1),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255))
|
||||||
|
}
|
||||||
|
elif shape == 'ellipse':
|
||||||
|
return {
|
||||||
|
'method': 'ellipse',
|
||||||
|
'pos': kwargs.get('pos', (0, 0)),
|
||||||
|
'size': kwargs.get('size', (1, 1)),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255))
|
||||||
|
}
|
||||||
|
elif shape == 'polygon':
|
||||||
|
return {
|
||||||
|
'method': 'polygon',
|
||||||
|
'pointlist': kwargs.get('pointlist', []),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255))
|
||||||
|
}
|
||||||
|
elif shape == 'arc':
|
||||||
|
return {
|
||||||
|
'method': 'arc',
|
||||||
|
'pos': kwargs.get('pos', (0, 0)),
|
||||||
|
'size': kwargs.get('size', (1, 1)),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255)),
|
||||||
|
'start_angle': kwargs.get('start_angle', 0),
|
||||||
|
'stop_angle': kwargs.get('stop_angle', 3.14)
|
||||||
|
}
|
||||||
|
elif shape == 'point':
|
||||||
|
return {
|
||||||
|
'method': 'point',
|
||||||
|
'pos': kwargs.get('pos', (0, 0)),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255))
|
||||||
|
}
|
||||||
|
elif shape == 'lines':
|
||||||
|
return {
|
||||||
|
'method': 'lines',
|
||||||
|
'pointlist': kwargs.get('pointlist', []),
|
||||||
|
'color': kwargs.get('color', (255, 255, 255))
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
raise ValueError("Unsupported shape type")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("欢迎使用图形参数生成器!")
|
||||||
|
shape = input("请输入图形类型 (rect, line, circle, ellipse, polygon, arc, point, lines): ").strip().lower()
|
||||||
|
|
||||||
|
params = {}
|
||||||
|
|
||||||
|
if shape == 'rect':
|
||||||
|
params['pos'] = tuple(map(int, input("请输入矩形位置 (x y): ").split()))
|
||||||
|
params['size'] = tuple(map(int, input("请输入矩形大小 (width height): ").split()))
|
||||||
|
params['color'] = tuple(map(int, input("请输入矩形颜色 (R G B): ").split()))
|
||||||
|
params['width'] = int(input("请输入矩形边框宽度: ")) # 添加边框宽度输入
|
||||||
|
elif shape == 'line':
|
||||||
|
params['start_pos'] = tuple(map(int, input("请输入起始位置 (x y): ").split()))
|
||||||
|
params['end_pos'] = tuple(map(int, input("请输入结束位置 (x y): ").split()))
|
||||||
|
params['color'] = tuple(map(int, input("请输入线条颜色 (R G B): ").split()))
|
||||||
|
elif shape == 'circle':
|
||||||
|
params['center'] = tuple(map(int, input("请输入圆心位置 (x y): ").split()))
|
||||||
|
params['radius'] = int(input("请输入圆的半径: "))
|
||||||
|
params['color'] = tuple(map(int, input("请输入圆的颜色 (R G B): ").split()))
|
||||||
|
elif shape == 'ellipse':
|
||||||
|
params['pos'] = tuple(map(int, input("请输入椭圆位置 (x y): ").split()))
|
||||||
|
params['size'] = tuple(map(int, input("请输入椭圆大小 (width height): ").split()))
|
||||||
|
params['color'] = tuple(map(int, input("请输入椭圆颜色 (R G B): ").split()))
|
||||||
|
elif shape == 'polygon':
|
||||||
|
points = input("请输入多边形的点 (x1 y1 x2 y2 ...): ").split()
|
||||||
|
params['pointlist'] = [(int(points[i]), int(points[i + 1])) for i in range(0, len(points), 2)]
|
||||||
|
params['color'] = tuple(map(int, input("请输入多边形颜色 (R G B): ").split()))
|
||||||
|
elif shape == 'arc':
|
||||||
|
params['pos'] = tuple(map(int, input("请输入弧的位置 (x y): ").split()))
|
||||||
|
params['size'] = tuple(map(int, input("请输入弧的大小 (width height): ").split()))
|
||||||
|
params['color'] = tuple(map(int, input("请输入弧的颜色 (R G B): ").split()))
|
||||||
|
params['start_angle'] = float(input("请输入弧的起始角度 (弧度制): "))
|
||||||
|
params['stop_angle'] = float(input("请输入弧的结束角度 (弧度制): "))
|
||||||
|
elif shape == 'point':
|
||||||
|
params['pos'] = tuple(map(int, input("请输入点的位置 (x y): ").split()))
|
||||||
|
params['color'] = tuple(map(int, input("请输入点的颜色 (R G B): ").split()))
|
||||||
|
elif shape == 'lines':
|
||||||
|
points = input("请输入线段的点 (x1 y1 x2 y2 ...): ").split()
|
||||||
|
params['pointlist'] = [(int(points[i]), int(points[i + 1])) for i in range(0, len(points), 2)]
|
||||||
|
params['color'] = tuple(map(int, input("请输入线段颜色 (R G B): ").split()))
|
||||||
|
else:
|
||||||
|
print("不支持的图形类型")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 生成图形字典
|
||||||
|
shape_dict = generate_shape_dict(shape, **params)
|
||||||
|
|
||||||
|
# 输出结果
|
||||||
|
print("生成的图形参数字典:")
|
||||||
|
print(shape_dict)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
26
testfield/vgl/test.py
Normal file
26
testfield/vgl/test.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import pygame
|
||||||
|
import sys
|
||||||
|
from testfield.vgl.vgllib import *
|
||||||
|
pygame.init()
|
||||||
|
window_size = (800, 600)
|
||||||
|
window = pygame.display.set_mode(window_size)
|
||||||
|
|
||||||
|
frame = Frame("Main Frame", window_size)
|
||||||
|
|
||||||
|
# 注册一个矩形组件
|
||||||
|
frame.register("rectangle", {"method": "rect", "pos": (100, 100), "size": (200, 150), "color": (255, 0, 0)})
|
||||||
|
|
||||||
|
# 注册一个圆形组件
|
||||||
|
frame.register("circle", {"method": "circle", "center": (400, 300), "radius": 50, "color": (0, 255, 0)})
|
||||||
|
|
||||||
|
# 主循环
|
||||||
|
while True:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
window.fill((0, 0, 0)) # 清空窗口
|
||||||
|
frame.drawall(frame.components) # 绘制所有组件
|
||||||
|
frame.show(window, (0, 0)) # 显示框架
|
||||||
|
pygame.display.flip() # 更新显示
|
114
testfield/vgl/vgllib.py
Normal file
114
testfield/vgl/vgllib.py
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
# Vector Graphics Library
|
||||||
|
# vgllib.py
|
||||||
|
import pygame
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
class Graph:
|
||||||
|
@staticmethod
|
||||||
|
def rect(frame, pos: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), width: int = 0):
|
||||||
|
pygame.draw.rect(frame.surface, color=color, rect=(pos[0], pos[1], size[0], size[1]), width=width)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def line(frame, start_pos: tuple, end_pos: tuple, color: tuple = (255, 255, 255)):
|
||||||
|
pygame.draw.aaline(frame.surface, color, start_pos, end_pos)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def circle(frame, center: tuple, radius: int, color: tuple = (255, 255, 255), width: int = 0):
|
||||||
|
pygame.draw.circle(frame.surface, color, center, radius, width)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def ellipse(frame, pos: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), width: int = 0):
|
||||||
|
rect=(pos[0], pos[1], size[0], size[1])
|
||||||
|
pygame.draw.ellipse(frame.surface, color, rect, width)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def polygon(frame, pointlist: list, color: tuple = (255, 255, 255), width: int = 0):
|
||||||
|
pygame.draw.polygon(frame.surface, color, pointlist, width)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def arc(frame, pos: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), start_angle: float = 0, stop_angle: float = 3.14, width: int = 1):
|
||||||
|
rect=(pos[0], pos[1], size[0], size[1])
|
||||||
|
pygame.draw.arc(frame.surface, color, rect, start_angle, stop_angle, width)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def point(frame, pos: tuple, color: tuple = (255, 255, 255)):
|
||||||
|
pygame.draw.point(frame.surface, color, pos)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def lines(frame, pointlist: list, color: tuple = (255, 255, 255)):
|
||||||
|
pygame.draw.aalines(frame.surface, color, closed=False, points=pointlist)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def call(frame, method, **kwargs):
|
||||||
|
if hasattr(Graph, method):
|
||||||
|
getattr(Graph, method)(frame, **kwargs)
|
||||||
|
else:
|
||||||
|
print(f"方法 {method} 不存在")
|
||||||
|
|
||||||
|
class Frame(object):
|
||||||
|
components = dict()
|
||||||
|
components_stat = dict()
|
||||||
|
def __init__(self, name: str, size: tuple):
|
||||||
|
self.name = name
|
||||||
|
self.size = size
|
||||||
|
self.surface = pygame.Surface(size, flags=pygame.HWSURFACE)
|
||||||
|
self.is_hide = False
|
||||||
|
print("初始化子模块")
|
||||||
|
|
||||||
|
def show(self, window, position: tuple):
|
||||||
|
if not self.is_hide:
|
||||||
|
window.blit(self.surface, position)
|
||||||
|
|
||||||
|
def set_visible(self, newstat=True):
|
||||||
|
self.is_hide = newstat
|
||||||
|
|
||||||
|
def set_position(self, newposition):
|
||||||
|
self.position = newposition
|
||||||
|
|
||||||
|
def register(self, subname="", attr=None):
|
||||||
|
if subname == "":
|
||||||
|
subname = uuid.uuid4()
|
||||||
|
self.components[subname] = attr
|
||||||
|
self.components_stat[subname] = 1 # by default, not hiding
|
||||||
|
|
||||||
|
def draw(self, attr):
|
||||||
|
attr['pos'][0] = round(attr['pos'][0] / 100 * self.size[1])
|
||||||
|
attr['pos'][0] = round(attr['pos'][0] / 100 * self.size[1])
|
||||||
|
attr['pos'][0] = round(attr['pos'][0] / 100 * self.size[1])
|
||||||
|
attr['pos'][0] = round(attr['pos'][0] / 100 * self.size[1])
|
||||||
|
Graph.call(self, **attr)
|
||||||
|
|
||||||
|
def set_component_visible(self, subname, newstat):
|
||||||
|
self.components_stat[subname] = newstat
|
||||||
|
|
||||||
|
def drawall(self, attr):
|
||||||
|
for i in self.components.keys():
|
||||||
|
if self.components_stat[i]:
|
||||||
|
self.draw(self.components[i])
|
||||||
|
|
||||||
|
def clear(self, color=(0,0,0)):
|
||||||
|
self.surface.fill(color)
|
||||||
|
|
||||||
|
def loads(self, ):
|
||||||
|
|
||||||
|
|
||||||
|
# 示例
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pygame.init()
|
||||||
|
window = pygame.display.set_mode((800, 600))
|
||||||
|
frame = Frame("Test", (800, 600))
|
||||||
|
|
||||||
|
frame.draw({'method':'rect', 'pos':(50, 50), 'size':(200, 100), 'color':(255, 0, 0)}) # 绘制红色矩形
|
||||||
|
|
||||||
|
# 主循环
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
window.fill((0, 0, 0)) # 清空窗口
|
||||||
|
frame.show(window, (0, 0)) # 显示帧
|
||||||
|
pygame.display.flip() # 更新显示
|
||||||
|
|
||||||
|
pygame.quit()
|
Loading…
x
Reference in New Issue
Block a user