def center(path, points_step=10, min_points=100, max_error=0.009, max_points=1000): error = max_error + 1 n = float(min_points) center = None # TODO check if start and end are the same while error > max_error: if n > max_points: raise Exception("center: too many points") # evaluate path at n points if center is None: # find center, center = sum([path.point(i / n) for i in xrange(int(n))]) center = (center.real / n + center.imag / n * 1j) # evaluate at n + points_step points hrn = n + points_step hr = sum([path.point(i / hrn) for i in xrange(int(hrn))]) hr = (hr.real / hrn + hr.imag / hrn * 1j) # measure error diff = hr - center error = abs(diff.real) + abs(diff.imag) #print n, error, center n += points_step center = hr # return center evaluated at n return center.real, center.imag
def outroFrames(args): xml = etree.parse('froscon2015/artwork/outro.svg').getroot() pathstr = xml.find(".//*[@id='animatePath']").get('d') frog = xml.find(".//*[@id='animatePath']").get('d') path = svg.path.parse_path(pathstr) init = path.point(0) frames = int(0.5*fps) for i in range(0, frames): p = path.point(i / frames) - init yield ( ('animatePath', 'style', 'opacity', 0), ('license', 'style', 'opacity', 0), ) frames = 3*fps for i in range(0, frames): p = path.point(i / frames) - init yield ( ('frog', 'attr', 'transform', 'translate(%.4f, %.4f)' % (p.real, p.imag)), ) frames = int(0.5*fps)+1 for i in range(0, frames): yield tuple() frames = 1*fps for i in range(0, frames): yield ( ('logo', 'style', 'opacity', easeLinear(i, 1, -1, frames)), ) frames = 1*fps for i in range(0, frames): yield ( ('logo', 'style', 'opacity', 0), ('license', 'style', 'opacity', easeLinear(i, 0, 1, frames)), ) frames = 2*fps for i in range(0, frames): yield tuple() frames = 1*fps for i in range(0, frames): yield ( ('license', 'style', 'opacity', easeLinear(i, 1, -1, frames)), ) frames = 1*fps for i in range(0, frames): yield ( ('license', 'style', 'opacity', 0), )
def animSVG(screen, color:tuple, path:svg.path.path, scale:tuple, offset:tuple, line_width:float, time:float, framerate:float, clock): #Zeichnet einen SVG-Pfad (animiert); path: geparster SVG-Pfad, time:Animationszeit(in Sekunden); scale=(x_skalierung, y_skalierung), offset=(x_verschiebung, y_verschiebung) stepsize = 1/(time*framerate) #Benötigte Schrittweite um den Pfad in der angegebenen Zeit zu animieren svg_path_array = [(scale[0] * path.point(0).real + offset[0], scale[1] * path.point(0).imag + offset[1])] # Alle Punkte des SVG-Pfads in einem Array for i in np.arange(stepsize, 1, stepsize): #screen.fill((0, 0, 0)) #Bildschirm clearen/mit Schwarz füllen #---ZEICHENVORGANG next_point = (scale[0] * path.point(i+stepsize).real + offset[0], scale[1] * path.point(i+stepsize).imag + offset[1]) #nächster Punkt; "-------------" svg_path_array.append(next_point) #nächsten Punkt an Array anhängen --> Array neu Zeichnen drawArray(screen, color, svg_path_array, line_width) #--> Array wird "Stück für Stück" gezeichnet pg.display.flip() #Fenster updaten clock.tick(framerate)
def create_frames(path_data, frame_size): path = svg.path.parse_path(path_data) length = path.length() duration = math.sqrt(length) / STROKE_SPEED num_frames = int(math.ceil(duration * FRAME_RATE)) frames = [] previous_point = complex_to_tuple(path.point(0)) for frame in range(1, num_frames + 1): next_point = complex_to_tuple(path.point(frame / num_frames)) image = Image.new('P', frame_size) image.putpalette([0] * (3 * 256)) ImageDraw.Draw(image).line(previous_point + next_point, fill=1, width=STROKE_WIDTH) image.info['transparency'] = 0 image.info['loop'] = 0 image.info['duration'] = int(duration / num_frames * 1000) frames.append(image) previous_point = next_point return frames
def drawSVG(screen, color:tuple, path:svg.path.path, scale:tuple, offset:tuple, stepsize, line_width:float): path_arr = [] for i in np.arange(0, 1, stepsize): path_arr.append((scale[0] * path.point(i).real + offset[0], scale[1] * path.point(i).imag + offset[0])) drawArray(screen, color, path_arr, line_width)