#Create boxes!!
c=0
cnt=0
for i in range(-6,7,3):
for k in range(-6,7,3):
boxpos(i,k,0,c)
cnt=cnt+1
c=cnt%6
cnt=cnt+1でカウントを行い、c=cnt%6で、6で割った余りが
0から5までになるので、順番に色を決めていくことができる。
以下は、サンプルファイルである。
#! /usr/bin/env python
from lightflowPM import *
from math import *
import colorinc
s = scene()
s.lightOn( s.newLight( "point", [ "position", vector3( 5.0, -5.0, 6.0 ), "color", vector3( 300.0, 300.0, 300.0 ) ] ) )
s.lightOn( s.newLight( "ambient", [ "color", vector3( 0.3, 0.3, 0.3 ) ] ) ) #環境光を加える。
plastic = s.newMaterial( "standard",[ "kc", colorinc.Brown,"kd",0.66 ] ) #
plastic2 = s.newMaterial( "standard",[ "kc", colorinc.CadetBlue,"kd",0.66 ] ) #
plastic3 = s.newMaterial( "standard",[ "kc", colorinc.Coral,"kd",0.66 ] ) #
plastic4 = s.newMaterial( "standard",[ "kc", colorinc.VLightGray,"kd",0.66 ] ) #
plastic5 = s.newMaterial( "standard",[ "kc", colorinc.Aquamarine,"kd",0.66 ] ) #
plastic6 = s.newMaterial( "standard",[ "kc", colorinc.BlueViolet,"kd",0.66 ] ) #
#plasticをリスト化した
col=[plastic,plastic2,plastic3,plastic4,plastic5,plastic6]
check_ground=s.newPattern("check",["color",vector3( 0.2, 0.4, 0.6 ),"scale",0.025])
ground=s.newMaterial( "standard",[ "kc", check_ground,"kc",vector3( 1.0, 1.0, 1.0 ),"ka",check_ground ] ) #チェック青と白
#関数定義 ボックスの位置とリストcolのインデックス番号0から5まで
def boxpos(x0,y0,z0,c):
s.materialBegin( col[c] )
s.transformBegin( transform().translation( vector3(x0,y0,z0)))
s.addObject( s.newObject( "box", [ "position",vector3( -1.0, -1.0, -1.0 ),vector3( 1.0, 1.0, 1.0 )] ) )
s.transformEnd()
s.materialEnd()
#Create boxes!!
c=0
cnt=0
for i in range(-6,7,3):
for k in range(-6,7,3):
boxpos(i,k,0,c)
cnt=cnt+1
c=cnt%6
#check模様の地面groundをpatchで作成しています。高さ(z軸)を-1.0にしてぴったり立方体とあわせています。
s.materialBegin( ground )
s.addObject( s.newObject( "patch", [ "points",vector3( -50, -50, -1.0 ),vector3( -50, 50, -1.0 ),vector3( 50, -50, -1.0 ),vector3( 50, 50, -1.0 )] ) )
s.materialEnd()
saver = s.newImager( "tga-saver", [ "file", "box_def4.tga" ] )
s.imagerBegin( saver )
camera = s.newCamera( "pinhole", [ "eye", vector3( 0, -12, 5 ), "aim", vector3( 0, 0, 0 ) ] )
s.imagerEnd()
s.render( camera, 640, 340 )
- -
- -