def CalcScale(self, points, h, v, hittest=False): """Returns the proportion by which the xform needs to be scaled to make the hypot pass through the point. If hittest is set to true, this func doubles as a hittest, and checks if the point is inside the line's hitbox.""" xf = Xform(points=points) a,d,b,e,c,f = xf.coefs # Get angle of the hypothenuse angle = polar(((b-a), (e-d)))[1] # create a rotated triangle and (c,f)->(h,v) vector. This way, the # hypothenuse is guaranteed to be horizontal, which makes everything # easier. xf.rotate(-angle) l, theta = polar(((h-c), (v-f))) width,height = rect((l, theta - angle)) # return the result. # Note that xf.d and xf.e are guaranteed to be equal. if hittest: return xf.a < width < xf.b and \ abs(height - xf.d) < self.circle_radius return height / xf.d
def test_random(self): x = Xform.random(self.flame, fx=1) self.assertEquals(x, None) x = Xform.random(self.flame, fx=0) self.assertNotEquals(x, None) self.assertTrue(x in self.flame.xform) self.assertTrue(x.index, 5) x.delete() f = self.flame.final self.flame.final = None x = Xform.random(self.flame, fx=1) self.assertNotEquals(x, None) if x.isfinal(): self.assertTrue(x is self.flame.final) self.assertEquals(x.index, None) else: self.assertTrue(x in self.flame.xform) self.assertEquals(x.index, 5) x.delete() self.flame.final = f x = Xform.random(self.flame, fx=0, ident=1) self.assertNotEquals(x, None) self.assertTrue(x in self.flame.xform) self.assertTrue(x.index, 5) #for k in x.list_variations(): # self.assertEquals(getattr(x, k), 1.0, '%s = %s' % (k, getattr(x, k))) x.delete() x = Xform.random(self.flame, fx=0, xw=1) self.assertNotEquals(x, None) self.assertTrue(x in self.flame.xform) self.assertTrue(x.index, 5) x.delete()
def GenRandomFlame(*a,**k): if 'numbasic' in k: nb = k['numbasic'] nxforms=randrange2(2,nb+1,int=int) else: nb=0 nxforms = len(a) f = Flame() for i in range(nxforms): if (nb>0): Xform.random(f,col=float(i)/(nxforms-1),**a[0]) else: Xform.random(f,col=float(i)/(nxforms-1),**a[i]) f.reframe() f.gradient.random(hue=(0, 1),saturation=(0, 1),value=(.25, 1),nodes=(4, 6)) return f