def load_flame(self, flame_origin, flame_target=None, lerp=0.0): loaded_flame = self.flame try: if (lerp == 0.0 or flame_target is None): loaded_flame = flame_origin elif (lerp >= 1.0 or flame_origin is None): loaded_flame = flame_target else: # interpolation: flame_origin.time = 0 flame_target.time = 1 flames_lerp = [flame_origin, flame_target] flames_str = "<flames>%s</flames>" % "".join( map(flame_to_string, flames_lerp)) genomes, ngenomes = Genome.from_string(flames_str) targetflame = Genome() flam3_interpolate(genomes, ngenomes, lerp, 0, byref(targetflame)) loaded_flame = Flame(targetflame.to_string()) except Exception as ex: print('[!] error during interpolation at %s: %s' % (lerp, str(ex))) traceback.print_exc() return None return loaded_flame
def interpolate(flames): s = "<flames>%s</flames>" % "".join(map(to_string, flames)) genomes, ngenomes = Genome.from_string(s) target = Genome() for i in range(int(flames[0].time), int(flames[-1].time + 1)): flam3_interpolate(genomes, ngenomes, i, 0, byref(target)) flame = Flame(target.to_string()) flame.name = "morphed_%04d" % i yield flame
def reframe(self): TwoDoubles = ctypes.c_double * 2 b_min = TwoDoubles() b_max = TwoDoubles() b_eps = 0.1 nsamples = 10000 genome = Genome.from_string(self.to_string(False))[0] flam3_estimate_bounding_box(genome, b_eps, nsamples, b_min, b_max, RandomContext()) bxoff = (b_min[0] + b_max[0]) / 2 if abs(bxoff) < 5: self.x_offset = bxoff byoff = (b_min[1] + b_max[1]) / 2 if abs(byoff) < 5: self.y_offset = byoff denom = min(b_max[1] - b_min[1], b_max[0] - b_min[0]) if denom == 0: tmpscale = 0.0 else: tmpscale = 0.4 * 100.0 / min(b_max[1] - b_min[1], b_max[0] - b_min[0]) if tmpscale < 10: self.scale = 10 elif tmpscale > 100: self.scale = 100 else: self.scale = tmpscale
def reframe(self): TwoDoubles = ctypes.c_double * 2 b_min = TwoDoubles() b_max = TwoDoubles() b_eps = 0.01 nsamples = 10000 genome = Genome.from_string(self.to_string(False))[0] flam3_estimate_bounding_box(genome, b_eps, nsamples, b_min, b_max, RandomContext()) #print "%f %f" % ((b_min[0]+b_max[0])/2,(b_min[1]+b_max[1])/2) bxoff = (b_min[0]+b_max[0])/2 if abs(bxoff)<5: self.x_offset = bxoff byoff = (b_min[1]+b_max[1])/2 if abs(byoff)<5: self.y_offset = byoff denom = min(b_max[1]-b_min[1],b_max[0]-b_min[0]) if denom==0: tmpscale = 0.0 else: tmpscale = 0.7 * 100.0/min(b_max[1]-b_min[1],b_max[0]-b_min[0]) if tmpscale<10: self.scale = 10 elif tmpscale>100: self.scale = 100 else: self.scale = tmpscale
def DrawHistogram(self, dc=None): """ Create and draw the color histogram.""" dc = dc or wx.ClientDC(self) genome = Genome.from_string(self.parent.flame.to_string(True))[0] array = (c_double *256)() flam3_colorhist(genome, 1, array) dc.DrawLines([(i*1.5, 30-j*500) for i,j in enumerate(array)], 2, 2)
def var_preview(self, xform, range, numvals, depth): result = (c_double * (2* (2*numvals+1)**2))() genome = Genome.from_string(xform._parent.to_string(True))[0] index = xform.index if index is None: index = genome.final_xform_index flam3_xform_preview(genome, index, range, numvals, depth, result, RandomContext()) return [(x,-y) for x,y in zip(*[iter(result)]*2)]
def __init__(self, xform, Color): self.genome = Genome.from_string(xform._parent.to_string(True))[0][0] xform = xform._parent if xform.ispost() else xform self.index = xform.index if self.index is None: self.index = self.genome.final_xform_index kwds = config["Xform-Preview-Settings"].copy() depth = kwds.pop("depth") self.objects = [FC.PointSet(self.var_preview(depth=i + 1, **kwds), Color=tuple(c/(depth - i) for c in Color)) for i in range(depth)]
def Update(self, flame=None): flame = flame or self.parent.flame # Make the gradient image img = wx.ImageFromBuffer(256, 1, flame.gradient.to_buffer()) img.Rescale(384, 50) self.bmp = wx.BitmapFromImage(img) # Calculate the color histogram genome = Genome.from_string(flame.to_string(omit_details=True))[0] flam3_colorhist(genome, 3, RandomContext(), self.colorhist_array) self.Refresh()
def __init__(self, xform, Color): self.genome = Genome.from_string(xform._parent.to_string(True))[0][0] xform = xform._parent if xform.ispost() else xform self.index = xform.index if self.index is None: self.index = self.genome.final_xform_index kwds = config["Xform-Preview-Settings"].copy() depth = kwds.pop("depth") self.objects = [ FC.PointSet(self.var_preview(depth=i + 1, **kwds), Color=tuple(c / (depth - i) for c in Color)) for i in range(depth) ]
def flam3_render(flame, size, quality, **kwds): """Passes render requests on to flam3.""" flame = flame if type(flame) is Flame else Flame(flame) # try: genome = Genome.from_string(flame.to_string())[0] # except Exception: # raise ValueError("Error while parsing flame string.") width,height = size try: genome.pixels_per_unit /= genome.width/float(width) # Adjusts scale except ZeroDivisionError: raise ZeroDivisionError("Size passed to render function is 0.") genome.width = width genome.height = height genome.sample_density = quality output_buffer, stats = genome.render(**kwds) return output_buffer
def flam3_render(flame, size, quality, transparent=0, **kwds): """Passes render requests on to flam3.""" frame = Genome.load(to_string(flame), **kwds) output_buffer, stats = frame.render(size, quality, transparent) return output_buffer
from fr0stlib.pyflam3 import flam3_colorhist, Genome, flam3_xform_preview, RandomContext from ctypes import c_double genome = Genome.from_string(self.flame.to_string())[0] #array = (c_double *256)() #flam3_colorhist(genome, 1, array) array = (c_double *100)() flam3_xform_preview(genome, 0, 1, 3, 1, array, RandomContext()) print array[:]