開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
行列プログラマー(Philip N. Klein (著)、 松田 晃一 (翻訳)、 弓林 司 (翻訳)、 脇本 佑紀 (翻訳)、 中田 洋 (翻訳)、 齋藤 大吾 (翻訳)、オライリージャパン)の1章(体)、1.4(C(複素数)と遊ぼう)、1.4.11(変換の合成)の課題1.4.20を取り組んでみる。
課題 1.4.20
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
from plotting import plot
import image
filename = 'img01.png'
data = image.file2image(filename)
height = len(data)
width = len(data[0])
def center(z):
reals = {z0.real for z0 in z}
imags = {z0.imag for z0 in z}
real_c = (max(reals) + min(reals)) / 2
imag_c = (max(imags) + min(imags)) / 2
return {z0 - real_c - imag_c * 1j for z0 in z}
pts = { x + (height - y) * 1j
for y, l in enumerate(data)
for x, (pt, _, _) in enumerate(l)
if pt < 120}
pts = center(pts)
pts = {pt * math.e ** (math.pi / 4 * 1j) * 1/2 for pt in pts}
plot(pts, max(width, height))
input()
入出力結果(Terminal, IPython)
$ ./sample4_20.py q $
0 コメント:
コメントを投稿