示例#1
0
文件: 01-flock.py 项目: msarch/py
sys.path.insert(0, os.path.join("..", ".."))

from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle

# Flocking can be used to simulate birds, herds, or school of fish.
# Each "boid" in the flock adheres to a simple set of rules:
# - separation: steer to avoid crowding local flockmates,
# - alignment: steer towards the average heading of local flockmates,
# - cohesion: steer to move toward the average position of local flockmates.

# Create a new flock.
flock = Flock(30, x=50, y=50, width=500, height=500, depth=100.0)
flock.space(
    30)  # Set the space for each boid (influences boid separation forces).
flock.sight(70)  # Set the line-of-sight for each boid
# (influences boid cohesion and alignment forces).

# Add some obstacles that the flock will need to evade.
for i in range(3):
    o = Obstacle(x=random(50, 500), y=random(50, 500), radius=random(10, 70))
    flock.obstacles.append(o)


def draw(canvas):

    # Clear the previous frame.
    # For fun, comment this out and observe the interesting flocking patterns.
    canvas.clear()

    # If the mouse is moved inside the flocking area,
示例#2
0
from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle

flock = Flock(50, x=-50, y=-50, width=700, height=400)
flock.sight(80)


def draw(canvas):
    canvas.clear()
    flock.update(separation=0.4, cohesion=0.6, alignment=0.1, teleport=True)
    for boid in flock:
        push()
        translate(boid.x, boid.y)
        scale(0.5 + boid.depth)
        rotate(boid.heading)
        arrow(0, 0, 15)
        pop()


canvas.size = 600, 300
canvas.run(draw)
from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle

flock = Flock(50, x=-50, y=-50, width=700, height=400)
flock.sight(80)

def draw(canvas):
    canvas.clear()
    flock.update(separation=0.4, cohesion=0.6, alignment=0.1, teleport=True)
    for boid in flock:
        push()
        translate(boid.x, boid.y)
        scale(0.5 + boid.depth)
        rotate(boid.heading)
        arrow(0, 0, 15)
        pop()

canvas.size = 600, 300
canvas.run(draw)
示例#4
0
#!/usr/local/bin/python2.6
# encoding: utf-8
# Add the upper directory (where the nodebox module is) to the search path.
import os, sys

sys.path.insert(0, os.path.join("..", "..", "lib"))

from nodebox.graphics import *
from nodebox.graphics.physics import Flock

flock = Flock(40, 0, 0, 500, 500)
flock.sight = 300


def draw(canvas):
    background(1)
    fill(0, 0.75)
    flock.update(cohesion=0.15)
    for boid in flock:
        push()
        translate(boid.x, boid.y)
        scale(0.5 + 1.5 * boid.depth)
        rotate(boid.heading)
        arrow(0, 0, 15)
        pop()


canvas.fps = 30
canvas.size = 600, 400
canvas.run(draw)
示例#5
0
# Add the upper directory (where the nodebox module is) to the search path.
import os, sys; sys.path.insert(0, os.path.join("..",".."))

from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle

# Flocking can be used to simulate birds, herds, or school of fish.
# Each "boid" in the flock adheres to a simple set of rules:
# - separation: steer to avoid crowding local flockmates,
# - alignment: steer towards the average heading of local flockmates,
# - cohesion: steer to move toward the average position of local flockmates.

# Create a new flock.
flock = Flock(30, x=50, y=50, width=500, height=500, depth=100.0)
flock.space(30) # Set the space for each boid (influences boid separation forces).
flock.sight(70) # Set the line-of-sight for each boid 
                # (influences boid cohesion and alignment forces).

# Add some obstacles that the flock will need to evade.
for i in range(3):
    o = Obstacle(x=random(50,500), y=random(50,500), radius=random(10,70))
    flock.obstacles.append(o)

def draw(canvas):

    # Clear the previous frame.
    # For fun, comment this out and observe the interesting flocking patterns.
    canvas.clear()
    
    # If the mouse is moved inside the flocking area, 
    # set it as a target for the boids.
示例#6
0
from nodebox.graphics import *
from nodebox.graphics.physics import Flock

flock = Flock(40, 0, 0, 500, 500)
flock.sight = 300


def draw(canvas):
    canvas.clear()
    translate(250, 250)
    rotate(canvas.frame)
    rect(x=-50, y=-50, width=100, height=200)


canvas.fps = 30
canvas.size = 600, 400
canvas.run(draw)