Seite 1 von 1

Suche 'interlacing' Algorithmus...

Verfasst: Donnerstag 28. Mai 2015, 07:49
von jens
Bei meinem https://jedie.github.io/pypyjs-examples ... anced.html versuche ich das Mandelbrot Fractal "nach und nach" zu rendern...

Ist allerdings nicht wirklich optimal gelöst.

Ich hab "Adam 7" gefunden: https://en.wikipedia.org/wiki/Adam7_algorithm
Doch ich möchte einzelnen Linien beibehalten. Also mehr so wie GIF das macht.

Hier ein Vergleich Adam 7 in PNG mit GIF: http://www.schaik.com/png/adam7.html

Wer weiß weiter?

Re: Suche 'interlacing' Algorithmus...

Verfasst: Donnerstag 28. Mai 2015, 10:49
von jens
OK, hab was...

Damit man es "sehen" kann, hab ich ein kleines Tk Programm draus gemacht:

Code: Alles auswählen

#!/usr/bin/python
# coding: UTF-8

from __future__ import absolute_import, division, print_function

import sys
import time

PY2 = sys.version_info[0] == 2
if PY2:
    # Python 2
    import Tkinter as tkinter
else:
    # Python 3
    import tkinter

COLORS = ("white", "red", "green", "blue", "yellow", "orange", "cyan", "purple", "black")



def iterlace_generator(limit):
    print("limit:", limit)

    def gen_pow(limit):
        interlace_steps = []
        step=0
        while True:
            value = 2**step
            if value>=limit:
                return interlace_steps
            interlace_steps.append(value)
            step+=1
    interlace_steps = gen_pow(limit)
    interlace_steps.reverse()
    print("interlace_steps:", interlace_steps)

    pos = 0
    step = 1
    iteration = 0
    size = interlace_steps[iteration]
    new_iteration = True

    while True:
        yield (pos, size, iteration, new_iteration)
        new_iteration = False
        pos += (size * step)

        if pos>limit:
            step = 2
            iteration += 1
            print("\t*** get step_pos:", iteration)
            try:
                size = interlace_steps[iteration]
            except IndexError:
                return

            pos = size
            new_iteration = True


class Test(object):
    def __init__(self):
        self.root = tkinter.Tk()
        self.root.title(self.__class__.__name__)

        self.width=300
        self.height=70

        self.line_width = self.width

        self.canvas = tkinter.Canvas(self.root, width=self.width, height=self.height)
        self.canvas.pack()

        self.done = False

        self.interlace_generator = iterlace_generator(self.height)

        self.drawed_lines = []

        while not self.done:
            self.fill()

        self.root.mainloop()

    def fill(self):
        if self.done:
            return

        try:
            y, size, iteration, new_iteration = self.interlace_generator.__next__()
        except StopIteration:
            print("DONE")
            self.done = True
            return

        print(y)

        assert y not in self.drawed_lines
        self.drawed_lines.append(y)

        if new_iteration:
            print("***********")

        self.canvas.create_line(
            16*iteration, y,
            self.width-(16*iteration), y,
            fill=COLORS[iteration]
        )
        self.root.update()
        time.sleep(0.01)



if __name__ == "__main__":
    Test()


EDIT: und im Einsatz: https://jedie.github.io/pypyjs-examples ... anced.html