-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex5.c
77 lines (56 loc) · 1.7 KB
/
ex5.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
73
74
75
76
77
/*=========================================================================
GFX EXAMPLE CODE - #5
"the evil eye, line drawing"
Copyright (C) 2004 Rafael de Oliveira Jannone
This example's source code is Public Domain.
WARNING: The author makes no guarantees and holds no responsibility for
any damage, injury or loss that may result from the use of this source
code. USE IT AT YOUR OWN RISK.
Contact the author:
by e-mail : rafael AT jannone DOT org
homepage : http://jannone.org/gfxlib
ICQ UIN : 10115284
=========================================================================*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "gfx.h"
#include "line.h"
typedef struct {
int x;
int y;
} point_t;
#define MAX_POINT 12
main() {
u_char* buf = (u_char*)malloc(MODE2_MAX);
double M_PI;
double a;
int c, i;
surface_t surf;
point_t p[MAX_POINT];
printf("calculating, wait...\n");
M_PI = 8.0 * atan(1.0);
// calculates points from circunference
for (c = 0; c < MAX_POINT; c++) {
a = (M_PI * (double)c) / (double)MAX_POINT;
p[c].x = (int)(100.0 * cos(a) + 128.0);
p[c].y = (int)(80.0 * sin(a) + 96.0);
}
// clear the off-screen surface
printf("clearing buffer...\n");
memset(buf, MODE2_MAX, 0);
printf("drawing...\n");
surf.data.ram = buf;
// draw the eye's lines into the surface (obs: we are NOT in graphic mode yet)
for (c = 0; c < MAX_POINT; c++)
for (i = c+1; i < MAX_POINT; i++)
surface_line(&surf, p[c].x, p[c].y, p[i].x, p[i].y);
// set screen to graphic mode
set_color(15, 1, 1);
set_mode(mode_2);
fill(MODE2_ATTR, 0xF1, MODE2_MAX);
// finally show the surface
vwrite(surf.data.ram, 0, MODE2_MAX);
while (!get_trigger(0)) {}
set_mode(mode_0);
}