-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOLOR.C
72 lines (65 loc) · 1.4 KB
/
COLOR.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "stdio.h"
void setInk( int ink )
{
static int previous = -9999;
if ( previous != ink )
{
previous = ink;
printf( "\033[38;5;%dm", ink );
}
}
void setPaper( int paper )
{
static int previous = -9999;
if ( previous != paper )
{
previous = paper;
printf( "\033[48;5;%dm", paper );
}
}
void restoreDefaults( void )
{
printf( "\033[0m" );
}
void main( void )
{
int x, y, count, maxitr;
float creal, cimag;
float zreal, zimag;
float zm, zn, zl, zr2;
maxitr = 24;
for ( y = -39; y <= 39; ++y )
{
for ( x = -39; x <= 39; ++x )
{
creal = x / 20.;
cimag = y / 20.;
zreal = creal;
zimag = cimag;
for ( count = 1; count < maxitr; ++count )
{
zm = zreal * zreal;
zn = zimag * zimag;
zl = zm + zn;
if ( zl > 4. )
{
break;
}
zr2 = zm - zn + creal;
zimag = zreal * zimag * 2. + cimag;
zreal = zr2;
}
setInk( 184 - ( 7 * count ) );
setPaper( 232 + count );
/* put down a tick */
printf( "#" );
}
printf( "\n" );
if ( getk() )
{
break;
}
}
restoreDefaults();
}