代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Python
】
随机生成简单网络可用于模拟图遍历算法
作者:
looyer
/ 发布于
2012/10/22
/
937
<div>require 'iuplua'</div> <div>require 'iupluagl'</div> <div>require 'luagl'</div> <div>require 'luaglu'</div> <div>require 'date'</div> <div></div> <div>cvs = iup.glcanvas{expand = 'yes'} <div></div> <div>local width = 800</div> <div>local height = 600</div> <div></div> <div>function cvs:map_cb()</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>iup.GLMakeCurrent(self)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.ClearColor(0, 0, 0, 0)</div> <div>end</div> <div></div> <div>function cvs:resize_cb(cw, ch)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>iup.GLMakeCurrent(self)</div> <div></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>width = cw</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>height = ch</div> <div></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Viewport(0, 0, cw, ch)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>glu.Ortho2D(0, cw, 0, ch)</div> <div>end</div> <div></div> <div>function cvs:button_cb(btn, press, x, y, stat)</div> <div>end</div> <div></div> <div>function cvs:k_any(c)</div> <div>end</div> <div></div> <div>function distan(A, B)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>return math.sqrt((A.x - B.x)^2 + (A.y - B.y)^2)</div> <div>end</div> <div></div> <div>pt_tab = {} <div>line_tab = {} <div></div> <div></div> <div>--print(os.date())</div> <div>--now = date(os.date())</div> <div>--print(type(now))</div> <div>--math.randomseed(now.getticks())</div> <div>local tab_date = os.date('*t')</div> <div>math.randomseed((tab_date.min * 100 + tab_date.sec)^2)</div> <div></div> <div>for i = 1, 15 do</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>local x = math.random(50, width - 50)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>local y = math.random(50, height - 50)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>local tmp = {} <div><span class="Apple-tab-span" style="white-space:pre"> </span>tmp["x"] = x</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>tmp["y"] = y</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>local idx = 0</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>for j = 1, #pt_tab do</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>if distan(pt_tab[j], tmp) < 30 then</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>idx = 1</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>break</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>if idx == 0 then</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>if #pt_tab ~= 0 then</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>cnt = math.random(1, #pt_tab)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>for i = 1, cnt do</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>sid = math.random(1, #pt_tab)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>line_tab[#line_tab + 1] = {sid, #pt_tab + 1} <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>pt_tab[#pt_tab + 1] = tmp</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div>end</div> <div></div> <div>--print(#pt_tab)</div> <div></div> <div>function cvs:action(x, y)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>iup.GLMakeCurrent(self)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Clear('COLOR_BUFFER_BIT')</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.ClearColor(0, 0, 0, 0)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Color(255, 0, 0)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Begin('POINTS')</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>for i = 1, #pt_tab do</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Vertex(pt_tab[i].x, pt_tab[i].y)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.End()</div> <div></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Color(0, 255, 0)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>for i = 1, #line_tab do</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Begin('LINES')</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Vertex(pt_tab[line_tab[i][1]].x, pt_tab[line_tab[i][1]].y)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Vertex(pt_tab[line_tab[i][2]].x, pt_tab[line_tab[i][2]].y)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.End()</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div> <div></div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>gl.Flush()</div> <div>end</div> <div></div> <div>dlg = iup.dialog{cvs; title = 'gis', rastersize = '800x600'} <div>dlg:show()</div> <div></div> <div>iup.MainLoop()</div>
试试其它关键字
模拟图
同语言下
.
比较两个图片的相似度
.
过urllib2获取带有中文参数的url内容
.
不下载获取远程图片的宽度和高度及文件大小
.
通过qrcode库生成二维码
.
通过httplib发送GET和POST请求
.
Django下解决小文件下载
.
遍历windows的所有窗口并输出窗口标题
.
根据窗口标题调用窗口
.
python 抓取搜狗指定公众号
.
pandas读取指定列
可能有用的
.
实现测量程序运行时间及cpu使用时间
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
looyer
贡献的其它代码
(
1
)
.
随机生成简单网络可用于模拟图遍历算法
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3