def update(self): self.force[1] += -.1 * self.mass self.compute_wall_force_circle(self.size, .5) # air resistance if util.vmag(self.vel) > 1: vmag = util.vmag(self.vel) vdir = util.vdivs(self.vel, -.9 * vmag) self.force = util.vadd(self.force, vdir) self.integrate_force() self.vel[0] = util.clamp(self.vel[0], -20, 20) self.vel[1] = util.clamp(self.vel[1], -20, 20)
def draw(self): orth = [self.vel[1], -self.vel[0]] orth = util.vmuls(orth, self.size / util.vmag(orth)) return group(colors.red, shapes.regular_polygon(self.pos[0], self.pos[1], 30, self.size), quads(color(1, 0, 0, .5), self.pos[0] + orth[0], self.pos[1] + orth[1], self.pos[0] - orth[0], self.pos[1] - orth[1], color(1, 0, 0, 0), self.pos[0] - 10*self.vel[0] - orth[0], self.pos[1] - 10*self.vel[1] - orth[1], self.pos[0] - 10*self.vel[0] + orth[0], self.pos[1] - 10*self.vel[1] + orth[1] ))