update patch for openssl to 1.1.0h
[AROS-Contrib.git] / Demo / kdp / bump.c
blob41db70adaea05f41cd5b5a4d0dee76c5a10438d3
1 #include "kdp.h"
2 #include "kdpgfx.h"
3 //#include <stdio.h>
4 #include <math.h>
6 #include <proto/dos.h>
8 unsigned char sprite[256*256];
9 unsigned char light[256*256];
10 unsigned char picture[64000];
11 unsigned char palette[960];
12 unsigned char *vmem;
13 UBYTE pic[64000];
15 #define ARG_TEMPLATE "WINPOSX=X/N/K,WINPOSY=Y/N/K"
16 #define ARG_X 0
17 #define ARG_Y 1
18 #define NUM_ARGS 2
20 static IPTR args[NUM_ARGS];
22 static void getarguments(void)
24 struct RDArgs *myargs;
26 if ((myargs = ReadArgs(ARG_TEMPLATE, args, NULL)))
28 if (args[ARG_X])
30 char s[10];
31 WORD winx = *(IPTR *)args[ARG_X];
33 snprintf(s, sizeof(s), "%d", winx);
34 SetVar("WINPOSX", s, strlen(s), GVF_LOCAL_ONLY | LV_VAR);
37 if (args[ARG_Y])
39 char s[10];
40 WORD winy = *(IPTR *)args[ARG_Y];
42 snprintf(s, sizeof(s), "%d", winy);
43 SetVar("WINPOSY", s, strlen(s), GVF_LOCAL_ONLY | LV_VAR);
46 FreeArgs(myargs);
50 void make_sprite(float m)
52 int x, y, val;
54 for (y=-128; y<128; y++)
55 for (x=-128; x<128; x++)
57 val=255-(sqrt((x*x)+(y*y))*m);
58 if (val>0)
59 sprite[256*(y+128)+(x+128)]=val;
60 else
61 sprite[256*(y+128)+(x+128)]=0;
65 void load_pictures()
67 KDPreadBMP("bmp/shade1.bmp",palette,picture);
68 KDPreadBMP("bmp/shade2.bmp",palette,pic);
71 void make_lightpicture(int xpos, int ypos)
73 int x, y;
74 memset(light, 0, 256*256);
75 for (y=0; y<256; y++)
76 for (x=0; x<256; x++)
78 light[(320*(ypos+y)+(xpos+x))& 0xffff]=sprite[256*y+x];
82 void shade_picture()
84 int xdelta, ydelta;
85 int o;
87 UBYTE *vm=vmem;
88 UBYTE *p=picture;
89 UBYTE *pc=pic;
91 vm+=320;
92 p+=320;
93 for(o=320;o<64000;o++)
95 //xdelta=picture[o-1]-picture[o];
96 //ydelta=(picture[o-320]-picture[o])*320;
97 //vmem[o]=KDPcgcoltab[(pic[o]<<8)+light[(o+xdelta+ydelta)&0xffff]];
98 xdelta=(*(p-1))-(*p);
99 ydelta=((*(p-320))-(*p))*320;
100 p++;
101 *(vm++)=KDPcgcoltab[((*(pc++))<<8)+light[(o+xdelta+ydelta)&0xffff]];
103 for(o=0;o<320;o++)
104 vmem[o]=0;
107 int main(int argc, char **argv)
109 KDPscreen screen;
110 KDPmouse mouse;
111 float mx,my;
112 float xx = 0.0,yy = 0.0;
114 getarguments();
116 make_sprite(3);
117 load_pictures();
119 KDPmakecoltab1(palette);
121 if (KDPopen(&screen))
123 KDPsetPal(palette);
124 vmem=screen.vmem;
125 mouse.button=0;
126 mx=160;my=100;
127 while(mouse.button!=3)
129 make_lightpicture(mx, my);
130 shade_picture();
131 KDPwaitVr();
132 KDPshow(vmem);
133 KDPgetMouse(&mouse);
135 if (mouse.button!=1)
137 mx+=sin(xx)*2;
138 my+=sin(yy)*2;
140 else
142 mx+=mouse.xspeed;
143 my+=mouse.yspeed;
145 xx+=0.01;
146 yy+=0.003;
149 KDPclose(&screen);
151 return 0;