日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

用python tkinter显示Mandelbrot图

發布時間:2025/4/16 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用python tkinter显示Mandelbrot图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我前面已經講過了用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 = LX1while x < LX2:y = LY1while 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 += ystepx += xstepdef count(c):z = complex(0,0)for i in range(COUNT_LIMIT):z = z*z + cif abs(z) > 2: return ireturn COUNT_LIMITCOUNT_LIMIT = 1000 LX1 = -2.0 LX2 = 2.0 LY1 = -2.0 LY2 = 2.0random_color = [] for i in range(COUNT_LIMIT):r = randint(0, 255)g = randint(0, 255)b = randint(0, 255)r = "%02x" % rg = "%02x" % gb = "%02x" % brandom_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計算速度太慢了,經常卡死,就放棄了。大家可以嘗試一下

如何綁定鼠標滾輪的事件,請見下一篇文章。

總結

以上是生活随笔為你收集整理的用python tkinter显示Mandelbrot图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。