#!/usr/bin/env python # notes on how to use vectors to move the bees around in pyglet from euclid import Vector2 as v from pyglet import window from pyglet import font from random import randint b = v(1,1) # bee at 1,1 h = v(150,150) # hive at 4,4 b_range = 10 # the range of the bee, the distance they can travel. def in_range(b, h): # return true if magnitude (distance) is less than 1 return (b - h).magnitude() < b_range # move the bee one tick towards the hive def move_towards_hive(b,h): return b + ( h - b ).normalized() * b_range def move_random(b): return b + (v(randint(0,100), randint(0,100)) - b).normalized() * b_range win = window.Window() ft = font.load('Arial', 18) # make a bunch of bees bees = [] for i in range(10): bees.append(v(randint(0,400),randint(0,400))) while not win.has_exit: win.dispatch_events() while not in_range(b,h): win.clear() for i in range(len(bees)): bees[i] = move_towards_hive(bees[i],h) b = bees[i] b_text = font.Text(ft, 'b', x=b.x, y=b.y).draw() h_text = font.Text(ft, 'h', x=h.x, y=h.y).draw() win.flip()