Swarm in Grasshopper using GH_Python component. Testing swarm behaviour in Rhino is in this post: Rhino.Python Swarm Bridge

For more discussion please visit my post in grasshopper example forum.

GH_Python Code:

### --Written by Gene Ting-Chun Kao-- ###
ghenv.Component.Message = "written by +GENEATCG"

import rhinoscriptsyntax as rs
import Rhino as rc
from random import *

rectX = 600
rectY = 600

class Runner:
    def __init__(self, p, v):
        self.p = p
        self.v = v
        self.a = rs.VectorCreate( (0,0,0),(0,0,0) )

    def ptRun(self):
        self.v = rs.VectorAdd(self.v, self.a)
        v = rs.VectorLength(self.v)
        if v > 2:
            self.v = rs.VectorScale(rs.VectorUnitize(self.v), 2)
        self.p = rs.VectorAdd(self.p, self.v)

        self.a = rs.VectorCreate( (0,0,0),(0,0,0) )

    # ... (full code on GitHub)