Showing posts with label VPython. Show all posts
Showing posts with label VPython. Show all posts

Sunday, February 13, 2011

VPythonで光源の向きを設定する

VPythonで光源の向きを設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 立方体を作成
box1 = box(pos=(0, 0, 0), length=6, width=6, height=0.5,
color=(0xff/255.,0xff/255.,0xff/255.))
# 球を作成
sphere1 = sphere(pos=(0, 1.5, 0), radius=1,
color=(0xff/255.,0xff/255.,0xff/255.))
# カメラが見る点を指定
scene.center = (0,2,0)
# 緑色の下向きの光源を設定
lamp1 = distant_light(direction=(0, 1, 0),
color=color.green)
# 青色の左向きの光源を設定
lamp2 = distant_light(direction=(1, 0, 0),
color=color.blue)


実行画面


動作環境
Python 3.1.3, VPython 5.41

Thursday, February 10, 2011

VPythonで点光源を設定する

VPythonで点光源を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 立方体を作成
box1 = box(pos=(0, 0, 0), length=6, width=6, height=0.5,
color=(0xff/255.,0xff/255.,0xff/255.))
# 球を作成
sphere1 = sphere(pos=(0, 1.5, 0), radius=1,
color=(0xff/255.,0xff/255.,0xff/255.))
# カメラが見る点を指定
scene.center = (0,2,0)
# 緑色の点光源を設定
lamp1 = local_light(pos=(-2, 1.5, 0), color=color.green)
# 青色の点光源を設定
lamp2 = local_light(pos=(2, 1.5, 0), color=color.blue)


実行画面


動作環境
Python 3.1.3, VPython 5.41

Monday, February 07, 2011

VPythonでカメラを向ける位置を設定する

