manim
繪制圖形時,除了上一節提到的那些必須的引數,還有一些可選的引數,
這些引數可以控制圖形顯示的樣式,
繪制各類基本圖形(點,線,圓,多邊形等)時,每個圖形都有自己的默認的樣式,比如上一節的圖形,
有的默認是白色,有的默認是紅色,
控制圖形樣式的引數最常用的有以下四個:
- stroke_width:圖形邊框的粗細
- color:圖形的顏色
- fill_color:圖形的填充色
- fill_opacity:填充色的透明度,這個引數一般和
fill_color
一起使用
邊框
線,圓和多邊形都可以通過 stroke_width
調整邊框粗細程度,
線的邊框:
# 線
Line(
[-1, 1, 0],
[1, 1, 0],
stroke_width=1,
)
Line(
[-1, 0, 0],
[1, 0, 0],
stroke_width=5,
)
Line(
[-1, -1, 0],
[1, -1, 0],
stroke_width=10,
)
上面的示例中是3種不同粗細的線
運行效果:
圓的邊框:
# 圓(這里的 shift 函式是用來調整圓的位置)
Circle(
radius=0.8,
stroke_width=1,
).shift(LEFT * 2)
Circle(
radius=0.8,
stroke_width=5,
)
Circle(
radius=0.8,
stroke_width=10,
).shift(RIGHT * 2)
運行效果:
多變形的邊框:
# 多邊形
Polygon(
[-3, 1, 0],
[-1, 1, 0],
[-2, -1, 0],
stroke_width=5,
)
Polygon(
[1, 1, 0],
[2, 0, 0],
[3, 1, 0],
[3, -1, 0],
[1, -1, 0],
stroke_width=10,
)
運行效果:
顏色
各種基本圖形本身有默認的顏色,比如線默認是白色,圓默認紅色,多邊形默認藍色等,
除了默認顏色,manim
還預置了一系列的顏色,可以直接按顏色的名稱來使用,
設定圖形的顏色,使用 color
屬性,
線的顏色:(線默認是白色)
# 線
Line(
[-1, 1, 0],
[1, 1, 0],
stroke_width=1,
color=RED,
)
Line(
[-1, 0, 0],
[1, 0, 0],
stroke_width=5,
color=YELLOW,
)
Line(
[-1, -1, 0],
[1, -1, 0],
stroke_width=10,
color=GREEN,
)
運行效果:
圓的顏色:(線默認是紅色)
# 圓
Circle(
radius=0.8,
stroke_width=1,
color=RED,
).shift(LEFT * 2)
Circle(
radius=0.8,
stroke_width=5,
color=YELLOW,
)
Circle(
radius=0.8,
stroke_width=10,
color=GREEN,
).shift(RIGHT * 2)
運行效果:
多邊形的顏色:(線默認是藍色)
# 多邊形
Polygon(
[-3, 1, 0],
[-1, 1, 0],
[-2, -1, 0],
stroke_width=5,
color=RED,
)
Polygon(
[1, 1, 0],
[2, 0, 0],
[3, 1, 0],
[3, -1, 0],
[1, -1, 0],
stroke_width=10,
color=GREEN,
)
運行效果:
填充
最后是填充色,關聯兩個屬性:fill_color
和 fill_opacity
,
這兩個屬性一般用在閉合的圖形中,比如圓和多邊形,
圓的填充:
# 圓
Circle(
radius=0.8,
stroke_width=1,
color=RED,
fill_color=YELLOW,
fill_opacity=0.5,
).shift(LEFT * 2)
Circle(
radius=0.8,
stroke_width=5,
color=YELLOW,
fill_color=GREEN,
fill_opacity=0.5,
)
Circle(
radius=0.8,
stroke_width=10,
color=GREEN,
fill_color=RED,
fill_opacity=0.5,
).shift(RIGHT * 2)
運行效果:
多邊形的填充:
# 多邊形
Polygon(
[-3, 1, 0],
[-1, 1, 0],
[-2, -1, 0],
stroke_width=5,
color=RED,
fill_color=GREEN,
fill_opacity=0.5,
)
Polygon(
[1, 1, 0],
[2, 0, 0],
[3, 1, 0],
[3, -1, 0],
[1, -1, 0],
stroke_width=10,
color=GREEN,
fill_color=RED,
fill_opacity=0.5,
)
運行效果:
總結回顧
制作影片時,利用邊框和顏色,可以有效的區分各個圖形之間區別,也可以突出重點要表示的部分,
嘗試多使用上述四個屬性,讓影片更加美觀,
stroke_width
,color
,fill_color
,fill_opacity
本文關聯的微信視頻號短視頻:
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/548772.html
標籤:Python