Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
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)