VPythonでカメラを向ける位置を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 立方体を作成
box1 = box(pos=(0, 0, 0), length=6, width=6, height=0.5,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 球を作成
sphere1 = sphere(pos=(0, 1.5, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# カメラを向ける位置を指定
scene.center = (0,2,0)


実行画面


動作環境
Python 3.1.3, VPython 5.41

Friday, February 04, 2011

VPythonで不透明度を設定する

VPythonで不透明度を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 不透明度を設定
for lc in range(0,9):
sphere1 = sphere(pos=(lc, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.),
opacity=(10-lc)/10.)



実行画面


動作環境
Python 3.1.3, VPython 5.41

Tuesday, February 01, 2011

VPythonでテクスチャを設定する

VPythonでテクスチャを設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# テクスチャを使用
sphere1 = sphere(pos=(0, 0, 0), radius=1,
material = materials.texture(
data=materials.loadTGA('sf_128x128.tga'),
mapping='spherical'))
# 回転
sphere1.rotate(angle=pi*260./180., axis=(1,0,1))


実行画面


TGAファイルを作成するには、ImageMagickを使用して以下のようなバッチで
JPEGからTGAに変換します。サイズは2の乗数に設定します。
rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.6.6-Q16

%im%\convert.exe sf.jpg -resize 128x128 sf_128x128.tga



動作環境
Python 3.1.3, VPython 5.41

Saturday, January 29, 2011

VPythonで材質を設定する

VPythonで材質を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 木の材質
sphere1 = sphere(pos=(-2, 2, 0), radius=1,
material = materials.wood)
# でこぼこな材質
sphere2 = sphere(pos=(0, 2, 0), radius=1,
material = materials.rough)
# 大理石っぽい材質
sphere3 = sphere(pos=(2, 2, 0), radius=1,
material = materials.marble)
# プラスチックっぽい材質
sphere4 = sphere(pos=(-2, 0, 0), radius=1,
material = materials.plastic)
# 地球
sphere5 = sphere(pos=(0, 0, 0), radius=1,
material = materials.earth)
# diffuse(拡散)
sphere6 = sphere(pos=(2, 0, 0), radius=1,
material = materials.diffuse)
# emmisive(放射)
sphere7 = sphere(pos=(-2, -2, 0), radius=1,
material = materials.emissive)
# 光の影響を受けない材質
sphere8 = sphere(pos=(0, -2, 0), radius=1,
material = materials.unshaded)


実行画面


動作環境
Python 3.1.3, VPython 5.41

Wednesday, January 26, 2011

VPythonでウインドウをフルスクリーンに設定する

VPythonでウインドウをフルスクリーンに設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# ウインドウをフルスクリーンに設定
scene.fullscreen = True
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


フルスクリーンモードを抜けるにはESCキーを押します。

動作環境
Python 3.1.3, VPython 5.41

Sunday, January 23, 2011

VPythonでウインドウの位置・サイズを設定する

VPythonでウインドウの位置・サイズを設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# ウインドウの位置・サイズを設定
scene.x = 50
scene.y = 50
scene.width = 150
scene.height = 150
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Thursday, January 20, 2011

VPythonでレンダリング時間を表示する

VPythonでレンダリング時間を表示するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# レンダリング時間を表示
scene.show_rendertime = True
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Monday, January 17, 2011

VPythonで環境光を設定する

VPythonで環境光を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 環境光を設定
scene.ambient = (0x20/255.,0xdd/255.,0x66/255.)
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0xff/255.,0xff/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Friday, January 14, 2011

VPythonで背景色を設定する

VPythonで背景色を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 背景色を設定
scene.background = (0xdd/255.,0xee/255.,0xff/255.)
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Tuesday, January 11, 2011

VPythonでウインドウタイトルを設定する

VPythonでウインドウタイトルを設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# ウインドウのタイトルを設定
scene.title = 'VPython sample'
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Saturday, January 08, 2011

VPythonでラベルを描画する

VPythonでラベルを描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# ラベルを作成
textlabel = label(pos=sphere1.pos,
text='球のサンプル', xoffset=70,
yoffset=80, space=100,
color=(0xff/255.,0xdd/255.,0x66/255.),
linecolor=(0xcc/255.,0xcc/255.,0xcc/255.),
height=20, border=6,
font='MS ゴシック')



実行画面


動作環境
Python 3.1.3, VPython 5.41

Wednesday, January 05, 2011

VPythonで螺旋を描画する

VPythonで螺旋を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 螺旋を作成
helix1 = helix(pos=(0, 0, 0), radius=0.6,
color=(0x99/255.,0xdd/255.,0xff/255.))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Sunday, January 02, 2011

VPythonで矢印を描画する

VPythonで矢印を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 矢印を作成
arrow1 = arrow(pos=(0, 0, 0), shaftwidth=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
arrow1.rotate(angle=pi*110./180., axis=(1,0,1))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Thursday, December 30, 2010

VPythonで楕円を描画する

VPythonで楕円を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 楕円を作成
ellipsoid1 = ellipsoid(pos=(0, 0, 0), size=(2,0.5,0.5),
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
ellipsoid1.rotate(angle=pi*110./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Monday, December 27, 2010

VPythonで円錐を描画する

VPythonで円錐を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 円錐を作成
cone1 = cone(pos=(0, 0, 0), radius=0.25, length=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
cone1.rotate(angle=pi*110./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Friday, December 24, 2010

VPythonでシリンダーを描画する

VPythonでシリンダーを描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# シリンダーを作成
cylinder1 = cylinder(pos=(0, 0, 0), radius=0.25, length=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
cylinder1.rotate(angle=pi*110./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Tuesday, December 21, 2010

VPythonでリング型を描画する

VPythonでリング型を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# リングを作成
ring1 = ring(pos=(0, 0, 0), radius=1, thickness=0.2,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
ring1.rotate(angle=pi*90./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Saturday, December 18, 2010

VPythonでピラミッド型を描画する

VPythonでピラミッド型を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 球を作成
pyramid1 = pyramid(pos=(0, 0, 0), size=(1,1,1),
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
pyramid1.rotate(angle=pi*90./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41