今日の NodeBox

NodeBox のチュートリアルを少しばかり書き換えただけなので、コード自体には面白みに欠けるかも。

#!/usr/bin/env	python
# ============================================================================
# ------------------------------------------------------------------ import(s)
import	sys
import	nodebox.graphics
import	nodebox.graphics.physics

# ------------------------------------------------------------------- param(s)
oCFlock			= None

# ============================================================================
##
#
def draw( oCCanvas ):
	global	oCFlock

	nodebox.graphics.background( 1, 1, 1, 0.25 )

	oCFlock.update( cohesion = 0.05 )

	nColor	= 0
	for boid in oCFlock:
		nodebox.graphics.push()
		nodebox.graphics.translate( boid.x, boid.y )

		fScale	= boid.depth * 2.0
		if( fScale < 0.75 ):
			fScale	= 0.75

		nodebox.graphics.scale( fScale )
		nodebox.graphics.rotate( boid.heading )

		nC	= nColor % 3
		if( nC == 0 ):
			nodebox.graphics.fill( 1, 0, 0, 0.25 )
		elif( nC == 1 ):
			nodebox.graphics.fill( 0, 1, 0, 0.25 )
		elif( nC == 2 ):
			nodebox.graphics.fill( 0, 0, 1, 0.25 )

		nodebox.graphics.ellipse( 0, 0, 16, 16 )
		nodebox.graphics.pop()

		nColor	+= 1

# ============================================================================
##
#
def main():
	global	oCFlock

	oCFlock				= nodebox.graphics.physics.Flock( 64, 0, 0, 640, 480 )
	oCFlock.sight	= 640

	nodebox.graphics.canvas.name	= "Demo01"
	nodebox.graphics.canvas.fps		= 20
	nodebox.graphics.canvas.size	= ( 640, 480 )
	nodebox.graphics.canvas.run( draw )

if( __name__ == "__main__" ):
	main()

# ---------------------------------------------------------------------- [EOF]

単純な描画を行うにはかなり適しているかも。