以前玩过个玩具,类似于齿轮,一个小齿轮在一个大齿轮里面转,把笔插入那个小齿轮的小孔,然后一圈一圈转,就有了一个神奇的图案。用python写了下,也不知对不对,图是出来了,分析了一下规律,应该就是一个公转自转问题。下面上代码:
下面是效果图:
[img]http://dl.iteye.com/upload/attachment/469348/d8d2122b-5cf0-31a4-9764-1ed987c3d38b.jpg[/img]
换一下参数:
[img]http://dl.iteye.com/upload/attachment/469354/5aec42e0-7bc5-3621-ab1b-69b9a0f15280.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/469350/65ae57ee-5157-3eec-813b-3396a1ea64ea.jpg[/img]
#! /usr/bin/env python
#coding=utf-8
import Image,ImageDraw,sys,math
def magic(bigc, bigr, smallr, l):
thita = 0
for thita_big in xrange(36000):
thita_small = thita_big*(float(bigr)/smallr)
#print(thita_small)
smallc = (bigc[0]+math.cos(thita_big)*bigr, bigc[1]+math.sin(thita_big)*bigr)
point = (smallc[0]+math.cos(thita_small+thita)*smallr, smallc[1]+math.sin(thita_small+thita)*smallr)
sep(point,"#FF0000")
def sep(point, fillVal):
draw.point(point, fill=fillVal)
im = Image.new("RGB",(500,500), "#FFFFFF")
draw = ImageDraw.Draw(im);
center = (250,250)
radius = 100
magic(center,radius,10,2)
del draw
im.save("c:/t.jpg")
下面是效果图:
[img]http://dl.iteye.com/upload/attachment/469348/d8d2122b-5cf0-31a4-9764-1ed987c3d38b.jpg[/img]
换一下参数:
[img]http://dl.iteye.com/upload/attachment/469354/5aec42e0-7bc5-3621-ab1b-69b9a0f15280.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/469350/65ae57ee-5157-3eec-813b-3396a1ea64ea.jpg[/img]