博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
拓扑图动态制作
阅读量:6477 次
发布时间:2019-06-23

本文共 4837 字,大约阅读时间需要 16 分钟。

VC# + GDI+ 绘制

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void Form1_Paint(object sender, PaintEventArgs e)        {            Graphics g = e.Graphics;            //Pen pen = new Pen(Color.Red, 5);            //Point point1 = new Point(10, 50);            //Point point2 = new Point(100, 50);            //g.DrawLine(pen, point1, point2);            //Pen pen1 = new Pen(Color.Black, 3);            //Point point3 = new Point(150, 30);            //Point point4 = new Point(150, 100);            //g.DrawLine(pen1, point3, point4);            // Draw ellipse to screen.            Pen pen = new Pen(Color.Gray, 5);            Brush brush = new SolidBrush(Color.Gray);            e.Graphics.DrawEllipse(pen, 100, 200, 30, 30);            e.Graphics.FillEllipse(brush, 100, 200, 30, 30);            e.Graphics.DrawEllipse(pen, 200, 200, 30, 30);            e.Graphics.FillEllipse(brush, 200, 200, 30, 30);            e.Graphics.DrawEllipse(pen, 300, 200, 30, 30);            e.Graphics.FillEllipse(brush, 300, 200, 30, 30);            e.Graphics.DrawLine(pen, 100+15, 200+15, 200 + 15, 200 + 15);        }    }}
View Code

 

Matlab,使用graph的plot,可以设定点的位置,相对简单些

clc; clear;s = [1 1 1 1 1 1 1 9 9 9 9 9 9 9];t = [2 3 4 5 6 7 8 2 3 4 5 6 7 8];G = graph(s,t);h = plot(G)h.XData = [0 -3 -2 -1 0 1 2 3 0];h.YData = [2 0 0 0 0 0 0 0 -2];
View Code

 

调整节点位置,利用pause制作动画

clc; clear;s = [1 1 2 4 5 6 1 2 3];t = [2 3 3 7 8 9 4 5 6];G = graph(s,t);h = plot(G)h.XData = [0 -1 1 -1  0  1 -1  0  1];h.YData = [2  1 1 -1 -1 -1 -2 -2 -2];h.LineWidth = 3;h.MarkerSize = 8;pause(0.2)s = [1 1 2 4 5 6 1 2 3];t = [2 3 3 7 8 9 5 4 6];G = graph(s,t);h = plot(G)h.XData = [0 -1 1 -1  0  1 -1  0  1];h.YData = [2  1 1 -1 -1 -1 -2 -2 -2];h.LineWidth = 3;h.MarkerSize = 8;pause(0.5)s = [1 1 2 4 5 6 1 2 3];t = [2 3 3 7 8 9 6 5 4];G = graph(s,t);h = plot(G)h.XData = [0 -1 1 -1  0  1 -1  0  1];h.YData = [2  1 1 -1 -1 -1 -2 -2 -2];h.LineWidth = 3;h.MarkerSize = 8;
View Code

这儿有一个如何利用matlab制作gif图的教程。

 

这个博客的方法好,提供了一个库函数

function savegif(varargin)global iiii;global time;tip=0;p=clock;if isempty(varargin)    filename='untitledgif.gif';else    filename=varargin{
1}; if length(filename)<4 filename=[filename,'.gif']; else if ~strcmp(filename(end-3:end),'.gif') filename=[filename,'.gif']; end end if nargin>=2 tip=1; end endif isempty(iiii) iiii=0; time=p(6);else iiii=iiii+1; if ((p(6)>=time)*(p(6)-time)+(p(6)
100 iiii=0; end time=p(6);endif tip ==0 f=getframe(gca);%getframe(F)gets a frame from the current axes else pos=get(gcf,'position'); f=getframe(gcf,[1,1,pos(3),pos(4)]);endf=frame2im(f);[f,map]=rgb2ind(f,256);if iiii==0 || exist(filename,'file')==0 imwrite(f,map,filename,... 'delaytime',rand(1));else imwrite(f,map,filename,'writemode','append',... 'delaytime',rand(1));end
View Code

绘制代码,做了5个拓扑快照

clc; clear;a06 = 4;a08 = 7;a10 = 5;a12 = 8;a20 = 6;a22 = 9;for i=1:10    s = [1 1 2  1    2  3   4 5 6];    t = [2 3 3 a12 a22  a20 7 8 9];    G = graph(s,t);    h = plot(G);    h.XData = [0 -0.5 0.5 -1+0.2  0+0.2  1+0.2 -1-0.2  0-0.2  1-0.2];    h.YData = [2  0.5 0.5 -1 -1 -1 -2 -2 -2];    h.LineWidth = 3;    h.MarkerSize = 8;    pause(0.01);savegif('dot');    s = [1 1 2  1    2  3   4 5 6];    t = [2 3 3 a06 a12  a10 7 8 9];    G = graph(s,t);    h = plot(G);    h.XData = [0 -0.5 0.5 -1+0.2  0+0.2  1+0.2 -1-0.2  0-0.2  1-0.2];    h.YData = [2  0.5 0.5 -1 -1 -1 -2 -2 -2];    h.LineWidth = 3;    h.MarkerSize = 8;    pause(0.01);savegif('dot');    s = [1 1 2  1    2  3   4 5 6];    t = [2 3 3 a22 a08  a20 7 8 9];    G = graph(s,t);    h = plot(G);    h.XData = [0 -0.5 0.5 -1+0.2  0+0.2  1+0.2 -1-0.2  0-0.2  1-0.2];    h.YData = [2  0.5 0.5 -1 -1 -1 -2 -2 -2];    h.LineWidth = 3;    h.MarkerSize = 8;    pause(0.01);savegif('dot');        s = [1 1 2  1    2  3   4 5 6];    t = [2 3 3 a20 a06  a08 7 8 9];    G = graph(s,t);    h = plot(G);    h.XData = [0 -0.5 0.5 -1+0.2  0+0.2  1+0.2 -1-0.2  0-0.2  1-0.2];    h.YData = [2  0.5 0.5 -1 -1 -1 -2 -2 -2];    h.LineWidth = 3;    h.MarkerSize = 8;    pause(0.01);savegif('dot');        s = [1 1 2  1    2  3   4 5 6];    t = [2 3 3 a08 a10  a06 7 8 9];    G = graph(s,t);    h = plot(G);    h.XData = [0 -0.5 0.5 -1+0.2  0+0.2  1+0.2 -1-0.2  0-0.2  1-0.2];    h.YData = [2  0.5 0.5 -1 -1 -1 -2 -2 -2];    h.LineWidth = 3;    h.MarkerSize = 8;    pause(0.01);savegif('dot');end
View Code

生成的gif图

 

 

 

转载于:https://www.cnblogs.com/yanhc/p/11061442.html

你可能感兴趣的文章
rsync常见问题及解决办法
查看>>
MySQL日期 专题
查看>>
C#中禁止程序多开
查看>>
分布式缓存Redis使用以及原理
查看>>
Activity竟然有两个onCreate方法,可别用错了
查看>>
Linux经常使用命令(十六) - whereis
查看>>
Linux五种IO模型
查看>>
Bootstrap技术: 模式对话框的使用
查看>>
小知识,用myeclipes找jar
查看>>
in-list expansion
查看>>
设计原则(四):接口隔离原则
查看>>
基于react的滑动图片验证码组件
查看>>
java单例模式深度解析
查看>>
【学习笔记】阿里云Centos7.4下配置Nginx
查看>>
VuePress手把手一小時快速踩坑
查看>>
学习constructor和instanceof的区别
查看>>
Vijos P1881 闪烁的星星
查看>>
ABP理论学习之领域服务
查看>>
Qt 控制watchdog app hacking
查看>>
让所有IE支持HTML5的解决方案
查看>>