def random(corners=[-1, -1, 1, 1], n=5): """Create a random body.""" form = Form.random(corners, n) motion = Motion.random(n=2, d=3) moment = Motion.random(n=2, d=3) print(motion.acceleration) return Body(form, motion, moment)
def createRandomBody(): form=5*Form.random(n=5) form.side_color=mycolors.RED form.area_color=mycolors.BLACK form.fill=True motion=Motion(10*Vector.random(),Vector.random(),Vector.null()) moment=Motion(Vector([1]),Vector([0.1])) return Body(form,motion,moment)
def __init__(self,position,size=5): """Create an asteroid.""" form=size*Form.random(n=5) form.side_color=mycolors.RED form.area_color=mycolors.DARKGREY form.fill=True motion=Motion(Vector(*position),Vector.random(),Vector.null()) moment=Motion(Vector([0]),Vector([random.uniform(-1,1)])) super().__init__(form,motion,moment)
def random(cls, nf=3, np=5, nfp=3, **kwargs): """Create a random complex form.""" points = Form.random(n=np).points l = len(points) forms = [] for j in range(nf): f = Form([], area_color=mycolors.random(), fill=True) d = [] for i in range(nfp): d.append(random.randint(0, l - 1)) forms.append((d, f)) return cls(points, forms, **kwargs)
def random(corners=[-1, -1, 1, 1], n=5): """Create a random material form.""" form = Form.random(corners, n=n) return MaterialForm.createFromForm(form)
acceleration = property(getAcceleration, setAcceleration, delAcceleration, "Representation of the acceleration of the form.") #abstract_center=property(getAbstractCenter,setAbstractCenter,delAbstractCenter,"Representation of the abstract center of the material form.") #abstract_points=property(getAbstractPoints,setAbstractPoints,delAbstractPoints,"Representation of the abstract points of the material form.") steps = property(getSteps, setSteps, delSteps, "Representation of the steps of the material form.") FallingForm = lambda: MaterialForm( [mymaterialpoint.FallingPoint() for i in range(5)]) if __name__ == "__main__": from mycontext import Surface surface = Surface() c1 = [-10, -10, 10, 10] f1 = Form.random(c1, n=5) f1 = MaterialForm.createFromForm(f1) f1.velocity = Vector(0, 1) f1.acceleration = Vector(0, -0.01) print(f1) c2 = [-10, -10, 10, 10] f2 = Form.random(c2, n=5) f2 = MaterialForm.createFromForm(f2) #print(form[0].forces) #print(form.getMass()) origin = Point.origin() while surface.open: surface.check() surface.clear()
points.append(p) return points def update(self, surface): """Update the ray caster.""" self.emiter.update(surface) if __name__ == "__main__": from mysurface import Surface from myzone import Zone surface = Surface(name="RayCasting", plane=Zone()) #forms=[Form.random([-10,-10,10,10],number=5,side_color=mycolors.RED) for i in range(10)] forms = [ Form.random([10 * (i - 5), -5, 10 * (i - 4), 5], number=5, side_color=mycolors.RED) for i in range(10) ] #forms=[Segment.random([10*(i-5),-5,10*(i-4),5],number=5,side_color=mycolors.RED) for i in range(10)] emiter = Emiter() caster = RayCaster(emiter, forms) origin = Point(0, 0) while surface.open: surface.check() surface.control() surface.clear() surface.show() for form in forms: form.rotate(0.1, origin) caster.update(surface)
def __init__(self, *args, **kwargs): self.form = Form.random(n=10) self.focus = 0 super().__init__(*args, **kwargs)
v1 = Vector.createFromTwoPoints(p1, p2) v1 = ~v1 v2 = v1 % self p3 = v2(p2) s1 = Segment(p1, p2) s2 = Segment(p2, p3) s1.show(surface) s2.show(surface) #I need to show arc of circles which im too lazy to do now if __name__ == "__main__": from mysurface import Surface surface = Surface() corners = [-10, -10, 10, 10] f = Form.random(corners, number=5, side_width=3, side_color=mycolors.RED) p = f.points while surface.open: surface.check() surface.control() surface.clear() surface.show() f.show(surface) f.rotate(0.001) l = len(f) for i in range(l): h = (i + l - 1) % l j = (i + 1) % l angle = Angle.createFromThreePoints([p[h], p[i], p[j]]) angle.show(surface, [p[h], p[i]]) c = Circle.createFromPointAndRadius(p[i], 1, fill=Falses)
segments=[Segment(p.getPosition(),p.getNextPosition) for p in self.points] return segments def affectFriction(self,frixion=None): """Reduce th velocity of the object according to its frixion.""" f=self.factor for entity in self.entities: entity.velocity=[f*entity.velocity[0],f*entity.velocity[1]] if __name__=="__main__": from mysurface import Surface surface=Surface() c1=[-10,-10,10,10] f1=Form.random(c1) f1=MaterialForm.createFromForm(f1,[Force(0.001,0),Force(0,0.001)]) c2=[-10,-10,10,10] f2=Form.random(c2) f2=MaterialForm.createFromForm(f2,[Force(0.001,0),Force(0,0.001)]) #print(form[0].forces) #print(form.getMass()) origin=Point(0,0) while surface.open: surface.check() surface.clear() surface.control() surface.show() f1.update(t=0.1)
from myabstract import Form, Vector from mycontext import Context context = Context() f = Form.random() v = Vector.random() while context: context.check() context.control() context.clear() v *= 1.01 #f.move(v) f.show(context) context.flip()
class PhysicalBody(Body): def __init__(self, form, motion=Motion(d=2), moment=Motion(d=1), mass=1): """Create body using form and optional name.""" super().__init__(form, motion, moment) self.mass = mass def __str__(self): """Return the string representation of a physical body.""" return "p" + super().__str__() if __name__ == "__main__": from mycontext import Context context = Context(fullscreen=False) ru = random.uniform form1 = Form.random(n=4) motion1 = Motion(Vector(0, 0), Vector(ru(-1, 1), ru(-1, 1)), Vector(0, 0)) moment1 = Motion(Vector([0]), Vector([ru(-1, 1)]), Vector([0])) b1 = Body(form1, motion1, moment1) #b=Body.random() while context.open: context.check() context.clear() context.show() context.control() b1.show(context) b1.update(0.1) context.flip()
from myabstract import Form, Line import math #f = Form.createFromTuples([(0,1), (1,0), (1,1)]) f = Form.random(n=3) v1, v2, v3 = f.vectors # print(",".join(map(lambda x: str(x.angle), f.vectors))) print([str(v.angle) for v in f.vectors]) a1 = (v2.angle - v1.angle) % math.pi a2 = (v3.angle - v2.angle) % math.pi a3 = (v1.angle - v3.angle) % math.pi print("ai:", a1, a2, a3) print("sum:", sum([a1, a2, a3]) / math.pi) # l = Line.random() # print(l.angle) print("f.angles:", f.angles) print("sum(f.angles):", sum(f.angles)) print("f.abs_angles:", f.abs_angles) print("sum(f.abs_angles):", sum(f.abs_angles)) \