def Update(self, time): self.time = time self.p.acc *= 0 self.p.vel *= util.Constrain(self.p.vel.Length, 2) self.p.acc = self.p.pos - rg.Point3d(50, 50, 50) if self.p.acc.Length > 20: self.p.acc.Reverse() self.p.acc.Unitize() self.p.acc *= 1 rand = geo.RandomVector3d(.4) self.p.acc += rand self.p.Update() self.p.UpdateDisplay() for dot in self.dots: dot.Update() #for link in self.links: # link.Resolve() if False: self.links = [] for i in range(len(self.boxes)): for j in range(i + 1, len(self.boxes)): #Could add in a distance max here if (self.boxes[i].pos - self.boxes[j].pos).Length < 30: if self.boxes[i].age > 20 and self.boxes[i].age > 20: self.links.append( Link(self.boxes[i], self.boxes[j]))
def Update(self, time): for id in self.tempIDs: sc.doc.Objects.Delete(id, True) self.acc *= 0 futurePos = self.pos + self.vel hitBoundary = False f = 4 repulsion = 10 if futurePos.X < self.size * f: distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(repulsion * distanceModifier, 0, 0) hitBoundary = True if futurePos.Y < self.size * f: distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(0, repulsion * distanceModifier, 0) hitBoundary = True if futurePos.Z < self.size * f: distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(0, 0, repulsion * distanceModifier) hitBoundary = True if futurePos.X > 100 - self.size * f: distanceModifier = util.Remap(futurePos.X, 100 - self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(-repulsion * distanceModifier, 0, 0) hitBoundary = True if futurePos.Y > 100 - self.size * f: distanceModifier = util.Remap(futurePos.Y, 100 - self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(0, -repulsion * distanceModifier, 0) hitBoundary = True if futurePos.Z > 100 - self.size * f: distanceModifier = util.Remap(futurePos.Z, 100 - self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(0, 0, -repulsion * distanceModifier) hitBoundary = True self.vel += self.acc if hitBoundary == False: ran = 1 self.vel += rg.Vector3d(random.uniform(-ran, ran), random.uniform(-ran, ran), random.uniform(-ran, ran)) self.AvoidNeighborPaths() newAmp = util.Constrain(self.vel.Length, 0, self.speed) self.vel.Unitize() self.vel *= newAmp self.pos += self.vel if len(self.history) > 10: self.history.pop(0) if len(self.historyPos) > 10: self.historyPos.pop(0)
def Update(self, time): for id in self.tempIDs: sc.doc.Objects.Delete(id, True) self.acc *= 0 futurePos = self.pos + self.vel hitBoundary = False f = 2 repulsion = 10 if futurePos.X < self.size * f: distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(repulsion*distanceModifier,0,0) hitBoundary = True if futurePos.Y < self.size * f: distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(0,repulsion*distanceModifier,0) hitBoundary = True if futurePos.Z < self.size * f: distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(0,0,repulsion*distanceModifier) hitBoundary = True if futurePos.X > 100-self.size * f: distanceModifier = util.Remap(futurePos.X, 100-self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(-repulsion*distanceModifier,0,0) hitBoundary = True if futurePos.Y > 100-self.size * f: distanceModifier = util.Remap(futurePos.Y, 100-self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(0,-repulsion*distanceModifier,0) hitBoundary = True if futurePos.Z > 100-self.size * f: distanceModifier = util.Remap(futurePos.Z, 100-self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(0,0,-repulsion*distanceModifier) hitBoundary = True self.vel += self.acc if hitBoundary == False: ran = 1 self.vel += rg.Vector3d(random.uniform(-ran, ran), random.uniform(-ran, ran), random.uniform(-ran, ran)) self.AvoidNeighborPaths() self.CreateRectangles() newAmp = util.Constrain(self.vel.Length, 0, self.speed) self.vel.Unitize() self.vel *= newAmp self.pos += self.vel for each in self.history: mp = rg.AreaMassProperties.Compute(each) xform = rg.Transform.Scale(mp.Centroid, .9) each.Transform(xform) if len(self.history) > 30: self.history.pop(0) if len(self.historyPos) > 30: self.historyPos.pop(0)
def Update(self, time): if time == 1: sc.doc.Objects.AddSphere(self.sphere, self.attr) self.acc *= 0 futurePos = self.pos + self.vel hitBoundary = False f = 4 repulsion = 10 if futurePos.X < self.size * f: distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(repulsion * distanceModifier, 0, 0) hitBoundary = True if futurePos.Y < self.size * f: distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(0, repulsion * distanceModifier, 0) hitBoundary = True if futurePos.Z < self.size * f: distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0, repulsion) self.acc += rg.Vector3d(0, 0, repulsion * distanceModifier) hitBoundary = True if futurePos.X > 100 - self.size * f: distanceModifier = util.Remap(futurePos.X, 100 - self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(-repulsion * distanceModifier, 0, 0) hitBoundary = True if futurePos.Y > 100 - self.size * f: distanceModifier = util.Remap(futurePos.Y, 100 - self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(0, -repulsion * distanceModifier, 0) hitBoundary = True if futurePos.Z > 100 - self.size * f: distanceModifier = util.Remap(futurePos.Z, 100 - self.size * f, 100, 0, repulsion) self.acc += rg.Vector3d(0, 0, -repulsion * distanceModifier) hitBoundary = True self.vel += self.acc if hitBoundary == False: ran = 1 self.vel += rg.Vector3d(random.uniform(-ran, ran), random.uniform(-ran, ran), random.uniform(-ran, ran)) newAmp = util.Constrain(self.vel.Length, 0, self.speed) self.vel.Unitize() self.vel *= newAmp self.pos += self.vel self.history.append(self.pos)
def ApplySpring(self): #self.size += .25 restLength = 0 self.vertex = rg.Point3d(self.system.mesh.Vertices[self.index]) pts = [] for neigh in self.neighbors: p = rg.Point3d(self.system.mesh.Vertices[neigh]) force = self.vertex - p d = force.Length stretch = d - restLength force.Unitize() force.Reverse() stretch = util.Constrain(stretch, -3, 3) force *= stretch * .2 self.acc += force