Rev 312 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*******************************************************************************
* draw_test.c - a simple test of the draw library
*
* Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
******************************************************************************/
#include <cstdio>
#include <cmath>
#include <unistd.h>
using namespace std;
#include "draw.h"
void wait_for_newline ()
{
char c;
while ((c = getchar()) != '\n')
usleep (10000);
}
int main ()
{
int i;
int sinpos;
const int strsiz = 100;
char *tempstr;
/* Initialize the draw library */
draw_init ();
tempstr = (char*) malloc (strsiz * sizeof(char));
/* Testcase #1, a few boxes, a line, and a pixel */
draw_clearscreen ();
draw_putpixel (20, 20, RED);
draw_box (50, 50, 100, 100, GREEN);
draw_line (30, 20, 300, 180, BLUE);
draw_box (100, 80, 100, 100, WHITE);
wait_for_newline ();
/* Testcase #2, all of the possible colors */
draw_clearscreen ();
for (i=0; i<16; i++)
{
draw_box (10, (i+1)*22, 20, 20, i);
snprintf (tempstr, strsiz, "color: #%d", i);
draw_puts (36, (i+1)*22+8, tempstr, WHITE);
}
wait_for_newline ();
/* Testcase #3, draw the sin() function, labeling it as we go */
draw_clearscreen ();
for (i=0; i<800; i++)
{
/* sin itself */
sinpos = (int)(400+(50.0 * sin (i / 50.0)));
draw_putpixel (i, sinpos, GREEN);
/* labels */
if (i % 100 == 0)
{
snprintf (tempstr, strsiz, "%d sec", i / 100);
draw_puts (i, sinpos + 10, tempstr, WHITE);
draw_line (i, sinpos, i, sinpos+8, WHITE);
}
/* slow it down */
usleep (10000);
}
wait_for_newline ();
/* Testcase #4, text output */
draw_clearscreen ();
draw_puts (0, 80, "Hello world!", WHITE);
draw_puts (20, 100, "Some more test text", RED);
wait_for_newline ();
/* Cleanup */
draw_close ();
free (tempstr);
return (0);
}