-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathback up.txt
132 lines (113 loc) · 2.04 KB
/
back up.txt
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <ctime>
#include "WG.h"
#define W WF-50
#define H HF-50
#define PAL 900
#define WF 600
#define HF 250
void print(void);
int what(int x, int y);
void Null(int flag);
typedef struct MyStruct
{
short int r, g, b;
}RgB;
RgB palette[PAL],nul;
int map[H][W];
double start,ends;
void generatePalette(void);
int is = 0;
int main()
{
init_WinGraphic("KG", WF, HF);
srand(time(0));
generatePalette();
Null(0);
setDrawFunction(100, &print);
runWindows();
return 0;
}
void print(void)
{
//start = clock();
Null(1);
int Height = H;
for (int i = 0; i <4; i++)
for (size_t y =0 ; y < H - 2; y++)
{
for (size_t x = 0; x < W; x++)
map[y][x] = what(x, y);
}
for (size_t y =0 ; y < H-6; y++)
for (size_t x = 0; x < W; x++)
{
setpixel(x, y, RGB(palette[map[y][x]].r, palette[map[y][x]].g, palette[map[y][x]].b));
}
//ends = clock();
//printf("\n time %lf \n", (ends - start) / 1000);
}
int RR(void)
{
int color;
while(1)
{
color = rand() % PAL;
if (color >PAL-20 )return color;
}
}
void Null(int flag)
{
for (size_t y = 0; y < H; y++)
for (size_t x = 0; x < W; x++)
if (y > H - 3&&(x>30&&x<W-50))
{
if (!(rand()%4==0))
map[y][x] = RR();
else map[y][x] = 0;
}
else if (!flag)map[y][x] = 0;
}
int what(int x, int y)
{
int sum = 0;
sum += map[y][x];
y++;
if(x-1>0)
sum+= map[y][x-1];
else sum+= 0;
if (x+1 <W)
sum += map[y][x +1];
else sum += 0;
sum += map[y++][x];
sum += map[y][x];
sum= sum / 5;
sum += (sum - PAL-(H-y))/100;
if (sum < 0)
sum = 0;
return sum;
}
void generatePalette()
{
for (size_t i = 0; i < PAL; i++)
{
RgB buf=nul;
if (i <= PAL)
{
palette[i].r = i * ((double)255/ (PAL / 3));
}
if (i > (PAL/3)&&i<=(PAL*2/ 3))
{
palette[i].r = 255;
palette[i].g = ((double)160/ (PAL / 3))*(i- (PAL / 3));
}
if (i > (PAL * 2 / 3))
{
palette[i].r = 255;
palette[i].g = (((double)95/ (PAL / 3))*(i - (PAL * 2 / 3)))+160;
palette[i].b = ((double)255/ (PAL / 3))*(i - (PAL * 2 / 3));
}
}
}