Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
hilbert.c
Package: leda.tar.gz [view]
Upload User: gzelex
Upload Date: 2007-01-07
Package Size: 707k
Code Size: 1k
Category:
Mathimatics-Numerical algorithms
Development Platform:
MultiPlatform
- #include <LEDA/window.h>
- window W;
- double x, y, dx, dy;
- void A(int);
- void B(int);
- void C(int);
- void D(int);
- void plot(double new_x, double new_y)
- { W.draw_segment(x,y,new_x,new_y);
- x = new_x;
- y = new_y;
- }
- void A(int i)
- {
- if (i > 0)
- { D(i-1); plot(x-dx,y);
- A(i-1); plot(x,y-dy);
- A(i-1); plot(x+dx,y);
- B(i-1);
- }
- }
- void B(int i)
- {
- if (i > 0)
- { C(i-1); plot(x,y+dy);
- B(i-1); plot(x+dx,y);
- B(i-1); plot(x,y-dy);
- A(i-1);
- }
- }
- void C(int i)
- {
- if (i > 0)
- { B(i-1); plot(x+dx,y);
- C(i-1); plot(x,y+dy);
- C(i-1); plot(x-dx,y);
- D(i-1);
- }
- }
- void D(int i)
- {
- if (i > 0)
- { A(i-1); plot(x,y-dy);
- D(i-1); plot(x-dx,y);
- D(i-1); plot(x,y+dy);
- C(i-1);
- }
- }
- int n = 5;
- void hilbert()
- {
- double lx = W.xmax() - W.xmin();
- double ly = W.ymax() - W.ymin();
- double x0 = W.xmin() + 0.98*lx;
- double y0 = W.ymin() + 0.98*ly;
- dx = 0.96 * lx/(1 << n);
- dy = 0.96 * ly/(1 << n);
- x = x0;
- y = y0;
- A(n);
- W.draw_segment(x0,y0,x0+dx,y0);
- W.draw_segment(x0+dx,y0,x0+dx,y);
- W.draw_segment(x0+dx,y,x,y);
- }
- main()
- {
- panel P("hilbert curve");
- P.int_item("n = ",n,1,10);
- W.set_redraw(hilbert);
- for(;;)
- { P.open();
- W.clear();
- hilbert();
- W.read_mouse();
- }
- return 0;
- }