{"id":1179,"date":"2014-07-19T16:30:55","date_gmt":"2014-07-19T08:30:55","guid":{"rendered":"http:\/\/www.hsyyf.me\/?p=1179"},"modified":"2014-07-19T16:30:55","modified_gmt":"2014-07-19T08:30:55","slug":"dla%e7%94%9f%e9%95%bf%e6%a8%a1%e5%9e%8b%e6%a8%a1%e6%8b%9f","status":"publish","type":"post","link":"https:\/\/www.hsyyf.me\/?p=1179","title":{"rendered":"dla\u751f\u957f\u6a21\u578b\u6a21\u62df"},"content":{"rendered":"<p>\n\t\u4f9d\u65e7\u662f\u91c7\u7528python\u548cQt\u5199\u7684\uff0c\u4f9d\u8d56\u7684\u5e93\u6709Vpython\u548cnumpy\uff0c\u5206\u70b9\u751f\u957f\u548c\u7ebf\u751f\u957f\u4e24\u79cd\u3002151*151\u7684\u70b9\u9635\uff0c4000\u4e2a\u70b9\uff0c1\/3\u7528\u7ea2\u8272\u70b9\uff0c1\/3\u7528\u9ec4\u8272\u70b9\uff0c1\/3\u7528\u7eff\u8272\u70b9\u3002\n<\/p>\n<p>\n\t\u5148\u4e0a\u4e24\u4e2a\u56fe\uff0c\u7b2c\u4e00\u4e2a\u662f\u70b9\u751f\u957f\uff0c\u7b2c\u4e8c\u4e2a\u662f\u7ebf\u751f\u957f\u7684\u3002<a href=\"http:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/point.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"point\" class=\"aligncenter size-full wp-image-1181\" height=\"450\" src=\"http:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/point.jpg\" width=\"430\" srcset=\"https:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/point.jpg 430w, https:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/point-286x300.jpg 286w\" sizes=\"auto, (max-width: 430px) 100vw, 430px\" \/><\/a>\n<\/p>\n<p>\n\t<a href=\"http:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/line.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"line\" class=\"aligncenter size-full wp-image-1182\" height=\"450\" src=\"http:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/line.png\" width=\"429\" srcset=\"https:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/line.png 429w, https:\/\/www.hsyyf.me\/wp-content\/uploads\/2014\/07\/line-286x300.png 286w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/a>\n<\/p>\n<p><code lang=\"Python\">#coding=utf-8<br \/>\nimport sys<br \/>\nfrom PyQt4 import QtGui, QtCore<br \/>\nfrom visual import *<br \/>\nimport numpy as np<\/p>\n<p>class Window( QtGui.QWidget ):<br \/>\n    def __init__( self ):<br \/>\n        super( Window, self ).__init__()<br \/>\n        self.setWindowTitle( \"DLA\" )<br \/>\n        self.resize( 250, 250 )<br \/>\n        gridlayout = QtGui.QGridLayout()<\/p>\n<p>        self.lines = QtGui.QPushButton( u\"\u7ebf\u751f\u957f\" )<br \/>\n        gridlayout.addWidget( self.lines, 0, 0, 1, 3 )<br \/>\n        self.points = QtGui.QPushButton( \"\u70b9\u751f\u957f\" )<br \/>\n        gridlayout.addWidget( self.points, 1, 0, 1, 3 )<br \/>\n        self.quit = QtGui.QPushButton(\"\u9000\u51fa\")<br \/>\n        gridlayout.addWidget( self.quit, 2, 0, 1, 3 )<br \/>\n        self.setLayout( gridlayout )<br \/>\n        self.connect(self.lines, QtCore.SIGNAL(\"clicked()\"),self.Lines)<br \/>\n        self.connect(self.points, QtCore.SIGNAL(\"clicked()\"),self.Points)<br \/>\n        self.connect(self.quit, QtCore.SIGNAL(\"clicked()\"),self.Close)<\/p>\n<p>    def Lines(self):<br \/>\n        a=np.zeros([n,n])<br \/>\n        a[n\/2,]=1<br \/>\n        plot(a)<br \/>\n        return<br \/>\n    def Points(self):<br \/>\n        a=np.zeros([n,n])<br \/>\n        a[n\/2,n\/2]=1<br \/>\n        plot(a)<br \/>\n        return<br \/>\n    def Close(self):<br \/>\n        self.close()<\/p>\n<p>def plot(a):<br \/>\n    p=0<br \/>\n    while True:<br \/>\n        x=int(np.random.random()*(n-1)+1)<br \/>\n        y=int(np.random.random()*(n-1)+1)<br \/>\n        while True:<br \/>\n            k=int(4*np.random.random())+1<br \/>\n            if x<0 or x>n-1 or y<0 or y>n-1:<br \/>\n                break<br \/>\n            if (x-1)<0 or (x+1)>n-1 or (y-1)<0 or (y+1)>n-1:<br \/>\n                break<\/p>\n<p>            if k==1:<br \/>\n                if a[x+1,y]!=1:<br \/>\n                    x=x+1<br \/>\n                else:<br \/>\n                    a[x,y]=1<br \/>\n                if x>n:<br \/>\n                    break<\/p>\n<p>            if k==2:<br \/>\n                if a[x,y+1]!=1:<br \/>\n                    y=y+1<br \/>\n                else:<br \/>\n                    a[x,y]=1<br \/>\n                if y>n:<br \/>\n                    break<\/p>\n<p>            if k==3:<br \/>\n               if a[x-1,y]!=1:<br \/>\n                   x=x-1<br \/>\n               else:<br \/>\n                   a[x,y]=1<br \/>\n               if x<0:\n                   break\n               \n            if k==4:\n               if a[x,y-1]!=1:\n                   y=y-1\n               else:\n                   a[x,y]=1\n               if y<0:\n                   break\n            if a[x,y]==1:\n                p=p+1\n                if p<numbers\/3:\n                    sphere(pos=(x-n\/2,y-n\/2,0),radius=0.5,color=color.red)\n                elif p>2*numbers\/3:<br \/>\n                    sphere(pos=(x-n\/2,y-n\/2,0),radius=0.5,color=color.green)<br \/>\n                else:<br \/>\n                    sphere(pos=(x-n\/2,y-n\/2,0),radius=0.5,color=color.orange)<br \/>\n                break<br \/>\n        if p>numbers:<br \/>\n            break<br \/>\n    return<\/p>\n<p>n=151<br \/>\nnumbers=4000<br \/>\na=np.zeros([n,n])<\/p>\n<p>app = QtGui.QApplication( sys.argv )<br \/>\ndemo = Window()<br \/>\ndemo.show()<br \/>\napp.exec_()<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f9d\u65e7\u662f\u91c7\u7528python\u548cQt\u5199\u7684\uff0c\u4f9d\u8d56\u7684\u5e93\u6709Vpython\u548cnumpy\uff0c\u5206\u70b9\u751f\u957f\u548c\u7ebf\u751f\u957f\u4e24\u79cd\u3002151*151\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[3],"tags":[161,87,160],"class_list":["post-1179","post","type-post","status-publish","format-standard","hentry","category-3","tag-dla","tag-python","tag-qt"],"_links":{"self":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/posts\/1179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1179"}],"version-history":[{"count":0,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}