<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#/usr/bin/python

import cmath as C
import math as M
import Gnuplot
import time

def stringfunction(f, **kwds): return eval(f,globals(),kwds)

def aspan(a, b, N):
    step = (b-a)/float(max(N-1,1))
    return [ a+step*t for t in xrange(0,N) ]


def rect(xa, xb, ya, yb, xN=40, yN=40, NN=200):
    outy = []
    for x in aspan(xa,xb,xN):
        V = [ x+y*1j for y in aspan(ya,yb,NN)]
        outy.append(V)
    outx = []
    for y in aspan(ya,yb,yN):
        V = [ x+y*1j for x in aspan(xa,xb,NN)]
        outx.append(V)
    return outx, outy

def compute(f, grid):
    outx = [] 
    outy = []
    inx, iny = grid  
    for V in iny:
      yline = [ stringfunction(f, x=w.real, y =w.imag, z=w) for w in V ];
      outy.append(yline)
    for V in inx:
      xline = [ stringfunction(f, x=w.real, y =w.imag, z=w) for w in V ];
      outx.append(xline)
    return outx, outy

def polar(ra, rb, tta=0, ttb=2*C.pi, rN=10, ttN=40):
    return compute('x*C.exp(y*1.0j)', rect(ra, rb, tta, ttb, rN, ttN))

def range(grid):
    inx, iny = grid
    A = inx + iny 
    xa  = min([ min([w.real for w in V]) for V in A ])
    xb =  max([ max([w.real for w in V]) for V in A ])
    ya  = min([ min([w.imag for w in V]) for V in A ])
    yb =  max([ max([w.imag for w in V]) for V in A ])
    return (xa-0.1, xb+0.1, ya-0.1, yb+0.1) 

def size(grid):
    inx, iny = grid
    return len(inx), len(iny)
  
def plot(g, title, range, *data):
     ua, ub, va, vb = range
     g("""
     set title "%(title)s"
     set size square 1.0
     set xrange [ %(ua)f: %(ub)f]
     set yrange [ %(va)f: %(vb)f]
     """ % vars() )
     g.plot(*data) 
     time.sleep(0.2)
     g.reset()
     
def film(g, title, grid):
     inx, iny = grid
     uN, vN = size(grid)
     print uN, vN
     dd1 = []
     dd2 = []
     for t in xrange(uN+vN):
         if t &lt; uN:
              ds = [ (w.real, w.imag) for w in inx[t] ]
              dd1.append(ds) 
              d1 = Gnuplot.Data(dd1, with = 'lines 1')
              plot(g,title,range(grid),d1)
         else:
              ds = [(w.real,w.imag) for w in iny[t-uN] ] 
              dd2.append(ds)
              d2 = Gnuplot.Data(dd2, with = 'lines 3')
              plot(g,title,range(grid),d1,d2)

 
if __name__ == '__main__':
   g = Gnuplot.Gnuplot()

   R = rect(0, 1, 0, 1, 11, 19)
   film(g,'griglia cartesiana', R)
   raw_input('Premi una tasto per continuare...\n')

   P = polar(0.1, 1, 0,2*C.pi,11,39)
   film(g,'griglia polare x * exp(iy), z=x+iy, ', P)
   raw_input('Premi una tasto per continuare...\n')

   ZZ = compute('z*z', R)
   film(g,'Funzione z^2 su griglia cartesiana', ZZ)
   raw_input('Premi una tasto per continuare...\n')
      
   Youk = compute('z+1/z', P)
   film(g,'Funzione di Youkovski z+1/z su griglia polare', Youk)
   raw_input('Premi una tasto per continuare...\n')

   raw_input('Premi una tasto per uscire...\n')
 
</pre></body></html>