def Get3dProjected(v): global ang, depth try: z = constrain(v.z, depth, 25) except: z = constrain(v.y, alteredH, 25) rotatedV = Vector(*v.elems[:2], z).RotationX(angX, Vector(0, 0, 0)) rotatedV = rotatedV.RotationY(ang, Vector(0, 0, 0)) ang += 0.001 projg(rotatedV) return rotatedV
def GetEndPoints2d(): global scale, depth, threeDoctant endPoints = [] for x in range(0, alteredW, scale): endPoints.append([ Vector(x - alteredW // 2, (alteredH // 2)), Vector(x - alteredW // 2, -(alteredH - alteredH // 2)) ]) func([DrawLines], Args=[[endPoints, (51, 81, 121)]]) for y in range(0, alteredH, scale): endPoints.append([ Vector(0 - (alteredW // 2), -(y - alteredH // 2)), Vector(alteredW - (alteredW // 2), -(y - alteredH // 2)) ]) func([DrawLines], Args=[[endPoints, (51, 81, 121)]]) return endPoints
def DoTheStuff(self, ball, left): center = Vector(0, 0) ball.speed = postImpactVelocity ball.velocity.x *= -1 velx = ball.velocity.x magnitude = ball.velocity.GetMagnitude() bottom = self.pos.y + self.h distFromBottom = bottom - h ballDist = ball.pos.y - h cur = abs(ballDist - distFromBottom) sign = -1 if left else 1 rotation = Plank.constrain(cur, sign * self.h, sign * 75) ball.velocity.rotate(center, rotation) ball.velocity = ball.velocity.normalized() * magnitude ball.velocity.x = velx
def GetBasisVectors(): global endPoints v1 = endPoints[0][0] v2 = endPoints[1][0] v3 = endPoints[-2][0] v4 = endPoints[-1][0] threshold = Vector(w // 2, h // 2) x1 = v2 - v1 x2 = v4 - v3 ihat = DiffRootVector(threshold, *(x1), clampMagnitude=False) jhat = DiffRootVector(threshold, *(x2), clampMagnitude=False) return (ihat, jhat)
def drawBasisVectors(): global ProjectIn3d, testVectors if not ProjectIn3d: i, j = GetBasisVectors() for bVectors in (i, j): bVectors.b, bVectors.r, bVectors.g = (255, 255, 255) bVectors.draw(screen) if testVectors is not None: vToTests = [ DiffRootVector(Vector(w // 2, h // 2), *testVector, clampMagnitude=False) for testVector in testVectors ] for vToTest in vToTests: vToTest.b, vToTest.r, vToTest.g = (0, 255, 0) vToTest.draw(screen)
def applyTrans(): global endPoints, T, testVectors, threeDoctant, ProjectIn3d percent = 0 percentInc = .01 if not threeDoctant else .1 IdentityMatrix = Matrix([[1, 0], [0, 1]]) if threeDoctant: IdentityMatrix = Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) IM = { (2, 2): Matrix([[1, 0], [0, 1]]), (3, 3): Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), (3, 2): Matrix([[1, 0], [0, 1], [0, 0]]), (2, 3): Matrix([[1, 0, 0], [0, 1, 0]]) } origVs = copy.deepcopy(endPoints) origTests = copy.deepcopy(testVectors) Transformation = adjustTransformation(T) if Vector(2, 2) == T.shape else T try: IdentityMatrix = IM[tuple(T.shape.elems)] except: pass while percent <= 1: curTransformation = Lerp(IdentityMatrix, Transformation, percent) if curTransformation.shape[0] == 3: ProjectIn3d = True for i, (v1, v2) in enumerate(endPoints): endPoints[i] = (v1.applyTransformation(curTransformation), v2.applyTransformation(curTransformation)) if testVectors != None and not ProjectIn3d: testVectors = [ testVector.applyTransformation(curTransformation) for testVector in testVectors ] func([DrawLines, clock.tick, drawBasisVectors], Args=[[endPoints, (51, 81, 121)], [20], []]) percent += percentInc percent = round(percent, 2) endPoints = copy.deepcopy(origVs) if not percent > 1 else endPoints testVectors = copy.deepcopy( origTests) if not percent > 1 else testVectors
def __init__(self, pos, vel=None, acc=None, magnitude=None, dampeningAffect=1, mass=1): self.pos = pos self.velocity = Vector( math.cos(math.radians(random.choice([-180, 0]))), math.sin(math.radians(random.choice(range( 0, 360))))) if not vel is None else None self.acceleration = acc self.damp = dampeningAffect self.trail = [] self.maxTrail = 3 self.speed = 400 self.mass = mass self.radius = 4
def func(funcsToCall=[], Args=None): global origEnds, origTestVectors screen.fill((0, 0, 0)) try: DrawLines(origEnds, (21, 21, 51)) if not ProjectIn3d: vToTests = [ DiffRootVector(Vector(w // 2, h // 2), *origTestVector, clampMagnitude=False) for origTestVector in origTestVectors ] for vToTest in vToTests: vToTest.b, vToTest.r = (51, 51) vToTest.draw(screen) except: pass for i, func in enumerate(funcsToCall): func(*Args[i]) pygame.display.update() CheckEvent()
import pygame, copy, math, random from pygame.locals import * from seein import Vector, Matrix pygame.init() clock = pygame.time.Clock() frameRate = 60 deltaTime = 1 / frameRate w, h = 700, 480 screen = pygame.display.set_mode((w, h)) gravity = Vector(0, 9.8) postImpactVelocity = 400 class particle: def __init__(self, pos, vel=None, acc=None, magnitude=None, dampeningAffect=1, mass=1): self.pos = pos self.velocity = Vector( math.cos(math.radians(random.choice([-180, 0]))), math.sin(math.radians(random.choice(range( 0, 360))))) if not vel is None else None self.acceleration = acc self.damp = dampeningAffect self.trail = [] self.maxTrail = 3 self.speed = 400
threeDoctant = False if threeDoctant: ProjectIn3d = 1 if ProjectIn3d: alteredW, alteredH = 500, 500 mouseIsDown = False origXPos = None origYPos = None endPoints = EndPoints() origEnds = copy.deepcopy(endPoints) eigs = list(np.linalg.eig(np.array([[1, 1], [1, 1]]))[1]) #eigs[0][1] *= -1 testVectors = [Vector(*eig) * scale * i for eig in eigs for i in range(-5, 5)] ##y coord flipped #testVectors = [] origTestVectors = [copy.copy(each) for each in testVectors] Ts = { 0: Matrix([[ 1, 1, ], [-1, -1], [1, 1]]), 1: Matrix([[1, -1, 1], [1, -1, 1]]) } Ts = {0: Matrix([[1, 1], [1, 1]]), 1: Matrix([[1, 0], [0, 1]])} # Ts = {0:Vector(0,0,0).RotationOnX(90), 1:Matrix([[1,-1,0], # [1,2,0], # [1,2,3]])}