Created
December 14, 2011 15:48
-
-
Save catupper/1477099 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| Haba=4 | |
| def pic(a): | |
| if(a==0):return 1 | |
| if(a!=1):return pic(a-1)*2+1 | |
| else:return 2 | |
| def turn(a): | |
| res=1 | |
| j=a%2 | |
| if(a==0):return 0 | |
| while(a): | |
| if(a%2==j):a/=2 | |
| else: | |
| j=a%2 | |
| res+=1 | |
| a/=2 | |
| return res%4 | |
| def dragon(x): | |
| global pictx,picty,pict | |
| if(turn(x)==2): | |
| for a in range(Haba+1): | |
| pict.putpixel((pictx+a,picty),(255,255,255)) | |
| pictx+=Haba | |
| if(turn(x)==3): | |
| for a in range(Haba+1): | |
| pict.putpixel((pictx,picty+a),(255,255,255)) | |
| picty+=Haba | |
| if(turn(x)==0): | |
| for a in range(Haba+1): | |
| pict.putpixel((pictx-a,picty),(255,255,255)) | |
| pictx-=Haba | |
| if(turn(x)==1): | |
| for a in range(Haba+1): | |
| pict.putpixel((pictx,picty-a),(255,255,255)) | |
| picty-=Haba | |
| k=input() | |
| pict=Image.new('RGB',(pic(1+k/2)*Haba,pic(1+k/2)*Haba)) | |
| pictx,picty=pic(1+k/2)*Haba/2,pic(1+k/2)*Haba/2 | |
| def main(): | |
| for a in range(2**k): | |
| dragon(a) | |
| pict.save('dragon'+str(k)+'.png','PNG') | |
| if __name__=='__main__':main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment