Skip to main content

🎨 基础绘图工具 - 16个核心MCP绘图工具

Project description

🎨 GamePainter - 基础绘图工具

提供 16 个核心绘图工具,通过组合可绑制任意复杂图形!

Python PyPI MCP License

✨ 特性

  • 🎨 16 个核心工具 - 精简设计,功能完整
  • 🔧 MCP 工具集成 - 可被 AI 助手直接调用
  • 📐 灵活组合 - 基础图形组合成复杂图案
  • 🖼️ 图片处理 - 清除背景、裁切、缩放等
  • 🚀 开箱即用 - 无需复杂配置

🚀 快速开始

安装

从 PyPI 安装(推荐):

pip install game-painter

或从源码安装:

# 克隆项目
git clone https://github.com/dzqdzq/game-painter.git
cd game-painter

# 创建虚拟环境并安装依赖
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -e .

直接使用

from painter import GamePainter

# 创建画布
p = GamePainter(200, 150, bg_color=(240, 240, 240, 255))

# 画一个房子
p.pen_rect(50, 60, 100, 80, fill_color=(255, 230, 180, 255))  # 墙
p.pen_polygon([(50, 60), (100, 20), (150, 60)], fill_color=(180, 80, 50, 255))  # 屋顶
p.pen_rect(85, 100, 30, 40, fill_color=(139, 90, 43, 255))  # 门

# 保存
p.save("house.png")

🔌 MCP 工具配置

安装完成后,在 Cursor 或 Claude Desktop 中配置 MCP 服务器。

Cursor 配置

打开 Cursor Settings,找到 MCP 设置,添加配置:

{
  "mcpServers": {
    "game-painter": {
      "command": "uvx",
      "args": ["game-painter"]
    }
  }
}

或者如果你使用的是虚拟环境:

{
  "mcpServers": {
    "game-painter": {
      "command": "python",
      "args": ["-m", "server"]
    }
  }
}

Claude Desktop 配置

编辑 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS)或相应配置文件:

{
  "mcpServers": {
    "game-painter": {
      "command": "uvx",
      "args": ["game-painter"]
    }
  }
}

或使用 Python 直接运行:

{
  "mcpServers": {
    "game-painter": {
      "command": "python",
      "args": ["-m", "server"]
    }
  }
}

💡 提示:确保安装 game-painter 的 Python 环境在系统 PATH 中,或使用完整的 Python 路径。

🛠️ 工具列表 (16 个)

画布管理

工具 说明
create_canvas 创建画布(第一步)
save 保存画布为图片

线条类

工具 说明
line 直线/虚线
polyline 折线/多段线
arc 弧线
bezier 贝塞尔曲线
wave 波浪线

形状类

工具 说明
rect 矩形/圆角矩形
ellipse 椭圆/正圆
polygon 多边形(三角形、六边形等)

图标类

工具 说明
icon 五角星、箭头

辅助类

工具 说明
text 文字

图片处理类

工具 说明
remove_background AI 智能清除背景
resize_image 缩放图片
auto_crop_transparent 自动裁切透明区域(PNG)
crop_region 指定区域裁切

📖 工具详情

1. create_canvas - 创建画布

width: 画布宽度(默认 200)
height: 画布高度(默认 200)
bg_color: 背景颜色 [R,G,B,A](默认透明)
canvas_id: 画布 ID(默认 "default")

2. line - 画直线

x1, y1: 起点坐标
x2, y2: 终点坐标
color: 颜色 [R,G,B,A]
width: 线宽
dash: 虚线模式 [线段长, 间隔长],如 [10, 5]

3. polyline - 画折线

points: 点坐标列表 [[x1,y1], [x2,y2], ...]
closed: 是否闭合
dash: 虚线模式

4. arc - 画弧线

x, y: 外接矩形左上角
width, height: 外接矩形尺寸
start_angle: 起始角度(度)
end_angle: 结束角度(度)

5. bezier - 画贝塞尔曲线

points: 控制点列表
  - 2 点 = 直线
  - 3 点 = 二次曲线
  - 4 点 = 三次曲线

6. wave - 画波浪线

x1, y1: 起点
x2, y2: 终点
amplitude: 振幅(默认 10)
wavelength: 波长(默认 20)

