[Edu-sig] PDF geometry animations (ReportLab?) - and turtle module

Edward Cherlin echerlin at gmail.com
Sun May 17 18:06:18 CEST 2009


On Sun, May 17, 2009 at 6:35 AM, Gregor Lingl <gregor.lingl at aon.at> wrote:
> kirby urner schrieb
>>
>> For those of you looking for a way cool use of Python's ReportLab, I
>> so far have permission to release this one example "PDF flipbook"
>> showing how geometry concepts might be communicated using this simple
>> animation technique:
>>
>> http://www.4dsolutions.net/presentations/pdf_animation_by_ron_resch.pdf

Yes, the Python version below works much better for me. I'm not up for
clicking 1264 times to view the PDF.

> Very impressive and instructive! Is there a description somewhere, how
> 'flipbooks' like these
> can be produced?
>
> With me this way of communicating geometry concepts worked rather well, as
> you can see in the
> attachment.
>
> Regards,
> Gregor
>>
>> I've been sharing this as a teaser with Software Association of Oregon
>> as well, knowing Ron has a lot more where that came from (I'm suppose
>> to download a half-gig PDF next time in Pauling House for a bored er
>> board meeting).
>>
>> Kirby
>
> # uses turtle module from Python 2.6
> # hint from Kirby, 15. 5. 09
> # http://www.4dsolutions.net/presentations/pdf_animation_by_ron_resch.pdf
>
> from turtle import Turtle, Screen, Vec2D, mainloop
> import math
>
> A = 50.  # adjust this to your needs
>
> SHS = A / 20
> SF = 1.0
> DSF = 1.0038582416
> e = Vec2D(3**.5/2, 0.5)
>
> def dsin(angle):
>    return math.sin(angle*math.pi/180)
>
> def lines(l):
>    for i in range(6):
>        d.fd(l)
>        d.bk(l)
>        d.left(60)
>
> class TriTurtle(Turtle):
>    def __init__(self, c, r, tritype):
>        Turtle.__init__(self, shape="triangle")
>        self.c = c
>        self.r = r
>        self.speed(0)
>        self.pencolor(0,0,0)
>        if tritype == 1:
>            self.basecolor = (1.0, 0.80392, 0.0)
>            self.f = -1
>            self.left(30)
>        else:
>            self.basecolor = (0.43137, 0.43137, 1.0)
>            self.f = 1
>            self.left(90)
>        self.fillcolor(self.basecolor)
>        self.pu()
>        self.goto(c*A, r*A*3**.5/3)
>        self.shapesize(SHS, SHS, 1)
>        self.D = self.distance(0,0)
>        self.e = (1/self.D)*self.pos()
>    def setturn(self, phi):
>        self.goto(SF*self.D*dsin(90-phi)*self.e)
>        self.settiltangle(phi*self.f)
>        self.shapesize(SHS*SF)
>        if abs(self.c) + abs(self.r) > 2:
>            self.fillcolor([x + (1-x)*phi/360 for x in self.basecolor])
>            bc = phi/360.
>            self.pencolor(bc, bc, bc)
>
>
> s = Screen()
> s.reset()
> s.tracer(0)
> d = Turtle(visible=False)
> lines(500)
>
> triangles = []
> for c in range(-5,6,2):
>    triangles.append(TriTurtle(c, 1, 1))
>    triangles.append(TriTurtle(c, -1, 2))
> for c in range(-4,5,2):
>    triangles.append(TriTurtle(c, 2, 2))
>    triangles.append(TriTurtle(c, -2, 1))
>    triangles.append(TriTurtle(c, -4, 2))
>    triangles.append(TriTurtle(c, 4, 1))
> for c in range(-3,4,2):
>    triangles.append(TriTurtle(c, 5, 2))
>    triangles.append(TriTurtle(c, -5, 1))
>    triangles.append(TriTurtle(c, -7, 2))
>    triangles.append(TriTurtle(c, 7, 1))
> for c in range(-2,3,2):
>    triangles.append(TriTurtle(c, 8, 2))
>    triangles.append(TriTurtle(c, -8, 1))
> s.tracer(1)
>
> for phi in range(1,361):
>    SF = SF*DSF
>    s.tracer(0)
>    for t in triangles:
>        t.setturn(phi)
>    s.tracer(1)
>
> mainloop()
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>



-- 
Silent Thunder (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) is my name
And Children are my nation.
The Cosmos is my dwelling place, The Truth my destination.
http://earthtreasury.org/worknet (Edward Mokurai Cherlin)
-------------- next part --------------
# uses turtle module from Python 2.6
# hint from Kirby, 15. 5. 09
# http://www.4dsolutions.net/presentations/pdf_animation_by_ron_resch.pdf

from turtle import Turtle, Screen, Vec2D, mainloop
import math

A = 50.  # adjust this to your needs

SHS = A / 20
SF = 1.0
DSF = 1.0038582416
e = Vec2D(3**.5/2, 0.5)

def dsin(angle):
    return math.sin(angle*math.pi/180)

def lines(l):
    for i in range(6):
        d.fd(l)
        d.bk(l)
        d.left(60)   

class TriTurtle(Turtle):
    def __init__(self, c, r, tritype):
        Turtle.__init__(self, shape="triangle")
        self.c = c
        self.r = r
        self.speed(0)
        self.pencolor(0,0,0)
        if tritype == 1:
            self.basecolor = (1.0, 0.80392, 0.0)
            self.f = -1
            self.left(30)
        else:
            self.basecolor = (0.43137, 0.43137, 1.0)
            self.f = 1
            self.left(90)
        self.fillcolor(self.basecolor)
        self.pu()
        self.goto(c*A, r*A*3**.5/3)
        self.shapesize(SHS, SHS, 1)
        self.D = self.distance(0,0)
        self.e = (1/self.D)*self.pos()
    def setturn(self, phi):
        self.goto(SF*self.D*dsin(90-phi)*self.e)
        self.settiltangle(phi*self.f)
        self.shapesize(SHS*SF)
        if abs(self.c) + abs(self.r) > 2:
            self.fillcolor([x + (1-x)*phi/360 for x in self.basecolor])
            bc = phi/360.
            self.pencolor(bc, bc, bc)
            

s = Screen()
s.reset()
s.tracer(0)
d = Turtle(visible=False)
lines(500)

triangles = []
for c in range(-5,6,2):
    triangles.append(TriTurtle(c, 1, 1))
    triangles.append(TriTurtle(c, -1, 2))
for c in range(-4,5,2):
    triangles.append(TriTurtle(c, 2, 2))
    triangles.append(TriTurtle(c, -2, 1))
    triangles.append(TriTurtle(c, -4, 2))
    triangles.append(TriTurtle(c, 4, 1))
for c in range(-3,4,2):
    triangles.append(TriTurtle(c, 5, 2))
    triangles.append(TriTurtle(c, -5, 1))
    triangles.append(TriTurtle(c, -7, 2))
    triangles.append(TriTurtle(c, 7, 1))
for c in range(-2,3,2):
    triangles.append(TriTurtle(c, 8, 2))
    triangles.append(TriTurtle(c, -8, 1))
s.tracer(1)
                     
for phi in range(1,361):
    SF = SF*DSF
    s.tracer(0)
    for t in triangles:
        t.setturn(phi)
    s.tracer(1)
    
mainloop()


More information about the Edu-sig mailing list