fantas V3

Docs License Python pygame Code style: black

快速开始

欢迎了解 fantas!这是一个基于 pygame-ce [1] 的 2D 图形程序框架。 当你安装好 fantas 后,下一个问题就是怎样让程序运行起来。你可能知道,pygame-ce 并不是一个开箱即用的库,它需要你完全掌控整个主循环,这对于初学者来说可能会有些困难。 幸运的是,fantas 帮你做好了一切。

安装 fantas

fantas 可以通过 pip 轻松安装:

pip install fantas

小试牛刀

来看一个简单的例子吧:

 1import fantas
 2
 3# 创建窗口
 4window = fantas.Window(
 5    fantas.WindowConfig(
 6        title="Hello, Fantas!",
 7        window_size=(800, 600),
 8    )
 9)
10
11# 创建渐变背景
12background = fantas.LinearGradientLabel(
13    rect=fantas.Rect((0, 0), window.size),
14    start_color=fantas.Color('red'),
15    end_color=fantas.Color('blue'),
16    start_pos=(0, 0),
17    end_pos=window.size
18)
19window.append(background)
20
21# 设置默认文本样式
22fantas.DEFAULTTEXTSTYLE.font = fantas.fonts.DEFAULTSYSFONT
23fantas.DEFAULTTEXTSTYLE.size = 90
24# 创建文本
25text = fantas.Text(
26    text="好好学习\n天天向上",
27    rect=fantas.Rect(0, 0, 600, 300),
28    align_mode=fantas.AlignMode.CENTER,
29)
30text.rect.center = background.rect.center  # 将文本中心对齐到背景中心
31window.append(text)
32
33# 启动窗口主循环
34window.mainloop()

想要来点动画吗,那就试试这个:

 1import fantas
 2
 3window = fantas.Window(
 4    fantas.WindowConfig(
 5        title="Animate It!",
 6        window_size=(400, 300),
 7    )
 8)
 9
10# 纯色背景
11background = fantas.ColorBackground(fantas.Color(0, 0, 0))
12window.append(background)
13
14# 来个小方块吧
15block = fantas.Label(fantas.Rect(20, 20, 50, 50))
16background.append(block)
17
18# 动画1:让方块动起来
19block_pos_kf = fantas.PointKeyFrame(
20    block.rect,
21    "center",
22    fantas.Vector2(355, 255),
23    fantas.CURVE_SMOOTH,
24)
25block_pos_kf.set_duration_ms(1000)
26block_pos_kf.start()
27
28# 动画2:让背景变色
29background_color_kf = fantas.ColorKeyframe(
30    background,
31    "bgcolor",
32    fantas.Color(255, 0, 0),
33    fantas.CURVE_SMOOTH,
34)
35background_color_kf.set_duration_ms(1000)
36background_color_kf.start()
37
38window.mainloop()

想要更深入地探索可以看看 教程 或者 参考,祝你好运!

教程

介绍 fantas 的核心概念和使用方法,适合初学者入门。

未完成

TODO: 编写教程内容。

参考

详细介绍 fantas 的各个模块和函数的功能和参数,适合有一定基础的用户查阅。

未完成

TODO: 编写参考内容。

开发帮助

如果你想要参与 fantas 的开发,或者想要自己编译一个版本,那么你需要了解一些关于 fantas 的开发指南:

fantas 源代码托管在 GitHub 上,欢迎访问、使用和贡献。

首先,你需要克隆 fantas 的代码仓库(当然,也可以是你自己 fork 后的仓库):

git clone https://github.com/Fantastair/FantasV3.git

fantas 提供了一个开发脚本 dev.py,集成了所有开发过程中可能需要用到的命令,查看 使用 dev.py 脚本

其他

GitHub

这是 fantas 的代码仓库,欢迎访问、使用和贡献。

在此也一并提供 pygame-ce for fantas 的仓库链接。fantas 使用的是其 fantas 分支编译的版本。

MIT License

这是 fantas 的开源许可协议,允许你自由使用、修改和分发该软件, 但必须保留原作者的版权声明和许可声明。