Compare commits
3 Commits
87be1916ee
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| e72bc283f8 | |||
| c9d58e7498 | |||
| 627a48da1c |
@ -5,11 +5,19 @@
|
|||||||
shadertool [选项] <SkSL 代码>
|
shadertool [选项] <SkSL 代码>
|
||||||
|
|
||||||
示例
|
示例
|
||||||
`shadertool "void main() { sk_FragColor = vec4(sin(sk_FragCoord.x * 0.01), 0, 0, 1); }"`
|
shadertool """
|
||||||
使用默认参数(320×180,1秒,15fps)渲染一段红色水平波纹动画。
|
uniform float u_time;
|
||||||
|
uniform float2 u_resolution;
|
||||||
|
|
||||||
`shadertool --width 256 --height 256 --duration 2.0 --fps 20 "void main() { sk_FragColor = vec4(fract(sk_FragCoord * 0.02), 1); }"`
|
half4 main(float2 coord) {
|
||||||
以 256×256 分辨率、2 秒时长、20 帧每秒渲染一个彩色格点动画。
|
return half4(
|
||||||
|
1.0,
|
||||||
|
sin((coord.y / u_resolution.y + u_time) * 3.1415926 * 2) * 0.5 + 0.5,
|
||||||
|
coord.x / u_resolution.x,
|
||||||
|
1.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
参数说明
|
参数说明
|
||||||
SkSL 代码(必填)
|
SkSL 代码(必填)
|
||||||
|
|||||||
@ -141,17 +141,47 @@ async def _(
|
|||||||
output_img = BytesIO()
|
output_img = BytesIO()
|
||||||
|
|
||||||
adjusted_durations = [
|
adjusted_durations = [
|
||||||
max(10, int(dur / speed_factor)) for dur in selected_durations
|
dur / speed_factor for dur in selected_durations
|
||||||
]
|
]
|
||||||
|
|
||||||
if selected_frames:
|
rframes = []
|
||||||
selected_frames[0].save(
|
rdur = []
|
||||||
|
|
||||||
|
acc_mod_20 = 0
|
||||||
|
|
||||||
|
for i in range(len(selected_frames)):
|
||||||
|
fr = selected_frames[i]
|
||||||
|
du: float = adjusted_durations[i]
|
||||||
|
|
||||||
|
if du >= 20:
|
||||||
|
rframes.append(fr)
|
||||||
|
rdur.append(int(du))
|
||||||
|
acc_mod_20 = 0
|
||||||
|
else:
|
||||||
|
if acc_mod_20 == 0:
|
||||||
|
rframes.append(fr)
|
||||||
|
rdur.append(20)
|
||||||
|
acc_mod_20 += du
|
||||||
|
else:
|
||||||
|
acc_mod_20 += du
|
||||||
|
if acc_mod_20 >= 20:
|
||||||
|
acc_mod_20 = 0
|
||||||
|
|
||||||
|
if len(rframes) == 1 and len(selected_frames) > 1:
|
||||||
|
rframes.append(selected_frames[max(2, len(selected_frames) // 2)])
|
||||||
|
rdur.append(20)
|
||||||
|
|
||||||
|
if rframes:
|
||||||
|
rframes[0].save(
|
||||||
output_img,
|
output_img,
|
||||||
format="GIF",
|
format="GIF",
|
||||||
save_all=True,
|
save_all=True,
|
||||||
append_images=selected_frames[1:],
|
append_images=rframes[1:],
|
||||||
duration=adjusted_durations,
|
duration=rdur,
|
||||||
loop=0,
|
loop=0,
|
||||||
|
optimize=False,
|
||||||
|
disposal=2,
|
||||||
|
transparency=0,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise BotExceptionMessage("错误:没有可输出的帧")
|
raise BotExceptionMessage("错误:没有可输出的帧")
|
||||||
|
|||||||
@ -31,6 +31,8 @@ async def _(
|
|||||||
raise BotExceptionMessage("时长太短或帧率太小,没有帧被渲染")
|
raise BotExceptionMessage("时长太短或帧率太小,没有帧被渲染")
|
||||||
if fps_ * duration_ > 100:
|
if fps_ * duration_ > 100:
|
||||||
raise BotExceptionMessage("太多帧啦!试着缩短一点时间吧!")
|
raise BotExceptionMessage("太多帧啦!试着缩短一点时间吧!")
|
||||||
|
if width_ > 640 or height_ > 640:
|
||||||
|
raise BotExceptionMessage("最大支持 640x640 啦!不要太大啦!")
|
||||||
|
|
||||||
code = code.strip("\"").strip("'")
|
code = code.strip("\"").strip("'")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user