crashtest-r0ket/firmware/l0dable/rockets.c

150 lines
4.4 KiB
C
Raw Normal View History

#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "usetable.h"
static void draw_rakett (int x, int y, int scale, int angle);
2011-08-06 00:37:43 +00:00
static int my_gray (int x, int y, void *data);
void ram (void) {
2011-08-06 00:37:43 +00:00
char test[512]; /* scratch space */
o_init (test, sizeof(test));
int frame_no = 0;
int frame_dir = 1;
2011-08-06 00:37:43 +00:00
o_set_shader (my_gray, NULL);
while (getInputRaw() != BTN_ENTER){
o_identity ();
o_rectangle (0,0,RESX, RESY);
2011-08-06 00:37:43 +00:00
o_set_gray (250);
o_fill (); /* fill with 50% gray */
2011-08-06 00:37:43 +00:00
draw_rakett (40, 20, 400, 300);
draw_rakett (20, 20, 250, 10*frame_no);
draw_rakett (80, 30, 350, 450+14*frame_no);
frame_no += frame_dir;
lcdDisplay();
delayms(2);
if (frame_no > 1000 || frame_no < 0)
frame_dir *= -1;
}
}
2011-08-06 00:37:43 +00:00
static int my_gray (int x, int y, void *data)
{
int value = (int)(data); /* stored gray value as 8bit value */
switch (value) /* the dither patterns are can be seen */
{ /* at the end of the lines */
case 0: /* 0.0 */
return 0;
case 1: /* 0.16 */
return (x%3==0) ? (y %2)? 0:0:
(x%3==1) ? (y %2)? 0:0:
(y %2)? 0:1;
case 2: /* 0.25 */
return (x%2) ? (y %2)? 1:0:
(y %2)? 0:0;
case 3: /* 0.33 */
return (x%3==0) ? (y %2)? 1:0:
(x%3==1) ? (y %2)? 0:0:
(y %2)? 0:1;
case 4: /* 0.50 */
return (x%2==0) ? (y %2)? 1:0:
(y %2)? 0:1;
case 5: /* 0.66 */
return (x%3==0) ? (y %2)? 0:1:
(x%3==1) ? (y %2)? 1:1:
(y %2)? 1:0;
case 6: /* 0.75 */
return (x%2) ? (y %2)? 1:0:
(y %2)? 1:1;
case 7: /* 0.85 */
return (x%3==0) ? (y %2)? 1:1:
(x%3==1) ? (y %2)? 1:0:
(y %2)? 1:1;
case 8: /* 1.0 */
return 1;
default: // return ((char)(rnd1())) < value;
/* XXX: use a faster "random" source
for this fallback */
break;
}
return 0;
}
2011-08-06 00:37:43 +00:00
static signed char rakett[] = {
' ',
'm',38,6,
'c',38,6,36,13,36,15,
'c',24,22,23,26,21,32,'c',19,41,23,61,23,61,'c',15,73,14,95,17,110,'l',26,109,'c',26,102,26,87,30,83,'c',30,83,30,88,30,95,'c',31,103,31,108,31,108,'l',36,108,'c',36,108,35,98,36,91,'c',37,83,38,80,38,80,'c',41,79,43,80,47,79,'c',56,85,56,89,58,99,'c',58,103,58,108,58,108,'l',68,108,'c',67,89,69,73,54,58,'c',54,58,56,41,53,31,'c',50,21,40,15,40,15,'l',38,6,'z','g',0,'f','g',100,'s',
' ',
'm',33,20,'c',31,20,29,21,27,22,'c',25,24,23,27,22,29,'c',20,35,21,38,21,38,'c',26,38,29,36,34,33,'c',38,31,42,24,34,21,'c',34,21,33,20,33,20,'z','g', 50,'f','.'
};
static const signed char * o_process_op (const signed char *g)
{
switch (*g++) {
case ' ': o_path_new (); break;
/* all of these path commands are directly in integer coordinates */
case 'm':
2011-08-06 00:37:43 +00:00
o_move_to (g[0], g[1]); g += 2;
break;
2011-08-06 00:37:43 +00:00
case 'l': o_line_to (g[0], g[1]); g += 2; break;
case 'c': o_curve_to (g[0], g[1], g[2], g[3], g[4], g[5]); g += 6; break;
case 'z': o_close (); break;
case 'g': o_set_gray (g[0]*10); g ++; break;
case 'f': o_fill (); break;
2011-08-06 00:37:43 +00:00
case 's': break;
//case 's': o_stroke (); break;
/* 1 = 1 10 = 10 100 = 100 */
#if 0
case '!': o_identity (); break;
case 'T': o_translate (g[0] * 100, g[1] * 100); g+=2; break;
/* 1 = 0.01 10 = 0.1 50 = 0.5 100 = 10x */
case 'S': o_scale (g[0] * 10, g[1] * 10); g+=2; break;
/* -128 = -360 64 = 180 128 = 360 */
case 'R': o_rotate ((g[0] * 3600)/127); g+=1; break;
#endif
default:
case '\0':
case '.': /* end */
return NULL;
}
return g;
}
static void
2011-08-06 00:37:43 +00:00
orender (const signed char *g)
{
2011-08-06 00:37:43 +00:00
for (; g; g = o_process_op (g));
}
void o_rectangle (int x0, int y0, int width, int height)
{
o_path_new ();
o_move_to (x0, y0);
o_line_to (x0 + width, y0);
o_line_to (x0 + width, y0+height);
o_line_to (x0, y0+height);
o_close ();
}
void draw_rakett (int x, int y, int scale, int angle)
{
2011-08-06 00:37:43 +00:00
OMatrix m={{{scale,0},{0,scale},{x * 6000,y * 6000}}};
o_identity (); /* reset transform stack */
/*
o_translate(x * 1000 , y * 1000 );
o_rotate (angle);
o_scale (scale, scale);
o_translate (-37000, -60000);*/
o_transform (&m, 0);
orender (rakett); /* render a rocket */
}