[CentralOH] Comments and pull-requests welcome
Neil Ludban
nludban at columbus.rr.com
Mon Jan 16 00:18:05 EST 2017
On Sun, 15 Jan 2017 16:42:17 -0500
Eric Floehr <eric at intellovations.com> wrote:
> I was intrigued by this Mathologer video:
>
> https://www.youtube.com/watch?v=qhbuKbxJsk8
>
> titled "Times Tables, Mandelbrot and the Heart of Mathematics", and I
> wanted to create the circles and lines shown in the video, so I wrote a
> Python program to do so.
>
> Check out the program I wrote, it's a total of less than 200 lines,
> including blank lines and comments:
>
> https://github.com/efloehr/circlemult
>
> It requires Python 3 and PyQt5.
>
> I'd be interested in your comments, improvements, pull-requests, etc.
>
> Thanks!
> Eric
I was going to suggest numpy, then recognized the underlying equations,
and it turned into a project...
$ ./npcirclemult.py -h
usage: npcirclemult.py [-h] [-f F1] [-m N] [-c COLOR] [-r RADIUS] [-e F0]
[-p PHASE] [-w LINEWIDTH]
NumPy powered circlemult.
optional arguments:
-h, --help show this help message and exit
-f F1, --freq-1 F1
-m N, --modulus N
-c COLOR, --color COLOR
-r RADIUS, --radius RADIUS
-e F0, --freq-0 F0
-p PHASE, --phase PHASE
-w LINEWIDTH, --linewidth LINEWIDTH
$ ./npcirclemult.py -m 200 -e -17 -f 53 -c '#db7093'
$ ./npcirclemult.py -m 2048 -w 0.1 -f 42
#!/usr/local/bin/python2.7
from __future__ import division
import argparse
import sys
import matplotlib
import matplotlib.colors
import matplotlib.pyplot
import numpy
TWO_PI_J = 2j * numpy.pi
ap = argparse.ArgumentParser(
description='NumPy powered circlemult.',
add_help=True)
ap.add_argument('-f', '--freq-1', dest='F1', type=float, default=2.0)
ap.add_argument('-m', '--modulus', dest='N', type=int, default=100)
ap.add_argument('-c', '--color', type=str, default='MediumSeaGreen')
ap.add_argument('-r', '--radius', type=float, default=10)
ap.add_argument('-e', '--freq-0', dest='F0', type=float, default=1.0)
ap.add_argument('-p', '--phase', type=float, default=0.5)
ap.add_argument('-w', '--linewidth', type=float, default=1)
opts = ap.parse_args(sys.argv[1:])
t = numpy.arange(opts.N)
sp = opts.radius * numpy.exp(TWO_PI_J * (opts.phase + (opts.F0 / opts.N) * t))
ep = opts.radius * numpy.exp(TWO_PI_J * (0.5 + (opts.F1 / opts.N) * t))
mix = sp.conj() * ep
amp = numpy.abs(ep - sp)
fig = matplotlib.pyplot.figure(1, figsize=(8, 8))
gs = matplotlib.gridspec.GridSpec(3, 1, height_ratios=[6, 1, 1])
x1, y1 = sp.real, sp.imag
x2, y2 = ep.real, ep.imag
ax = fig.add_subplot(gs[0])
ax.set_title('Multiplication Circle')
#ax.axhline(0, color='lightgray')
#ax.axvline(0, color='lightgray')
lc = matplotlib.collections.LineCollection(
zip(zip(x1, y1), zip(x2, y2)),
colors=matplotlib.colors.colorConverter.to_rgba(opts.color),
linewidths=opts.linewidth)
ax.add_collection(lc)
ax.set_aspect('equal', 'datalim')
ax.margins(0.1)
ax = fig.add_subplot(gs[1])
ax.axhline(0, color='gray')
ax.plot(t, amp, 'b-')
ax.set_ylabel('seglen')
ax = fig.add_subplot(gs[2])
ax.axhline(0, color='gray')
ax.plot(t, mix.real, 'r-')
ax.plot(t, mix.imag, 'g-')
ax.set_ylabel('mixer')
matplotlib.pyplot.show()
#--#
More information about the CentralOH
mailing list