-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
77 lines (62 loc) · 1.82 KB
/
main.cpp
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
#include <iostream>
#include <cmath>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include "gfx.h"
#include "cudaFractal.h"
#define HEIGHT 768
#define WIDTH 1280
#define NUM_THREADS_PER_BLOCK 256
void draw_fractal(const char *fractal) {
for (int j = 0; j < HEIGHT; ++j) {
for (int i = 0; i < WIDTH; ++i) {
char pixel = fractal[i + j * WIDTH];
gfx_color(pixel, pixel, pixel);
gfx_point(i, j);
}
}
}
void save_fractal(const char* fractal) {
static int number = 0;
char outputImageFile[50];
sprintf(outputImageFile, "mandelbrot_%d.pgm", number);
number++;
FILE *fp = fopen(outputImageFile, "wb"); /* b - binary mode */
fprintf(fp, "P5\n%d %d\n255\n", WIDTH, HEIGHT);
fwrite(fractal, sizeof(char), HEIGHT*WIDTH, fp);
fclose(fp);
}
int main(int argc, char *argv[]) {
char c;
char* fractal;
// Open a new window for drawing.
gfx_open(WIDTH, HEIGHT, "Example Graphics Program");
init_gpu(WIDTH, HEIGHT);
draw_fractal(fractal = create_fractal());
while (true) {
// Wait for the user to press a character.
c = gfx_wait();
// Quit if it is the letter q.
if (c == 'q') break;
if (c == 'c') {
std::cout << gfx_xpos() << " " << gfx_ypos() << std::endl;
set_center(gfx_xpos(), gfx_ypos());
draw_fractal(fractal = create_fractal());
}
if (c == 'o') {
set_zoom_scale(1.5);
draw_fractal(fractal = create_fractal());
}
if (c == 'i') {
set_zoom_scale(0.66);
draw_fractal(fractal = create_fractal());
}
if (c == 's') {
save_fractal(fractal);
std::cout << "fractal saved" << std::endl;
}
}
delete_gpu();
return 0;
}