付加的な属性

以下の属性は全ての VPython オブジェクトに適用できます。

visible:もし 0 ならばオブジェクトは表示されません。例 ball.visible = 0
ball.visible = 1 とすれば、再び ball は見えるようになります。

frame:オブジェクトを特定のフレーム(frame)の中に配置します。例 ball = sphere(frame = f1)

display:VPython プログラムを開始させるとき、 VPython は表示ウィンドウを生成します。便利なように、デフォルト・ウィンドウの名前を scene とします。デフォルトで貴方が生成したオブジェクトは その表示ウィンドウの中に配置されます。でも下のように別の表示ウィンドウに配置することもできます。

        scene2 = display( title = "Act IV, Scene 2" )
        rod = cylinder( display = scene2 )
関数 display.get_selected() は現在オブジェクトが配置されている表示ウィンドウへの参照を返します。

__class__:オブジェクトのクラス名です。たとえば ball.__class__ is sphere が真であるのは ball が sphere オブジェクトのときです。classの綴りの前後には二つのアンダースコア文字があります。 scene.objects 上の見えるオブジェクト・リストの中で, if obj がリストの中にあるとき、オブジェクトの class 名は obj.__class__ で決められます。

__copy()__:オブジェクトのコピーを作ります。copy() の前後に二つのアンダースコア文字があります。 引数なしのときは最初のオブジェクトと全く同じ位置に二つ目のオブジェクトを作ります。たぶん これは望ましくないでしょう。__copy__() 関数はキーワード・リスト引数 keyword=value ペアの引数をとります。それは新しいオブジェクトを可視化する前に適用されます。例えば一つの display オブジェクトの表示オブジェクトを複製するには new_object = old_object.__copy__( display=new_display) とします。制限:元のオブジェクトが frame の中にあって同時に新しいオブジェクトが異なった display にあるとき、新しい display と新しい frame が作られねばなりません(frame は None かもしれません)。これはオブジェクトは別の display に一つの frame を共用できないとの制限によるものです。全てのオブジェクトの属性のリストを作るために使われていた属性 __members__ は、もう VPython では使われていません。その主要な使用目的はオブジェクトをコピーすることです。

下に __copy()_ 関数の使用例を示します。次のルーチンは現在一つの display に存在している全ての VPyshon オブジェクトを、二つ目の discplay 表示までにコピーします。

def clone_universe( new_display, old_display):
        # Create a dictionary of frames in the old display
        # to the corresponding frames in the new display.
        frames = dict()
        # Initialize the lookup dictionary
        for obj in old_display.objects:
                if obj.__class__ == frame:
                        frames[obj] = obj.__copy__( frame=None, display=new_display)
        # For each old reference frame that was within another reference frame,
        # place the new reference frame within the appropriate frame in the new
        # display. Here old is an object and new is its frame in the new display.
        for old, new in frames.iteritems():
                if old.frame:
                        new.frame = frames[old.frame]
        # Copy over the universe.
        for obj in old_display.objects:
                if obj.__class__ == frame:
                        # Already taken care of above.
                        continue
                if obj.frame:
                        # Then initialize with the corresponding reference frame in the new
                        # display.
                        obj.__copy__( display=new_display, frame=frames[obj.frame])
                else:
                        # Don't need to care about the frame attribute, since it is None.
                        obj.__copy__( display=new_display)

display オブジェクトを生成し操作する方法については ウィンドウを制御する を見てください。