Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,23 +0,0 @@
|
|||
-- FILE: dragon_curve.gpr --
|
||||
with "gtkada";
|
||||
|
||||
project Dragon_Curve is
|
||||
Adaflags := External_As_List ("ADAFLAGS", " ");
|
||||
Ldflags := External_As_List ("LDFLAGS", " ");
|
||||
|
||||
for Languages use ("Ada");
|
||||
for Main use ("dragon_curve.adb");
|
||||
for Source_Dirs use ("./");
|
||||
for Object_Dir use "obj/";
|
||||
for Exec_Dir use ".";
|
||||
|
||||
package Compiler is
|
||||
for Switches ("Ada") use ("-g", "-O0", "-gnaty-s", "-gnatwJ")
|
||||
& Adaflags;
|
||||
end Compiler;
|
||||
|
||||
package Linker is
|
||||
for Leading_Switches ("Ada") use Ldflags;
|
||||
end Linker;
|
||||
|
||||
end Dragon_Curve;
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
-- FILE: dragon_curve.adb --
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Events; use Events;
|
||||
with GLib.Main; use GLib.Main;
|
||||
with GTK;
|
||||
with GTK.Drawing_Area; use GTK.Drawing_Area;
|
||||
with GTK.Main;
|
||||
with GTK.Window; use GTK.Window;
|
||||
|
||||
procedure Dragon_Curve is
|
||||
Window : GTK_Window;
|
||||
begin
|
||||
GTK.Main.Init;
|
||||
GTK_New (Window);
|
||||
GTK_New (Drawing_Area);
|
||||
Window.Add (Drawing_Area);
|
||||
Drawing_Area.On_Draw (Events.Draw'Access, Drawing_Area);
|
||||
Show_All (Window);
|
||||
Resize (Window, 800, 800);
|
||||
GTK.Main.Main;
|
||||
end Dragon_Curve;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
-- FILE: events.ads --
|
||||
with Ada.Numerics.Generic_Elementary_Functions;
|
||||
with Cairo;
|
||||
with GLib; use Glib;
|
||||
with GTK.Drawing_Area; use GTK.Drawing_Area;
|
||||
with GTK.Widget; use GTK.Widget;
|
||||
with GLib.Object; use GLib.Object;
|
||||
|
||||
package Events is
|
||||
Drawing_Area : GTK_Drawing_Area;
|
||||
|
||||
package GDouble_Elementary_Functions is new Ada.Numerics.Generic_Elementary_Functions (Float);
|
||||
use GDouble_Elementary_Functions;
|
||||
|
||||
function Draw (Self : access GObject_Record'Class;
|
||||
CC : Cairo.Cairo_Context)
|
||||
return Boolean;
|
||||
end Events;
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
-- FILE: events.adb --
|
||||
with Cairo;
|
||||
with GTK;
|
||||
|
||||
package body Events is
|
||||
function Draw (Self : access GObject_Record'Class;
|
||||
CC : Cairo.Cairo_Context)
|
||||
return Boolean
|
||||
is
|
||||
type Rotate_Type is (Counterclockwise, Clockwise);
|
||||
|
||||
type Point is record
|
||||
X, Y : GDouble;
|
||||
end record;
|
||||
|
||||
procedure Heighway_Branch (CC : Cairo.Cairo_Context;
|
||||
A, B : Point;
|
||||
Rotate : Rotate_Type;
|
||||
N : Natural)
|
||||
is
|
||||
R, RU, C : Point;
|
||||
begin
|
||||
if N = 0 then
|
||||
Cairo.Move_To (CC, A.X, A.Y);
|
||||
Cairo.Line_To (CC, B.X, B.Y);
|
||||
Cairo.Stroke (CC);
|
||||
else
|
||||
-- Rotate 45 degrees --
|
||||
case Rotate is
|
||||
when Clockwise =>
|
||||
R.X := GDouble ((1.0 / Sqrt (2.0)) * Float (B.X - A.X)
|
||||
- (1.0 / Sqrt (2.0)) * Float (B.Y - A.Y));
|
||||
R.Y := GDouble ((1.0 / Sqrt (2.0)) * Float (B.X - A.X)
|
||||
+ (1.0 / Sqrt (2.0)) * Float (B.Y - A.Y));
|
||||
when Counterclockwise =>
|
||||
R.X := GDouble ((1.0 / Sqrt (2.0)) * Float (B.X - A.X)
|
||||
+ (1.0 / Sqrt (2.0)) * Float (B.Y - A.Y));
|
||||
R.Y := GDouble (-(1.0 / Sqrt (2.0)) * Float (B.X - A.X)
|
||||
+ (1.0 / Sqrt (2.0)) * Float (B.Y - A.Y));
|
||||
end case;
|
||||
|
||||
-- Make unit vector from rotation --
|
||||
RU.X := GDouble (Float (R.X) / Sqrt ( Float (R.X ** 2 + R.Y ** 2)));
|
||||
RU.Y := GDouble (Float (R.Y) / Sqrt ( Float (R.X ** 2 + R.Y ** 2)));
|
||||
|
||||
-- Scale --
|
||||
R.X := RU.X * GDouble (Sqrt (Float (B.X - A.X) ** 2 + Float (B.Y - A.Y) ** 2) / Sqrt (2.0));
|
||||
R.Y := RU.Y * GDouble (Sqrt (Float (B.X - A.X) ** 2 + Float (B.Y - A.Y) ** 2) / Sqrt (2.0));
|
||||
|
||||
C := (R.X + A.X, R.Y + A.Y);
|
||||
|
||||
Heighway_Branch (CC, A, C, Clockwise, N - 1);
|
||||
Heighway_Branch (CC, C, B, Counterclockwise, N - 1);
|
||||
end if;
|
||||
end Heighway_Branch;
|
||||
|
||||
Depth : constant := 14;
|
||||
Center, Right, Bottom, Left: Point;
|
||||
Width : GDouble := GDouble (Drawing_Area.Get_Allocated_Width);
|
||||
Height : GDouble := GDouble (Drawing_Area.Get_Allocated_Height);
|
||||
|
||||
begin
|
||||
Center := (Width / 2.0, Height / 2.0);
|
||||
Right := (Width, Height / 2.0);
|
||||
Left := (0.0, Height / 2.0);
|
||||
Bottom := (Width / 2.0, Height);
|
||||
|
||||
Cairo.Set_Source_RGB (CC, 0.0, 1.0, 0.0);
|
||||
Heighway_Branch (CC, Center, Right, Clockwise, Depth);
|
||||
Cairo.Set_Source_RGB (CC, 0.0, 1.0, 1.0);
|
||||
Heighway_Branch (CC, Center, Left, Clockwise, Depth);
|
||||
Cairo.Set_Source_RGB (CC, 0.0, 1.0, 0.5);
|
||||
Heighway_Branch (CC, Center, Bottom, Clockwise, Depth);
|
||||
|
||||
return True;
|
||||
end Draw;
|
||||
end Events;
|
||||
|
|
@ -12,11 +12,11 @@ SUB dragon (length AS Double, split AS Integer, d AS Double)
|
|||
IF split=0 THEN
|
||||
forward length
|
||||
ELSE
|
||||
turn d*45
|
||||
dragon length/1.4142136, split-1, 1
|
||||
turn -d*90
|
||||
dragon length/1.4142136, split-1, -1
|
||||
turn d*45
|
||||
turn d*45
|
||||
dragon length/1.4142136, split-1, 1
|
||||
turn -d*90
|
||||
dragon length/1.4142136, split-1, -1
|
||||
turn d*45
|
||||
END IF
|
||||
END SUB
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
graphsize 390,270
|
||||
|
||||
level = 18 : insize = 247 # initial values
|
||||
x = 92 : y = 94 #
|
||||
level = 18 : insize = 247 # initial values
|
||||
x = 92 : y = 94 #
|
||||
|
||||
iters = 2^level # total number of iterations
|
||||
qiter = 510/iters # constant for computing colors
|
||||
SQ = sqrt(2) : QPI = pi/4 # constants
|
||||
iters = 2^level # total number of iterations
|
||||
qiter = 510/iters # constant for computing colors
|
||||
SQ = sqrt(2) : QPI = pi/4 # constants
|
||||
|
||||
rotation = 0 : iter = 0 : rq = 1.0 # state variables
|
||||
dim rqs(level) # stack for rq (rotation coefficient)
|
||||
rotation = 0 : iter = 0 : rq = 1.0 # state variables
|
||||
dim rqs(level) # stack for rq (rotation coefficient)
|
||||
|
||||
color white
|
||||
fastgraphics
|
||||
|
|
@ -22,29 +22,29 @@ imgsave "Dragon_curve_BASIC-256.png", "PNG"
|
|||
end
|
||||
|
||||
dragon:
|
||||
if level<=0 then
|
||||
yn = sin(rotation)*insize + y
|
||||
xn = cos(rotation)*insize + x
|
||||
if iter*2<iters then
|
||||
color 0,iter*qiter,255-iter*qiter
|
||||
else
|
||||
color qiter*iter-255,(iters-iter)*qiter,0
|
||||
end if
|
||||
line x,y,xn,yn
|
||||
iter = iter + 1
|
||||
x = xn : y = yn
|
||||
return
|
||||
end if
|
||||
insize = insize/SQ
|
||||
rotation = rotation + rq*QPI
|
||||
level = level - 1
|
||||
rqs[level] = rq : rq = 1
|
||||
gosub dragon
|
||||
rotation = rotation - rqs[level]*QPI*2
|
||||
rq = -1
|
||||
gosub dragon
|
||||
rq = rqs[level]
|
||||
rotation = rotation + rq*QPI
|
||||
level = level + 1
|
||||
insize = insize*SQ
|
||||
return
|
||||
if level<=0 then
|
||||
yn = sin(rotation)*insize + y
|
||||
xn = cos(rotation)*insize + x
|
||||
if iter*2<iters then
|
||||
color 0,iter*qiter,255-iter*qiter
|
||||
else
|
||||
color qiter*iter-255,(iters-iter)*qiter,0
|
||||
end if
|
||||
line x,y,xn,yn
|
||||
iter = iter + 1
|
||||
x = xn : y = yn
|
||||
return
|
||||
end if
|
||||
insize = insize/SQ
|
||||
rotation = rotation + rq*QPI
|
||||
level = level - 1
|
||||
rqs[level] = rq : rq = 1
|
||||
gosub dragon
|
||||
rotation = rotation - rqs[level]*QPI*2
|
||||
rq = -1
|
||||
gosub dragon
|
||||
rq = rqs[level]
|
||||
rotation = rotation + rq*QPI
|
||||
level = level + 1
|
||||
insize = insize*SQ
|
||||
return
|
||||
|
|
|
|||
|
|
@ -14,90 +14,90 @@ public:
|
|||
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
|
||||
~myBitmap()
|
||||
{
|
||||
DeleteObject( pen ); DeleteObject( brush );
|
||||
DeleteDC( hdc ); DeleteObject( bmp );
|
||||
DeleteObject( pen ); DeleteObject( brush );
|
||||
DeleteDC( hdc ); DeleteObject( bmp );
|
||||
}
|
||||
|
||||
bool create( int w, int h )
|
||||
{
|
||||
BITMAPINFO bi;
|
||||
ZeroMemory( &bi, sizeof( bi ) );
|
||||
bi.bmiHeader.biSize = sizeof( bi.bmiHeader );
|
||||
bi.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
bi.bmiHeader.biCompression = BI_RGB;
|
||||
bi.bmiHeader.biPlanes = 1;
|
||||
bi.bmiHeader.biWidth = w;
|
||||
bi.bmiHeader.biHeight = -h;
|
||||
BITMAPINFO bi;
|
||||
ZeroMemory( &bi, sizeof( bi ) );
|
||||
bi.bmiHeader.biSize = sizeof( bi.bmiHeader );
|
||||
bi.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
bi.bmiHeader.biCompression = BI_RGB;
|
||||
bi.bmiHeader.biPlanes = 1;
|
||||
bi.bmiHeader.biWidth = w;
|
||||
bi.bmiHeader.biHeight = -h;
|
||||
|
||||
HDC dc = GetDC( GetConsoleWindow() );
|
||||
bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 );
|
||||
if( !bmp ) return false;
|
||||
HDC dc = GetDC( GetConsoleWindow() );
|
||||
bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 );
|
||||
if( !bmp ) return false;
|
||||
|
||||
hdc = CreateCompatibleDC( dc );
|
||||
SelectObject( hdc, bmp );
|
||||
ReleaseDC( GetConsoleWindow(), dc );
|
||||
hdc = CreateCompatibleDC( dc );
|
||||
SelectObject( hdc, bmp );
|
||||
ReleaseDC( GetConsoleWindow(), dc );
|
||||
|
||||
width = w; height = h;
|
||||
return true;
|
||||
width = w; height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
void clear( BYTE clr = 0 )
|
||||
{
|
||||
memset( pBits, clr, width * height * sizeof( DWORD ) );
|
||||
memset( pBits, clr, width * height * sizeof( DWORD ) );
|
||||
}
|
||||
|
||||
void setBrushColor( DWORD bClr )
|
||||
{
|
||||
if( brush ) DeleteObject( brush );
|
||||
brush = CreateSolidBrush( bClr );
|
||||
SelectObject( hdc, brush );
|
||||
if( brush ) DeleteObject( brush );
|
||||
brush = CreateSolidBrush( bClr );
|
||||
SelectObject( hdc, brush );
|
||||
}
|
||||
|
||||
void setPenColor( DWORD c )
|
||||
{
|
||||
clr = c; createPen();
|
||||
clr = c; createPen();
|
||||
}
|
||||
|
||||
void setPenWidth( int w )
|
||||
{
|
||||
wid = w; createPen();
|
||||
wid = w; createPen();
|
||||
}
|
||||
|
||||
void saveBitmap( string path )
|
||||
{
|
||||
BITMAPFILEHEADER fileheader;
|
||||
BITMAPINFO infoheader;
|
||||
BITMAP bitmap;
|
||||
DWORD wb;
|
||||
BITMAPFILEHEADER fileheader;
|
||||
BITMAPINFO infoheader;
|
||||
BITMAP bitmap;
|
||||
DWORD wb;
|
||||
|
||||
GetObject( bmp, sizeof( bitmap ), &bitmap );
|
||||
DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight];
|
||||
GetObject( bmp, sizeof( bitmap ), &bitmap );
|
||||
DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight];
|
||||
|
||||
ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );
|
||||
ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );
|
||||
ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) );
|
||||
ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );
|
||||
ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );
|
||||
ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) );
|
||||
|
||||
infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
infoheader.bmiHeader.biCompression = BI_RGB;
|
||||
infoheader.bmiHeader.biPlanes = 1;
|
||||
infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader );
|
||||
infoheader.bmiHeader.biHeight = bitmap.bmHeight;
|
||||
infoheader.bmiHeader.biWidth = bitmap.bmWidth;
|
||||
infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD );
|
||||
infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
infoheader.bmiHeader.biCompression = BI_RGB;
|
||||
infoheader.bmiHeader.biPlanes = 1;
|
||||
infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader );
|
||||
infoheader.bmiHeader.biHeight = bitmap.bmHeight;
|
||||
infoheader.bmiHeader.biWidth = bitmap.bmWidth;
|
||||
infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD );
|
||||
|
||||
fileheader.bfType = 0x4D42;
|
||||
fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER );
|
||||
fileheader.bfSize = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage;
|
||||
fileheader.bfType = 0x4D42;
|
||||
fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER );
|
||||
fileheader.bfSize = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage;
|
||||
|
||||
GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS );
|
||||
GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS );
|
||||
|
||||
HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );
|
||||
WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );
|
||||
WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL );
|
||||
CloseHandle( file );
|
||||
HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );
|
||||
WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );
|
||||
WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL );
|
||||
CloseHandle( file );
|
||||
|
||||
delete [] dwpBits;
|
||||
delete [] dwpBits;
|
||||
}
|
||||
|
||||
HDC getDC() const { return hdc; }
|
||||
|
|
@ -107,9 +107,9 @@ public:
|
|||
private:
|
||||
void createPen()
|
||||
{
|
||||
if( pen ) DeleteObject( pen );
|
||||
pen = CreatePen( PS_SOLID, wid, clr );
|
||||
SelectObject( hdc, pen );
|
||||
if( pen ) DeleteObject( pen );
|
||||
pen = CreatePen( PS_SOLID, wid, clr );
|
||||
SelectObject( hdc, pen );
|
||||
}
|
||||
|
||||
HBITMAP bmp;
|
||||
|
|
@ -130,58 +130,58 @@ public:
|
|||
private:
|
||||
void generate( int it )
|
||||
{
|
||||
generator.push_back( 1 );
|
||||
string temp;
|
||||
generator.push_back( 1 );
|
||||
string temp;
|
||||
|
||||
for( int y = 0; y < it - 1; y++ )
|
||||
{
|
||||
temp = generator; temp.push_back( 1 );
|
||||
for( string::reverse_iterator x = generator.rbegin(); x != generator.rend(); x++ )
|
||||
temp.push_back( !( *x ) );
|
||||
for( int y = 0; y < it - 1; y++ )
|
||||
{
|
||||
temp = generator; temp.push_back( 1 );
|
||||
for( string::reverse_iterator x = generator.rbegin(); x != generator.rend(); x++ )
|
||||
temp.push_back( !( *x ) );
|
||||
|
||||
generator = temp;
|
||||
}
|
||||
generator = temp;
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
HDC dc = bmp.getDC();
|
||||
unsigned int clr[] = { 0xff, 0xff00, 0xff0000, 0x00ffff };
|
||||
int mov[] = { 0, 0, 1, -1, 1, -1, 1, 0 }; int i = 0;
|
||||
HDC dc = bmp.getDC();
|
||||
unsigned int clr[] = { 0xff, 0xff00, 0xff0000, 0x00ffff };
|
||||
int mov[] = { 0, 0, 1, -1, 1, -1, 1, 0 }; int i = 0;
|
||||
|
||||
for( int t = 0; t < 4; t++ )
|
||||
{
|
||||
int a = BMP_SIZE / 2, b = a; a += mov[i++]; b += mov[i++];
|
||||
MoveToEx( dc, a, b, NULL );
|
||||
for( int t = 0; t < 4; t++ )
|
||||
{
|
||||
int a = BMP_SIZE / 2, b = a; a += mov[i++]; b += mov[i++];
|
||||
MoveToEx( dc, a, b, NULL );
|
||||
|
||||
bmp.setPenColor( clr[t] );
|
||||
for( string::iterator x = generator.begin(); x < generator.end(); x++ )
|
||||
{
|
||||
switch( dir )
|
||||
{
|
||||
case NORTH:
|
||||
if( *x ) { a += LEN; dir = EAST; }
|
||||
else { a -= LEN; dir = WEST; }
|
||||
break;
|
||||
case EAST:
|
||||
if( *x ) { b += LEN; dir = SOUTH; }
|
||||
else { b -= LEN; dir = NORTH; }
|
||||
break;
|
||||
case SOUTH:
|
||||
if( *x ) { a -= LEN; dir = WEST; }
|
||||
else { a += LEN; dir = EAST; }
|
||||
break;
|
||||
case WEST:
|
||||
if( *x ) { b -= LEN; dir = NORTH; }
|
||||
else { b += LEN; dir = SOUTH; }
|
||||
}
|
||||
LineTo( dc, a, b );
|
||||
}
|
||||
}
|
||||
// !!! change this path !!!
|
||||
bmp.saveBitmap( "f:/rc/dragonCpp.bmp" );
|
||||
bmp.setPenColor( clr[t] );
|
||||
for( string::iterator x = generator.begin(); x < generator.end(); x++ )
|
||||
{
|
||||
switch( dir )
|
||||
{
|
||||
case NORTH:
|
||||
if( *x ) { a += LEN; dir = EAST; }
|
||||
else { a -= LEN; dir = WEST; }
|
||||
break;
|
||||
case EAST:
|
||||
if( *x ) { b += LEN; dir = SOUTH; }
|
||||
else { b -= LEN; dir = NORTH; }
|
||||
break;
|
||||
case SOUTH:
|
||||
if( *x ) { a -= LEN; dir = WEST; }
|
||||
else { a += LEN; dir = EAST; }
|
||||
break;
|
||||
case WEST:
|
||||
if( *x ) { b -= LEN; dir = NORTH; }
|
||||
else { b += LEN; dir = SOUTH; }
|
||||
}
|
||||
LineTo( dc, a, b );
|
||||
}
|
||||
}
|
||||
|
||||
// !!! change this path !!!
|
||||
bmp.saveBitmap( "f:/rc/dragonCpp.bmp" );
|
||||
}
|
||||
|
||||
int dir;
|
||||
myBitmap bmp;
|
||||
string generator;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ rgb ** pix;
|
|||
*/
|
||||
void sc_up()
|
||||
{
|
||||
long long tmp = dx - dy; dy = dx + dy; dx = tmp;
|
||||
scale *= 2; x *= 2; y *= 2;
|
||||
long long tmp = dx - dy; dy = dx + dy; dx = tmp;
|
||||
scale *= 2; x *= 2; y *= 2;
|
||||
}
|
||||
|
||||
/* Hue changes from 0 to 360 degrees over entire length of path; Value
|
||||
|
|
@ -29,23 +29,23 @@ void sc_up()
|
|||
*/
|
||||
void h_rgb(long long x, long long y)
|
||||
{
|
||||
rgb *p = &pix[y][x];
|
||||
rgb *p = &pix[y][x];
|
||||
|
||||
# define SAT 1
|
||||
double h = 6.0 * clen / scale;
|
||||
double VAL = 1 - (cos(3.141592653579 * 64 * clen / scale) - 1) / 4;
|
||||
double c = SAT * VAL;
|
||||
double X = c * (1 - fabs(fmod(h, 2) - 1));
|
||||
# define SAT 1
|
||||
double h = 6.0 * clen / scale;
|
||||
double VAL = 1 - (cos(3.141592653579 * 64 * clen / scale) - 1) / 4;
|
||||
double c = SAT * VAL;
|
||||
double X = c * (1 - fabs(fmod(h, 2) - 1));
|
||||
|
||||
switch((int)h) {
|
||||
case 0: p->r += c; p->g += X; return;
|
||||
case 1: p->r += X; p->g += c; return;
|
||||
case 2: p->g += c; p->b += X; return;
|
||||
case 3: p->g += X; p->b += c; return;
|
||||
case 4: p->r += X; p->b += c; return;
|
||||
default:
|
||||
p->r += c; p->b += X;
|
||||
}
|
||||
switch((int)h) {
|
||||
case 0: p->r += c; p->g += X; return;
|
||||
case 1: p->r += X; p->g += c; return;
|
||||
case 2: p->g += c; p->b += X; return;
|
||||
case 3: p->g += X; p->b += c; return;
|
||||
case 4: p->r += X; p->b += c; return;
|
||||
default:
|
||||
p->r += c; p->b += X;
|
||||
}
|
||||
}
|
||||
|
||||
/* string rewriting. No need to keep the string itself, just execute
|
||||
|
|
@ -53,16 +53,16 @@ void h_rgb(long long x, long long y)
|
|||
*/
|
||||
void iter_string(const char * str, int d)
|
||||
{
|
||||
long tmp;
|
||||
# define LEFT tmp = -dy; dy = dx; dx = tmp
|
||||
# define RIGHT tmp = dy; dy = -dx; dx = tmp
|
||||
while (*str != '\0') {
|
||||
switch(*(str++)) {
|
||||
case 'X': if (d) iter_string("X+YF+", d - 1); continue;
|
||||
case 'Y': if (d) iter_string("-FX-Y", d - 1); continue;
|
||||
case '+': RIGHT; continue;
|
||||
case '-': LEFT; continue;
|
||||
case 'F':
|
||||
long tmp;
|
||||
# define LEFT tmp = -dy; dy = dx; dx = tmp
|
||||
# define RIGHT tmp = dy; dy = -dx; dx = tmp
|
||||
while (*str != '\0') {
|
||||
switch(*(str++)) {
|
||||
case 'X': if (d) iter_string("X+YF+", d - 1); continue;
|
||||
case 'Y': if (d) iter_string("-FX-Y", d - 1); continue;
|
||||
case '+': RIGHT; continue;
|
||||
case '-': LEFT; continue;
|
||||
case 'F':
|
||||
/* draw: increment path length; add color; move. Here
|
||||
* is why the code does not allow user to choose arbitrary
|
||||
* image size: if it's not a power of two, aliasing will
|
||||
|
|
@ -71,59 +71,59 @@ void iter_string(const char * str, int d)
|
|||
* involves computing multiplicative order and would be a huge
|
||||
* bore.
|
||||
*/
|
||||
clen ++;
|
||||
h_rgb(x/scale, y/scale);
|
||||
x += dx; y += dy;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
clen ++;
|
||||
h_rgb(x/scale, y/scale);
|
||||
x += dx; y += dy;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dragon(long leng, int depth)
|
||||
{
|
||||
long i, d = leng / 3 + 1;
|
||||
long h = leng + 3, w = leng + d * 3 / 2 + 2;
|
||||
long i, d = leng / 3 + 1;
|
||||
long h = leng + 3, w = leng + d * 3 / 2 + 2;
|
||||
|
||||
/* allocate pixel buffer */
|
||||
rgb *buf = malloc(sizeof(rgb) * w * h);
|
||||
pix = malloc(sizeof(rgb *) * h);
|
||||
for (i = 0; i < h; i++)
|
||||
pix[i] = buf + w * i;
|
||||
memset(buf, 0, sizeof(rgb) * w * h);
|
||||
/* allocate pixel buffer */
|
||||
rgb *buf = malloc(sizeof(rgb) * w * h);
|
||||
pix = malloc(sizeof(rgb *) * h);
|
||||
for (i = 0; i < h; i++)
|
||||
pix[i] = buf + w * i;
|
||||
memset(buf, 0, sizeof(rgb) * w * h);
|
||||
|
||||
/* init coords; scale up to desired; exec string */
|
||||
x = y = d; dx = leng; dy = 0; scale = 1; clen = 0;
|
||||
for (i = 0; i < depth; i++) sc_up();
|
||||
iter_string("FX", depth);
|
||||
x = y = d; dx = leng; dy = 0; scale = 1; clen = 0;
|
||||
for (i = 0; i < depth; i++) sc_up();
|
||||
iter_string("FX", depth);
|
||||
|
||||
/* write color PNM file */
|
||||
unsigned char *fpix = malloc(w * h * 3);
|
||||
double maxv = 0, *dbuf = (double*)buf;
|
||||
/* write color PNM file */
|
||||
unsigned char *fpix = malloc(w * h * 3);
|
||||
double maxv = 0, *dbuf = (double*)buf;
|
||||
|
||||
/* find highest value among pixels; normalize image according
|
||||
* to it. Highest value would be at points most travelled, so
|
||||
* this ends up giving curve edge a nice fade -- it's more apparaent
|
||||
* if we increase iteration depth by one or two.
|
||||
*/
|
||||
for (i = 3 * w * h - 1; i >= 0; i--)
|
||||
if (dbuf[i] > maxv) maxv = dbuf[i];
|
||||
for (i = 3 * h * w - 1; i >= 0; i--)
|
||||
fpix[i] = 255 * dbuf[i] / maxv;
|
||||
for (i = 3 * w * h - 1; i >= 0; i--)
|
||||
if (dbuf[i] > maxv) maxv = dbuf[i];
|
||||
for (i = 3 * h * w - 1; i >= 0; i--)
|
||||
fpix[i] = 255 * dbuf[i] / maxv;
|
||||
|
||||
printf("P6\n%ld %ld\n255\n", w, h);
|
||||
fflush(stdout); /* printf and fwrite may treat buffer differently */
|
||||
fwrite(fpix, h * w * 3, 1, stdout);
|
||||
printf("P6\n%ld %ld\n255\n", w, h);
|
||||
fflush(stdout); /* printf and fwrite may treat buffer differently */
|
||||
fwrite(fpix, h * w * 3, 1, stdout);
|
||||
}
|
||||
|
||||
int main(int c, char ** v)
|
||||
{
|
||||
int size, depth;
|
||||
int size, depth;
|
||||
|
||||
depth = (c > 1) ? atoi(v[1]) : 10;
|
||||
size = 1 << depth;
|
||||
depth = (c > 1) ? atoi(v[1]) : 10;
|
||||
size = 1 << depth;
|
||||
|
||||
fprintf(stderr, "size: %d depth: %d\n", size, depth);
|
||||
dragon(size, depth * 2);
|
||||
fprintf(stderr, "size: %d depth: %d\n", size, depth);
|
||||
dragon(size, depth * 2);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,173 +0,0 @@
|
|||
>>SOURCE FORMAT FREE
|
||||
*> This code is dedicated to the public domain
|
||||
identification division.
|
||||
program-id. dragon.
|
||||
environment division.
|
||||
configuration section.
|
||||
repository. function all intrinsic.
|
||||
data division.
|
||||
working-storage section.
|
||||
01 segment-length pic 9 value 2.
|
||||
01 mark pic x value '.'.
|
||||
01 segment-count pic 9999 value 513.
|
||||
|
||||
01 segment pic 9999.
|
||||
01 point pic 9999 value 1.
|
||||
01 point-max pic 9999.
|
||||
01 point-lim pic 9999 value 8192.
|
||||
01 dragon-curve.
|
||||
03 filler occurs 8192.
|
||||
05 ydragon pic s9999.
|
||||
05 xdragon pic s9999.
|
||||
|
||||
01 x pic s9999 value 1.
|
||||
01 y pic S9999 value 1.
|
||||
|
||||
01 xdelta pic s9 value 1. *> start pointing east
|
||||
01 ydelta pic s9 value 0.
|
||||
|
||||
01 x-max pic s9999 value -9999.
|
||||
01 x-min pic s9999 value 9999.
|
||||
01 y-max pic s9999 value -9999.
|
||||
01 y-min pic s9999 value 9999.
|
||||
|
||||
01 n pic 9999.
|
||||
01 r pic 9.
|
||||
|
||||
01 xupper pic s9999.
|
||||
01 yupper pic s9999.
|
||||
|
||||
01 window-line-number pic 99.
|
||||
01 window-width pic 99 value 64.
|
||||
01 window-height pic 99 value 22.
|
||||
01 window.
|
||||
03 window-line occurs 22.
|
||||
05 window-point occurs 64 pic x.
|
||||
|
||||
01 direction pic x.
|
||||
|
||||
procedure division.
|
||||
start-dragon.
|
||||
|
||||
if segment-count * segment-length > point-lim
|
||||
*> too many segments for the point-table
|
||||
compute segment-count = point-lim / segment-length
|
||||
end-if
|
||||
|
||||
perform varying segment from 1 by 1
|
||||
until segment > segment-count
|
||||
|
||||
*>===========================================
|
||||
*> segment = n * 2 ** b
|
||||
*> if mod(n,4) = 3, turn left else turn right
|
||||
*>===========================================
|
||||
|
||||
*> calculate the turn
|
||||
divide 2 into segment giving n remainder r
|
||||
perform until r <> 0
|
||||
divide 2 into n giving n remainder r
|
||||
end-perform
|
||||
divide 2 into n giving n remainder r
|
||||
|
||||
*> perform the turn
|
||||
evaluate r also xdelta also ydelta
|
||||
when 0 also 1 also 0 *> turn right from east
|
||||
when 1 also -1 also 0 *> turn left from west
|
||||
*> turn to south
|
||||
move 0 to xdelta
|
||||
move 1 to ydelta
|
||||
when 1 also 1 also 0 *> turn left from east
|
||||
when 0 also -1 also 0 *> turn right from west
|
||||
*> turn to north
|
||||
move 0 to xdelta
|
||||
move -1 to ydelta
|
||||
when 0 also 0 also 1 *> turn right from south
|
||||
when 1 also 0 also -1 *> turn left from north
|
||||
*> turn to west
|
||||
move 0 to ydelta
|
||||
move -1 to xdelta
|
||||
when 1 also 0 also 1 *> turn left from south
|
||||
when 0 also 0 also -1 *> turn right from north
|
||||
*> turn to east
|
||||
move 0 to ydelta
|
||||
move 1 to xdelta
|
||||
end-evaluate
|
||||
|
||||
*> plot the segment points
|
||||
perform segment-length times
|
||||
add xdelta to x
|
||||
add ydelta to y
|
||||
|
||||
move x to xdragon(point)
|
||||
move y to ydragon(point)
|
||||
|
||||
add 1 to point
|
||||
end-perform
|
||||
|
||||
*> update the limits for the display
|
||||
compute x-max = max(x, x-max)
|
||||
compute x-min = min(x, x-min)
|
||||
compute y-max = max(y, y-max)
|
||||
compute y-min = min(y, y-min)
|
||||
move point to point-max
|
||||
|
||||
end-perform
|
||||
|
||||
*>==========================================
|
||||
*> display the curve
|
||||
*> hjkl corresponds to left, up, down, right
|
||||
*> anything else ends the program
|
||||
*>==========================================
|
||||
|
||||
move 1 to yupper xupper
|
||||
|
||||
perform with test after
|
||||
until direction <> 'h' and 'j' and 'k' and 'l'
|
||||
|
||||
*>==========================================
|
||||
*> (yupper,xupper) maps to window-point(1,1)
|
||||
*>==========================================
|
||||
|
||||
*> move the window
|
||||
evaluate true
|
||||
when direction = 'h' *> move window left
|
||||
and xupper > x-min + window-width
|
||||
subtract 1 from xupper
|
||||
when direction = 'j' *> move window up
|
||||
and yupper < y-max - window-height
|
||||
add 1 to yupper
|
||||
when direction = 'k' *> move window down
|
||||
and yupper > y-min + window-height
|
||||
subtract 1 from yupper
|
||||
when direction = 'l' *> move window right
|
||||
and xupper < x-max - window-width
|
||||
add 1 to xupper
|
||||
end-evaluate
|
||||
|
||||
*> plot the dragon points in the window
|
||||
move spaces to window
|
||||
perform varying point from 1 by 1
|
||||
until point > point-max
|
||||
if ydragon(point) >= yupper and < yupper + window-height
|
||||
and xdragon(point) >= xupper and < xupper + window-width
|
||||
*> we're in the window
|
||||
compute y = ydragon(point) - yupper + 1
|
||||
compute x = xdragon(point) - xupper + 1
|
||||
move mark to window-point(y, x)
|
||||
end-if
|
||||
end-perform
|
||||
|
||||
*> display the window
|
||||
perform varying window-line-number from 1 by 1
|
||||
until window-line-number > window-height
|
||||
display window-line(window-line-number)
|
||||
end-perform
|
||||
|
||||
*> get the next window move or terminate
|
||||
display 'hjkl?' with no advancing
|
||||
accept direction
|
||||
end-perform
|
||||
|
||||
stop run
|
||||
.
|
||||
end program dragon.
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
(defun dragon-ensure-line-above ()
|
||||
"If point is in the first line of the buffer then insert a new line above."
|
||||
(when (= (line-beginning-position) (point-min))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(insert "\n"))))
|
||||
|
||||
(defun dragon-ensure-column-left ()
|
||||
"If point is in the first column then insert a new column to the left.
|
||||
This is designed for use in `picture-mode'."
|
||||
(when (zerop (current-column))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(insert " ")
|
||||
(while (= 0 (forward-line 1))
|
||||
(insert " ")))
|
||||
(picture-forward-column 1)))
|
||||
|
||||
(defun dragon-insert-char (char len)
|
||||
"Insert CHAR repeated LEN many times.
|
||||
After each CHAR point move in the current `picture-mode'
|
||||
direction (per `picture-set-motion' etc).
|
||||
|
||||
This is the same as `picture-insert' except in column 0 or row 0
|
||||
a new row or column is inserted to make room, with existing
|
||||
buffer contents shifted down or right."
|
||||
|
||||
(dotimes (i len)
|
||||
(dragon-ensure-line-above)
|
||||
(dragon-ensure-column-left)
|
||||
(picture-insert char 1)))
|
||||
|
||||
(defun dragon-bit-above-lowest-0bit (n)
|
||||
"Return the bit above the lowest 0-bit in N.
|
||||
For example N=43 binary \"101011\" has lowest 0-bit at \"...0..\"
|
||||
and the bit above that is \"..1...\" so return 8 which is that
|
||||
bit."
|
||||
(logand n (1+ (logxor n (1+ n)))))
|
||||
|
||||
(defun dragon-next-turn-right-p (n)
|
||||
"Return non-nil if the dragon curve should turn right after segment N.
|
||||
Segments are numbered from N=0 for the first, so calling with N=0
|
||||
is whether to turn right after drawing that N=0 segment."
|
||||
(zerop (dragon-bit-above-lowest-0bit n)))
|
||||
|
||||
(defun dragon-picture (len step)
|
||||
"Draw the dragon curve in a *dragon* buffer.
|
||||
LEN is the number of segments of the curve to draw.
|
||||
STEP is the length of each segment, in characters.
|
||||
|
||||
Any LEN can be given but a power-of-2 such as 256 shows the
|
||||
self-similar nature of the curve.
|
||||
|
||||
If STEP >= 2 then the segments are lines using \"-\" or \"|\"
|
||||
characters (`picture-rectangle-h' and `picture-rectangle-v').
|
||||
If STEP=1 then only \"+\" corners.
|
||||
|
||||
There's a `sit-for' delay in the drawing loop to draw the curve
|
||||
progressively on screen."
|
||||
|
||||
(interactive (list (read-number "Length of curve " 256)
|
||||
(read-number "Each step size " 3)))
|
||||
(unless (>= step 1)
|
||||
(error "Step length must be >= 1"))
|
||||
|
||||
(switch-to-buffer "*dragon*")
|
||||
(erase-buffer)
|
||||
(ignore-errors ;; if already in picture-mode
|
||||
(picture-mode))
|
||||
|
||||
(dotimes (n len) ;; n=0 to len-1, inclusive
|
||||
(dragon-insert-char ?+ 1) ;; corner char
|
||||
(dragon-insert-char (if (zerop picture-vertical-step)
|
||||
picture-rectangle-h picture-rectangle-v)
|
||||
(1- step)) ;; line chars
|
||||
|
||||
(if (dragon-next-turn-right-p n)
|
||||
;; turn right
|
||||
(picture-set-motion (- picture-horizontal-step) picture-vertical-step)
|
||||
;; turn left
|
||||
(picture-set-motion picture-horizontal-step (- picture-vertical-step)))
|
||||
|
||||
;; delay to display the drawing progressively
|
||||
(sit-for .01))
|
||||
|
||||
(picture-insert ?+ 1) ;; endpoint
|
||||
(picture-mode-exit)
|
||||
(goto-char (point-min)))
|
||||
|
||||
(dragon-picture 128 2)
|
||||
|
|
@ -4,8 +4,8 @@ y 0 = ""
|
|||
y n = " - f"++(x$n-1)++" -"++(y$n-1)
|
||||
|
||||
dragon n =
|
||||
concat ["0 setlinewidth 300 400 moveto",
|
||||
"/f{2 0 rlineto}def/+{90 rotate}def/-{-90 rotate}def\n",
|
||||
"f", x n, " stroke showpage"]
|
||||
concat ["0 setlinewidth 300 400 moveto",
|
||||
"/f{2 0 rlineto}def/+{90 rotate}def/-{-90 rotate}def\n",
|
||||
"f", x n, " stroke showpage"]
|
||||
|
||||
main = putStrLn $ dragon 14
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ beginchar("D", 25pt#, 25pt#, 0pt#);
|
|||
for i = 1 upto dragoniter:
|
||||
for v = 1 step mstep until (2-mstep):
|
||||
if unknown z[v+mstep]:
|
||||
pair t;
|
||||
t := .7071[ z[v], z[v+2mstep] ];
|
||||
z[v+mstep] = t rotatedaround(z[v], 45sg);
|
||||
sg := -1*sg;
|
||||
pair t;
|
||||
t := .7071[ z[v], z[v+2mstep] ];
|
||||
z[v+mstep] = t rotatedaround(z[v], 45sg);
|
||||
sg := -1*sg;
|
||||
fi
|
||||
endfor
|
||||
mstep := mstep/2;
|
||||
|
|
|
|||
|
|
@ -1,60 +1,60 @@
|
|||
dragonCurve(N) :-
|
||||
dcg_dg(N, [left], DCL, []),
|
||||
Side = 4,
|
||||
Angle is -N * (pi/4),
|
||||
dcg_computePath(Side, Angle, DCL, point(180,400), P, []),
|
||||
new(D, window('Dragon Curve')),
|
||||
send(D, size, size(800,600)),
|
||||
new(Path, path(poly)),
|
||||
send_list(Path, append, P),
|
||||
send(D, display, Path),
|
||||
send(D, open).
|
||||
dcg_dg(N, [left], DCL, []),
|
||||
Side = 4,
|
||||
Angle is -N * (pi/4),
|
||||
dcg_computePath(Side, Angle, DCL, point(180,400), P, []),
|
||||
new(D, window('Dragon Curve')),
|
||||
send(D, size, size(800,600)),
|
||||
new(Path, path(poly)),
|
||||
send_list(Path, append, P),
|
||||
send(D, display, Path),
|
||||
send(D, open).
|
||||
|
||||
|
||||
% compute the list of points of the Dragon Curve
|
||||
dcg_computePath(Side, Angle, [left | DCT], point(X1, Y1)) -->
|
||||
[point(X1, Y1)],
|
||||
{ X2 is X1 + Side * cos(Angle),
|
||||
Y2 is Y1 + Side * sin(Angle),
|
||||
Angle1 is Angle + pi / 2
|
||||
},
|
||||
dcg_computePath(Side, Angle1, DCT, point(X2, Y2)).
|
||||
[point(X1, Y1)],
|
||||
{ X2 is X1 + Side * cos(Angle),
|
||||
Y2 is Y1 + Side * sin(Angle),
|
||||
Angle1 is Angle + pi / 2
|
||||
},
|
||||
dcg_computePath(Side, Angle1, DCT, point(X2, Y2)).
|
||||
|
||||
dcg_computePath(Side, Angle, [right | DCT], point(X1, Y1)) -->
|
||||
[point(X1, Y1)],
|
||||
{ X2 is X1 + Side * cos(Angle),
|
||||
Y2 is Y1 + Side * sin(Angle),
|
||||
Angle1 is Angle - pi / 2
|
||||
},
|
||||
dcg_computePath(Side, Angle1, DCT, point(X2, Y2)).
|
||||
[point(X1, Y1)],
|
||||
{ X2 is X1 + Side * cos(Angle),
|
||||
Y2 is Y1 + Side * sin(Angle),
|
||||
Angle1 is Angle - pi / 2
|
||||
},
|
||||
dcg_computePath(Side, Angle1, DCT, point(X2, Y2)).
|
||||
|
||||
|
||||
dcg_computePath(_Side, _Angle, [], point(X1, Y1)) -->
|
||||
[ point(X1, Y1)].
|
||||
[ point(X1, Y1)].
|
||||
|
||||
|
||||
% compute the list of the "turns" of the Dragon Curve
|
||||
dcg_dg(1, L) --> L.
|
||||
|
||||
dcg_dg(N, L) -->
|
||||
{dcg_dg(L, L1, []),
|
||||
N1 is N - 1},
|
||||
dcg_dg(N1, L1).
|
||||
{dcg_dg(L, L1, []),
|
||||
N1 is N - 1},
|
||||
dcg_dg(N1, L1).
|
||||
|
||||
% one interation of the process
|
||||
dcg_dg(L) -->
|
||||
L,
|
||||
[left],
|
||||
inverse(L).
|
||||
L,
|
||||
[left],
|
||||
inverse(L).
|
||||
|
||||
inverse([H | T]) -->
|
||||
inverse(T),
|
||||
inverse(H).
|
||||
inverse(T),
|
||||
inverse(H).
|
||||
|
||||
inverse([]) --> [].
|
||||
|
||||
inverse(left) -->
|
||||
[right].
|
||||
[right].
|
||||
|
||||
inverse(right) -->
|
||||
[left].
|
||||
[left].
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use SVG;
|
|||
role Lindenmayer {
|
||||
has %.rules;
|
||||
method succ {
|
||||
self.comb.map( { %!rules{$^c} // $c } ).join but Lindenmayer(%!rules)
|
||||
self.comb.map( { %!rules{$^c} // $c } ).join but Lindenmayer(%!rules)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,35 +4,35 @@ import <Utilities/Conversion.sl>;
|
|||
initPoints := [[0,0],[1,0]];
|
||||
|
||||
f1(point(1)) :=
|
||||
let
|
||||
matrix := [[cos(45 * (pi/180)), -sin(45 * (pi/180))],
|
||||
[sin(45 * (pi/180)), cos(45 * (pi/180))]];
|
||||
in
|
||||
head(transpose((1/sqrt(2)) * matmul(matrix, transpose([point]))));
|
||||
|
||||
let
|
||||
matrix := [[cos(45 * (pi/180)), -sin(45 * (pi/180))],
|
||||
[sin(45 * (pi/180)), cos(45 * (pi/180))]];
|
||||
in
|
||||
head(transpose((1/sqrt(2)) * matmul(matrix, transpose([point]))));
|
||||
|
||||
f2(point(1)) :=
|
||||
let
|
||||
matrix := [[cos(135 * (pi/180)), -sin(135 * (pi/180))],
|
||||
[sin(135 * (pi/180)), cos(135 * (pi/180))]];
|
||||
in
|
||||
head(transpose((1/sqrt(2)) * matmul(matrix, transpose([point])))) + initPoints[2];
|
||||
let
|
||||
matrix := [[cos(135 * (pi/180)), -sin(135 * (pi/180))],
|
||||
[sin(135 * (pi/180)), cos(135 * (pi/180))]];
|
||||
in
|
||||
head(transpose((1/sqrt(2)) * matmul(matrix, transpose([point])))) + initPoints[2];
|
||||
|
||||
matmul(X(2),Y(2))[i,j] := sum(X[i,all]*Y[all,j]);
|
||||
|
||||
entry(steps(0), maxX(0), maxY(0)) :=
|
||||
let
|
||||
scaleX := maxX / 1.5;
|
||||
scaleY := maxY;
|
||||
|
||||
shiftX := maxX / 3.0 / 1.5;
|
||||
shiftY := maxY / 3.0;
|
||||
in
|
||||
round(run(steps, initPoints) * [scaleX, scaleY] + [shiftX, shiftY]);
|
||||
let
|
||||
scaleX := maxX / 1.5;
|
||||
scaleY := maxY;
|
||||
|
||||
shiftX := maxX / 3.0 / 1.5;
|
||||
shiftY := maxY / 3.0;
|
||||
in
|
||||
round(run(steps, initPoints) * [scaleX, scaleY] + [shiftX, shiftY]);
|
||||
|
||||
run(steps(0), result(2)) :=
|
||||
let
|
||||
next := f1(result) ++ f2(result);
|
||||
in
|
||||
result when steps <= 0
|
||||
else
|
||||
run(steps - 1, next);
|
||||
let
|
||||
next := f1(result) ++ f2(result);
|
||||
in
|
||||
result when steps <= 0
|
||||
else
|
||||
run(steps - 1, next);
|
||||
|
|
|
|||
|
|
@ -9,66 +9,66 @@ using namespace std;
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int threads = 0;
|
||||
if(argc > 1) threads = atoi(argv[1]);
|
||||
Sequence< Sequence<int> > result;
|
||||
int threads = 0;
|
||||
if(argc > 1) threads = atoi(argv[1]);
|
||||
Sequence< Sequence<int> > result;
|
||||
|
||||
sl_init(threads);
|
||||
sl_init(threads);
|
||||
|
||||
int width = 500;
|
||||
if(argc > 2) width = atoi(argv[2]);
|
||||
int height = width;
|
||||
if(argc > 3) height = atoi(argv[3]);
|
||||
int width = 500;
|
||||
if(argc > 2) width = atoi(argv[2]);
|
||||
int height = width;
|
||||
if(argc > 3) height = atoi(argv[3]);
|
||||
|
||||
CImg<unsigned char> visu(width, height, 1, 3, 0);
|
||||
CImgDisplay draw_disp(visu);
|
||||
CImg<unsigned char> visu(width, height, 1, 3, 0);
|
||||
CImgDisplay draw_disp(visu);
|
||||
|
||||
SLTimer compTimer;
|
||||
SLTimer drawTimer;
|
||||
SLTimer compTimer;
|
||||
SLTimer drawTimer;
|
||||
|
||||
int steps = 0;
|
||||
int maxSteps = 18;
|
||||
if(argc > 4) maxSteps = atoi(argv[4]);
|
||||
int waitTime = 200;
|
||||
if(argc > 5) waitTime = atoi(argv[5]);
|
||||
bool adding = true;
|
||||
while(!draw_disp.is_closed())
|
||||
{
|
||||
compTimer.start();
|
||||
sl_entry(steps, width, height, threads, result);
|
||||
compTimer.stop();
|
||||
int steps = 0;
|
||||
int maxSteps = 18;
|
||||
if(argc > 4) maxSteps = atoi(argv[4]);
|
||||
int waitTime = 200;
|
||||
if(argc > 5) waitTime = atoi(argv[5]);
|
||||
bool adding = true;
|
||||
while(!draw_disp.is_closed())
|
||||
{
|
||||
compTimer.start();
|
||||
sl_entry(steps, width, height, threads, result);
|
||||
compTimer.stop();
|
||||
|
||||
drawTimer.start();
|
||||
visu.fill(0);
|
||||
drawTimer.start();
|
||||
visu.fill(0);
|
||||
|
||||
double thirdSize = ((result.size() / 2.0) / 3.0);
|
||||
thirdSize = (int)thirdSize == 0 ? 1 : thirdSize;
|
||||
double thirdSize = ((result.size() / 2.0) / 3.0);
|
||||
thirdSize = (int)thirdSize == 0 ? 1 : thirdSize;
|
||||
|
||||
for(int i = 1; i <= result.size(); i+=2)
|
||||
{
|
||||
unsigned char shade = (unsigned char)(255 * ((((i / 2) % (int)thirdSize) / thirdSize)) + 0.5);
|
||||
for(int i = 1; i <= result.size(); i+=2)
|
||||
{
|
||||
unsigned char shade = (unsigned char)(255 * ((((i / 2) % (int)thirdSize) / thirdSize)) + 0.5);
|
||||
|
||||
unsigned char r = i / 2 <= thirdSize ? shade : 255/2;
|
||||
unsigned char g = thirdSize < i / 2 && i / 2 <= thirdSize * 2 ? shade : 255/2;
|
||||
unsigned char b = thirdSize * 2 < i / 2 && i / 2 <= thirdSize * 3 ? shade : 255/2;
|
||||
const unsigned char color[] = {r,g,b};
|
||||
unsigned char r = i / 2 <= thirdSize ? shade : 255/2;
|
||||
unsigned char g = thirdSize < i / 2 && i / 2 <= thirdSize * 2 ? shade : 255/2;
|
||||
unsigned char b = thirdSize * 2 < i / 2 && i / 2 <= thirdSize * 3 ? shade : 255/2;
|
||||
const unsigned char color[] = {r,g,b};
|
||||
|
||||
visu.draw_line(result[i][1], result[i][2], 0, result[i + 1][1], result[i + 1][2], 0, color);
|
||||
}
|
||||
visu.display(draw_disp);
|
||||
drawTimer.stop();
|
||||
visu.draw_line(result[i][1], result[i][2], 0, result[i + 1][1], result[i + 1][2], 0, color);
|
||||
}
|
||||
visu.display(draw_disp);
|
||||
drawTimer.stop();
|
||||
|
||||
draw_disp.set_title("Dragon Curve in SequenceL: %d Threads | Steps: %d | CompTime: %f Seconds | Draw Time: %f Seconds", threads, steps, drawTimer.getTime(), compTimer.getTime());
|
||||
draw_disp.set_title("Dragon Curve in SequenceL: %d Threads | Steps: %d | CompTime: %f Seconds | Draw Time: %f Seconds", threads, steps, drawTimer.getTime(), compTimer.getTime());
|
||||
|
||||
if(adding) steps++;
|
||||
else steps--;
|
||||
if(adding) steps++;
|
||||
else steps--;
|
||||
|
||||
if(steps <= 0) adding = true;
|
||||
else if(steps >= maxSteps) adding = false;
|
||||
if(steps <= 0) adding = true;
|
||||
else if(steps >= maxSteps) adding = false;
|
||||
|
||||
draw_disp.wait(waitTime);
|
||||
}
|
||||
draw_disp.wait(waitTime);
|
||||
}
|
||||
|
||||
sl_done();
|
||||
return 0;
|
||||
sl_done();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ proc forward {len} {
|
|||
proc dragon {len split {d 1}} {
|
||||
global r2 coords
|
||||
if {$split == 0} {
|
||||
forward $len
|
||||
return
|
||||
forward $len
|
||||
return
|
||||
}
|
||||
|
||||
# This next part is only necessary to allow the illustration of progress
|
||||
if {$split == 10 && [llength $::coords]>2} {
|
||||
.c coords dragon $::coords
|
||||
update
|
||||
.c coords dragon $::coords
|
||||
update
|
||||
}
|
||||
|
||||
incr split -1
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
option explicit
|
||||
'outputs turtle graphics to svg file and opens it
|
||||
|
||||
const pi180= 0.01745329251994329576923690768489 ' pi/180
|
||||
const pi=3.1415926535897932384626433832795 'pi
|
||||
class turtle
|
||||
|
||||
dim fso
|
||||
dim fn
|
||||
dim svg
|
||||
|
||||
dim iang 'radians
|
||||
dim ori 'radians
|
||||
dim incr
|
||||
dim pdown
|
||||
dim clr
|
||||
dim x
|
||||
dim y
|
||||
|
||||
public property let orient(n):ori = n*pi180 :end property
|
||||
public property let iangle(n):iang= n*pi180 :end property
|
||||
public sub pd() : pdown=true: end sub
|
||||
public sub pu() :pdown=FALSE :end sub
|
||||
|
||||
public sub rt(i)
|
||||
ori=ori - i*iang:
|
||||
'if ori<0 then ori = ori+pi*2
|
||||
end sub
|
||||
public sub lt(i):
|
||||
ori=(ori + i*iang)
|
||||
'if ori>(pi*2) then ori=ori-pi*2
|
||||
end sub
|
||||
|
||||
public sub bw(l)
|
||||
x= x+ cos(ori+pi)*l*incr
|
||||
y= y+ sin(ori+pi)*l*incr
|
||||
' ori=ori+pi '?????
|
||||
end sub
|
||||
|
||||
public sub fw(l)
|
||||
dim x1,y1
|
||||
x1=x + cos(ori)*l*incr
|
||||
y1=y + sin(ori)*l*incr
|
||||
if pdown then line x,y,x1,y1
|
||||
x=x1:y=y1
|
||||
end sub
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
setlocale "us"
|
||||
initsvg
|
||||
x=400:y=400:incr=100
|
||||
ori=90*pi180
|
||||
iang=90*pi180
|
||||
clr=0
|
||||
pdown=true
|
||||
end sub
|
||||
|
||||
Private Sub Class_Terminate()
|
||||
disply
|
||||
end sub
|
||||
|
||||
private sub line (x,y,x1,y1)
|
||||
svg.WriteLine "<line x1=""" & x & """ y1= """& y & """ x2=""" & x1& """ y2=""" & y1 & """/>"
|
||||
end sub
|
||||
|
||||
private sub disply()
|
||||
dim shell
|
||||
svg.WriteLine "</svg></body></html>"
|
||||
svg.close
|
||||
Set shell = CreateObject("Shell.Application")
|
||||
shell.ShellExecute fn,1,False
|
||||
end sub
|
||||
|
||||
private sub initsvg()
|
||||
dim scriptpath
|
||||
Set fso = CreateObject ("Scripting.Filesystemobject")
|
||||
ScriptPath= Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
|
||||
fn=Scriptpath & "SIERP.HTML"
|
||||
Set svg = fso.CreateTextFile(fn,True)
|
||||
if SVG IS nothing then wscript.echo "Can't create svg file" :vscript.quit
|
||||
svg.WriteLine "<!DOCTYPE html>" &vbcrlf & "<html>" &vbcrlf & "<head>"
|
||||
svg.writeline "<style>" & vbcrlf & "line {stroke:rgb(255,0,0);stroke-width:.5}" &vbcrlf &"</style>"
|
||||
svg.writeline "</head>"&vbcrlf & "<body>"
|
||||
svg.WriteLine "<svg xmlns=""http://www.w3.org/2000/svg"" width=""800"" height=""800"" viewBox=""0 0 800 800"">"
|
||||
end sub
|
||||
end class
|
||||
|
||||
sub dragon(st,le,dir)
|
||||
if st=0 then x.fw le: exit sub
|
||||
x.rt dir
|
||||
dragon st-1, le/1.41421 ,1
|
||||
x.rt dir*2
|
||||
dragon st-1, le/1.41421 ,-1
|
||||
x.rt dir
|
||||
end sub
|
||||
|
||||
|
||||
dim x
|
||||
set x=new turtle
|
||||
x.iangle=45
|
||||
x.orient=45
|
||||
x.incr=1
|
||||
x.x=200:x.y=200
|
||||
dragon 12,300,1
|
||||
set x=nothing 'this displays the image
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
File_Open("|(USER_MACRO)\dragon.bmp", OVERWRITE+NOEVENT)
|
||||
BOF Del_Char(ALL)
|
||||
|
||||
#11 = 640 // width of the image
|
||||
#12 = 480 // height of the image
|
||||
#11 = 640 // width of the image
|
||||
#12 = 480 // height of the image
|
||||
Call("CREATE_BMP")
|
||||
|
||||
#1 = 384 // dx
|
||||
#2 = 0 // dy
|
||||
#3 = 6 // depth of recursion
|
||||
#4 = 1 // flip
|
||||
#5 = 150 // x
|
||||
#6 = 300 // y
|
||||
#1 = 384 // dx
|
||||
#2 = 0 // dy
|
||||
#3 = 6 // depth of recursion
|
||||
#4 = 1 // flip
|
||||
#5 = 150 // x
|
||||
#6 = 300 // y
|
||||
Call("DRAGON")
|
||||
Buf_Close(NOMSG)
|
||||
|
||||
|
|
@ -29,15 +29,15 @@ if (#3 == 0) {
|
|||
#2 /= 2
|
||||
#3--
|
||||
if (#4) {
|
||||
Num_Push(1,4) #4=1; #7=#1; #1=#2; #2=-#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=1; #7=#1; #1=-#2; #2=#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=1; #7=#1; #1=#2; #2=-#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=1; #7=#1; #1=-#2; #2=#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; Call("DRAGON") Num_Pop(1,4)
|
||||
} else {
|
||||
Num_Push(1,4) #4=1; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; #7=#1; #1=-#2; #2=#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=1; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; #7=#1; #1=#2; #2=-#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=1; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; #7=#1; #1=-#2; #2=#7; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=1; Call("DRAGON") Num_Pop(1,4)
|
||||
Num_Push(1,4) #4=0; #7=#1; #1=#2; #2=-#7; Call("DRAGON") Num_Pop(1,4)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
@ -53,7 +53,7 @@ while (#1 || #2 ) {
|
|||
#5 += #21; #1 -= #21
|
||||
#6 += #22; #2 -= #22
|
||||
Goto_Pos(1078 + #5 + #6*#11)
|
||||
IC(255, OVERWRITE) // plot a pixel
|
||||
IC(255, OVERWRITE) // plot a pixel
|
||||
}
|
||||
return
|
||||
|
||||
|
|
@ -64,19 +64,19 @@ return
|
|||
:CREATE_BMP:
|
||||
|
||||
// BITMAPFILEHEADER:
|
||||
IT("BM") // bfType
|
||||
#10 = 1078+#11*#12 // file size
|
||||
IT("BM") // bfType
|
||||
#10 = 1078+#11*#12 // file size
|
||||
Call("INS_4BYTES")
|
||||
IC(0, COUNT, 4) // reserved
|
||||
#10 = 1078; Call("INS_4BYTES") // offset to bitmap data
|
||||
IC(0, COUNT, 4) // reserved
|
||||
#10 = 1078; Call("INS_4BYTES") // offset to bitmap data
|
||||
|
||||
// BITMAPINFOHEADER:
|
||||
#10 = 40; Call("INS_4BYTES") // size of BITMAPINFOHEADER
|
||||
#10 = #11; Call("INS_4BYTES") // width of image
|
||||
#10 = #12; Call("INS_4BYTES") // height of image
|
||||
IC(1) IC(0) // number of bitplanes = 1
|
||||
IC(8) IC(0) // bits/pixel = 8
|
||||
IC(0, COUNT, 24) // compression, number of colors etc.
|
||||
#10 = 40; Call("INS_4BYTES") // size of BITMAPINFOHEADER
|
||||
#10 = #11; Call("INS_4BYTES") // width of image
|
||||
#10 = #12; Call("INS_4BYTES") // height of image
|
||||
IC(1) IC(0) // number of bitplanes = 1
|
||||
IC(8) IC(0) // bits/pixel = 8
|
||||
IC(0, COUNT, 24) // compression, number of colors etc.
|
||||
|
||||
// Color table - create greyscale palette
|
||||
for (#1 = 0; #1 < 256; #1++) {
|
||||
|
|
@ -96,5 +96,5 @@ return
|
|||
for (#1 = 0; #1 < 4; #1++) {
|
||||
Ins_Char(#10 & 0xff)
|
||||
#10 = #10 >> 8
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -15,30 +15,30 @@ clear window
|
|||
dragon()
|
||||
|
||||
sub dragon()
|
||||
if level<=0 then
|
||||
yn = sin(rotation)*insize + y
|
||||
xn = cos(rotation)*insize + x
|
||||
if iter*2<iters then
|
||||
color 0,iter*qiter,255-iter*qiter
|
||||
else
|
||||
color qiter*iter-255,(iters-iter)*qiter,0
|
||||
end if
|
||||
line x,y,xn,yn
|
||||
iter = iter + 1
|
||||
x = xn : y = yn
|
||||
return
|
||||
end if
|
||||
insize = insize/SQ
|
||||
rotation = rotation + rq*QPI
|
||||
level = level - 1
|
||||
rqs(level) = rq : rq = 1
|
||||
dragon()
|
||||
rotation = rotation - rqs(level)*QPI*2
|
||||
rq = -1
|
||||
dragon()
|
||||
rq = rqs(level)
|
||||
rotation = rotation + rq*QPI
|
||||
level = level + 1
|
||||
insize = insize*SQ
|
||||
return
|
||||
if level<=0 then
|
||||
yn = sin(rotation)*insize + y
|
||||
xn = cos(rotation)*insize + x
|
||||
if iter*2<iters then
|
||||
color 0,iter*qiter,255-iter*qiter
|
||||
else
|
||||
color qiter*iter-255,(iters-iter)*qiter,0
|
||||
end if
|
||||
line x,y,xn,yn
|
||||
iter = iter + 1
|
||||
x = xn : y = yn
|
||||
return
|
||||
end if
|
||||
insize = insize/SQ
|
||||
rotation = rotation + rq*QPI
|
||||
level = level - 1
|
||||
rqs(level) = rq : rq = 1
|
||||
dragon()
|
||||
rotation = rotation - rqs(level)*QPI*2
|
||||
rq = -1
|
||||
dragon()
|
||||
rq = rqs(level)
|
||||
rotation = rotation + rq*QPI
|
||||
level = level + 1
|
||||
insize = insize*SQ
|
||||
return
|
||||
end sub
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue