我已经说明了由两个向量跨越的平行四边形,并且想在该平行四边形的区域中着色,我尝试这样做:
from manim import *
import numpy as np
class DrawParallelogram( Scene ):
def construct( self ):
o = np.array( [ 0, -2, 0 ] )
p1 = np.array( [ 3, 1, 0 ] ) # u
p2 = np.array( [ 1, 3, 0 ] ) # v
op1 = o + p1
op2 = o + p2
op3 = o + p1 + p2
v1 = Arrow( start = o, end = op1, buff = 0, color = RED ) # u
v2 = Arrow( start = o, end = op2, buff = 0, color = YELLOW ) # v
v1p = Arrow( start = op2, end = op3, buff = 0, color = RED ) # u'
v2p = Arrow( start = op1, end = op3, buff = 0, color = YELLOW ) # v'
parallelogram = [ o, op1, op3, op2 ]
poly = Polygon( *parallelogram, color = PURPLE, fill_opacity = 0.5 )
self.play( AnimationGroup( Write( v1 ), Write( v2 ), Write( v1p ), Write( v2p ) ) )
self.wait( )
self.play( Write( poly ) )
Run Code Online (Sandbox Code Playgroud)
我希望它在后台。有没有办法将一个新对象引入场景中,以便它在逻辑上位于任何现有对象的后面,就像我先绘制它一样,这样它看起来像:
小智 7
您可以使用set_z_index方法将平行四边形的属性设置z_index为小于箭头的值。
这里我将其设置为比以下值更低的值v1:
poly.set_z_index(v1.z_index - 1)
Run Code Online (Sandbox Code Playgroud)
或者,您可以直接操作该z_index属性:
poly.z_index = v1.z_index - 1
Run Code Online (Sandbox Code Playgroud)
使用该set_z_index方法将是更清洁的解决方案。
完整代码:
from manim import *
import numpy as np
class DrawParallelogram( Scene ):
def construct( self ):
o = np.array( [ 0, -2, 0 ] )
p1 = np.array( [ 3, 1, 0 ] ) # u
p2 = np.array( [ 1, 3, 0 ] ) # v
op1 = o + p1
op2 = o + p2
op3 = o + p1 + p2
v1 = Arrow( start = o, end = op1, buff = 0, color = RED ) # u
v2 = Arrow( start = o, end = op2, buff = 0, color = YELLOW ) # v
v1p = Arrow( start = op2, end = op3, buff = 0, color = RED ) # u'
v2p = Arrow( start = op1, end = op3, buff = 0, color = YELLOW ) # v'
parallelogram = [ o, op1, op3, op2 ]
poly = Polygon( *parallelogram, color = PURPLE, fill_opacity = 0.5 )
# Set the z-index
poly.set_z_index(v1.z_index - 1)
self.play( AnimationGroup( Write( v1 ), Write( v2 ), Write( v1p ), Write( v2p ) ) )
self.wait( )
self.play( Write( poly ) )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1629 次 |
| 最近记录: |