Math Adventures with Python
An Illustrated Guide to Exploring Math with Code
楽天ブックス(Kobo)
紀伊国屋書店(Kinoppy)
開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
- Processing 3 (プログラミング言語、統合開発環境、グラフィック機能)
Math Adventures with Python: An Illustrated Guide to Exploring Math with Code (Peter Farrell(著)、No Starch Press)のPART 2(RIDING INTO MATH TERRITORY)、7(COMPLEX NUMBERS)、EXERCISE 7-1(DRAWING A JULIA SET)の解答を求めてみる。
コード
Python 3
import math
xmin = -2
xmax = 2
ymin = -2
ymax = 2
x_range = xmax - xmin
y_range = ymax - ymin
xscl = 0
yscl = 0
def setup():
global xscl, yscl
size(600, 600)
colorMode(HSB)
noStroke()
xscl = width / float(x_range)
yscl = height / float(y_range)
def julia(z, c, num):
for count in range(num + 1):
if abs(z) > 2.0:
return count
z = z ** 2 + c
return num
def draw():
translate(width/2, height/2)
x = xmin
while x < xmax:
y = ymin
while y < ymax:
z = x + y * 1j
c = 0.285 + 0.01j
col = julia(z, c, 100)
if col == 100:
fill(0)
else:
fill(3 * col, 255, 255)
rect(x * xscl, y*yscl, 1, 1)
y += 0.01
x += 0.01
0 コメント:
コメントを投稿