7. rect - 画矩形

x, y: 左上角坐标
width, height: 尺寸
fill_color: 填充颜色
border_color: 边框颜色
radius: 圆角半径(0 为直角)

8. ellipse - 画椭圆

x, y: 外接矩形左上角
width, height: 尺寸(相等则为正圆)
fill_color: 填充颜色
border_color: 边框颜色

9. polygon - 画多边形

支持两种模式:

模式 1:自定义顶点

points: [[x1,y1], [x2,y2], ...]

模式 2:正多边形

cx, cy: 中心坐标
radius: 外接圆半径
sides: 边数(3=三角形, 6=六边形)
rotation: 旋转角度

10. icon - 画图标

icon_type: "star" 或 "arrow"
cx, cy: 中心坐标
size: 图标大小
direction: 箭头方向(up/down/left/right)
points: 星角数量(默认 5)

11. text - 写文字

x, y: 位置
text: 文字内容
color: 颜色
font_size: 字体大小

12. save - 保存画布

filename: 文件名
output_dir: 输出目录(可选)

13. remove_background - 清除背景

image_path: 图片文件路径
image_base64: 图片 base64 数据
image_url: 图片 URL(必须 https 且有后缀)
alpha_matting: 是否使用 alpha matting(改善边缘)
bgcolor: 背景颜色(可选,不设置则透明)

三个图片来源参数只能提供一个

14. resize_image - 缩放图片

image_path: 图片文件路径
image_base64: 图片 base64 数据
image_url: 图片 URL
width: 目标宽度(高度自动等比缩放)
height: 目标高度(宽度自动等比缩放)

width 和 height 只能提供一个,避免图片变形

15. auto_crop_transparent - 自动裁切透明区域

image_path: 图片文件路径
image_base64: 图片 base64 数据
image_url: 图片 URL(必须是 PNG 格式)

只支持 PNG 格式,自动去除四周的透明边缘

16. crop_region - 指定区域裁切

image_path: 图片文件路径
image_base64: 图片 base64 数据
image_url: 图片 URL
x: 裁切区域左上角 X 坐标
y: 裁切区域左上角 Y 坐标
width: 裁切区域宽度
height: 裁切区域高度

支持所有图片格式

🎨 使用示例

画小汽车

1. create_canvas(width=200, height=100)
2. polygon(points=车身坐标)        # 车身
3. polygon(points=车顶坐标)        # 车顶
4. polygon(points=车窗坐标)        # 车窗
5. ellipse(x, y, 30, 30)           # 轮子
6. save(filename="car.png")

画花朵

1. create_canvas(width=150, height=180)
2. rect(茎)
3. bezier(叶子弯曲)
4. ellipse(花瓣 x 4)
5. ellipse(花心)
6. save(filename="flower.png")

图片处理:清除背景并裁切

1. remove_background(image_path="photo.jpg")      # 清除背景
2. auto_crop_transparent(image_path="result.png")  # 自动裁切透明区域
3. resize_image(image_path="cropped.png", width=256)  # 缩放到指定宽度

图片处理:裁切头像

1. crop_region(
     image_path="photo.jpg",
     x=100, y=100,    # 裁切位置
     width=200, height=200  # 裁切尺寸
   )

📄 License

MIT License


Made with ❤️ for Developers

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

game_painter-2.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

game_painter-2.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file game_painter-2.1.0.tar.gz.

File metadata

  • Download URL: game_painter-2.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for game_painter-2.1.0.tar.gz
Algorithm Hash digest
SHA256 58aabf3f6602b033f26af63834a0f9e0ae58625c0ec5ff6d6fa6a3b8a9fc040f
MD5 660b67af646f74ba753d849f8d5f225e
BLAKE2b-256 0081e4db2cff48ada5ce20a6c076554bd0fbc334dd78312d83593c409de4a102

See more details on using hashes here.

File details

Details for the file game_painter-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: game_painter-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for game_painter-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fc2446ee91713b1e57ed181f4bd3272263da791fcf643832d3573abc1fb4d13
MD5 61ef3da03cffa000c3ca246c04726d8c
BLAKE2b-256 65212695dfc26ddcc71e50acae54d3c821bee54b6e56b7621f0ea0ce5eaddea9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page