用python tkinter显示Mandelbrot图
来源:互联网 发布:物联网与大数据的关系 编辑:程序博客网 时间:2024/06/07 17:34
我前面已经讲过了用Matlab显示Mandelbrot图的方法,原理在那里也说的,链接地址:http://blog.csdn.net/whoispo/article/details/49557823, 这次就不讲了。直接贴代码(python3):
# encoding=utf-8from tkinter import *from random import randintdef paint(LX1, LX2, LY1, LY2): xscale = float(canvas["width"]) / (LX2 - LX1) yscale = float(canvas["height"]) / (LY2 - LY1) xstep = (LX2 - LX1) / (float(canvas["width"])) ystep = (LY2 - LY1) / (float(canvas["height"])) x = LX1 while x < LX2: y = LY1 while y < LY2: c = count(complex(x, y)) if c == COUNT_LIMIT: color = "black" else: color = random_color[c-1] canvas.create_rectangle((x - LX1) * xscale, (y - LY1) * yscale, (x - LX1) * xscale, (y - LY1) * yscale, fill=color, outline = color, tags="pic") y += ystep x += xstepdef count(c): z = complex(0,0) for i in range(COUNT_LIMIT): z = z*z + c if abs(z) > 2: return i return COUNT_LIMITCOUNT_LIMIT = 1000LX1 = -2.0LX2 = 2.0LY1 = -2.0LY2 = 2.0random_color = []for i in range(COUNT_LIMIT): r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) r = "%02x" % r g = "%02x" % g b = "%02x" % b random_color.append("#"+r+g+b)window = Tk()window.title("曼德布罗特分形")canvas = Canvas(window, width=500, height=500, bg="white")canvas.pack()paint(LX1, LX2, LY1, LY2)window.mainloop()
python的计算速度肯定与Matlab是没办法比的,运行时耐心点吧。本来还绑定一个鼠标滚动放大缩小的事件,但是python计算速度太慢了,经常卡死,就放弃了。大家可以尝试一下
如何绑定鼠标滚轮的事件,请见下一篇文章。
0 0
- 用python tkinter显示Mandelbrot图
- 用Python画Mandelbrot集
- 用matlab画Mandelbrot(曼德布罗特)图
- Python Tkinter GUI(三)显示图片
- Python Tkinter Hello,Tkinter
- python tkinter
- python:Tkinter
- Python Tkinter
- python Tkinter(2)label 包含图像显示
- python TKinter 实现显示日期时间和秒表的功能
- 解决Ubuntu python 使用turtle显示没有Tkinter模块问题
- 用Python的Tkinter实现时钟
- Python下用Tkinter进行GUI编程
- tkinter显示当前时间
- Python Tkinter的HelloWorld
- Python GUI (Tkinter)
- Python + Tkinter画树
- python Tkinter例子
- UC浏览器无法打开百度网盘
- IDDFS--UVA - 11212 Editing a Book
- 各种接口API
- 关于ComponentName的使用
- linux config/make/make install
- 用python tkinter显示Mandelbrot图
- OpenGL入门学习
- ZOJ3623 Battle Ships
- Sum Root to Leaf Numbers
- No.5 Single Number 找出一组数中落单的数
- CSS基础学习四:元素选择器
- ./configure,make,make install的作用
- 文件的结构
- CentOS 6.5下安装MySQL 5.6.21