From 4445796ff2abc36a5679bdbcb7ff3c4ed7f64b4d Mon Sep 17 00:00:00 2001 From: Fred Z Date: Wed, 21 Feb 2018 23:13:33 +0100 Subject: [PATCH] Ajoute scripts fractale et 'lint' exercices --- linttest01.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ linttest02.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 linttest01.py create mode 100644 linttest02.py diff --git a/linttest01.py b/linttest01.py new file mode 100644 index 0000000..7ccc8a8 --- /dev/null +++ b/linttest01.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python2 +# by Daniel Rosengren, modified by e-satis +# https://stackoverflow.com/a/1429145/6709630 + +import sys, time +stdout = sys.stdout + +BAILOUT = 16 +MAX_ITERATIONS = 1000 + +class Iterator(object) : + + def __init__(self): + + print 'Rendering...' + for y in xrange(-39, 39): + stdout.write('\n') + for x in xrange(-39, 39): + if self.mandelbrot(x/40.0, y/40.0) : + stdout.write(' ') + else: + stdout.write('*') + + + def mandelbrot(self, x, y): + cr = y - 0.5 + ci = x + zi = 0.0 + zr = 0.0 + + for i in xrange(MAX_ITERATIONS) : + temp = zr * zi + zr2 = zr * zr + zi2 = zi * zi + zr = zr2 - zi2 + cr + zi = temp + temp + ci + + if zi2 + zr2 > BAILOUT: + return i + + return 0 + +t = time.time() +Iterator() +print '\nPython Elapsed %.02f' % (time.time() - t) diff --git a/linttest02.py b/linttest02.py new file mode 100644 index 0000000..501d186 --- /dev/null +++ b/linttest02.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python2 +# by Daniel Rosengren, modified by e-satis +""" +Module doctring +https://stackoverflow.com/a/1429145/6709630 +""" + + +import time +from sys import stdout + +BAILOUT = 16 +MAX_ITERATIONS = 1000 + +def mandelbrot(dim_1, dim_2): + """ + function doc string + """ + cr1 = dim_1 - 0.5 + ci1 = dim_2 + zi1 = 0.0 + zr1 = 0.0 + + for i in xrange(MAX_ITERATIONS) : + temp = zr1 * zi1 + zr2 = zr1 * zr1 + zi2 = zi1 * zi1 + zr1 = zr2 - zi2 + cr1 + zi1 = temp + temp + ci1 + + if zi2 + zr2 > BAILOUT: + return i + + return 0 + +def execute() : + """ + func doc string + """ + print 'Rendering...' + for dim_1 in xrange(-39, 39): + stdout.write('\n') + for dim_2 in xrange(-39, 39): + if mandelbrot(dim_1/40.0, dim_2/40.0) : + stdout.write(' ') + else: + stdout.write('*') + + +START_TIME = time.time() +execute() +print '\nPython Elapsed %.02f' % (time.time() - START_TIME)