Yahoo!知恵袋に「円を開くように展開したときの,それぞれの頂点の軌跡を表す計算式が分かりません。」という質問がありました。Pythonでやりたいとのこと。
面白そうなので作ってみました。
できたのが次のGIFです。
汚いですがコードも載せておきます。
from PIL import Image, ImageDraw
import math
width = 400
height = 150
color_bg = (0, 0, 0)
color_point = (255, 255, 255)
base_x = 200
base_y = 140
base_r = 60
images = []
maisu = 50
for x in range(0, maisu):
im = Image.new("RGB", (width, height), color_bg)
draw = ImageDraw.Draw(im)
r = base_r + 2 ** (x * 0.75)
ox = base_x
oy = base_y - r
nagasa = base_r * math.pi
dosu = nagasa / (r * math.pi / 180)
start = 50
for i in range(-start, start + 1):
d = i * dosu / start
u = math.pi * d / 180
x = ox + r * math.sin(u)
y = oy + r * math.cos(u)
draw.point((x, y), fill=color_point)
images.append(im)
images[0].save("data/entenkai.gif",
save_all = True,
append_images = images[1:],
optimize = False,
duration = 100,
loop = 0)
import math
width = 400
height = 150
color_bg = (0, 0, 0)
color_point = (255, 255, 255)
base_x = 200
base_y = 140
base_r = 60
images = []
maisu = 50
for x in range(0, maisu):
im = Image.new("RGB", (width, height), color_bg)
draw = ImageDraw.Draw(im)
r = base_r + 2 ** (x * 0.75)
ox = base_x
oy = base_y - r
nagasa = base_r * math.pi
dosu = nagasa / (r * math.pi / 180)
start = 50
for i in range(-start, start + 1):
d = i * dosu / start
u = math.pi * d / 180
x = ox + r * math.sin(u)
y = oy + r * math.cos(u)
draw.point((x, y), fill=color_point)
images.append(im)
images[0].save("data/entenkai.gif",
save_all = True,
append_images = images[1:],
optimize = False,
duration = 100,
loop = 0)
コメント