-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex4.c
72 lines (53 loc) · 1.58 KB
/
ex4.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
/*=========================================================================
GFX EXAMPLE CODE - #4
"moving sprites"
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 <stdio.h>
#include <math.h>
#include "gfx.h"
typedef struct {
int x;
int y;
} point_t;
#define MAX_POINT 256
main() {
double M_PI;
double a;
int c, i, l;
point_t p[MAX_POINT];
printf("calculating, wait...");
M_PI = 8.0 * atan(1.0);
// precalculate trajetory
for (c = 0; c < MAX_POINT; c++) {
a = (M_PI * (double)c) / (double)MAX_POINT;
p[c].x = ((int)(100.0 * cos(a))) + (128 - 8);
p[c].y = ((int)(80.0 * sin(a))) + (96 - 8);
if (c & 8)
putch('.');
}
printf("done!\n");
// set graphic screen
set_color(15, 1, 1);
set_mode(mode_2);
set_sprite_mode(sprite_large);
fill(MODE2_ATTR, 0xF1, MODE2_MAX);
// create one sprite with a shape from the character table
set_sprite_16(0, (void*)(0x1BBF + 8));
while (!get_trigger(0))
for (c = 0; c < MAX_POINT; c++) { // for each starting point
for (i = 0; i < 8; i++) { // set location for the 8 sprites contiguously
l = (c + (i << 4)) % MAX_POINT;
put_sprite_16(i, p[l].x, p[l].y, 0, i + 2);
}
}
set_mode(mode_0);
}