Main Page | Data Structures | File List | Data Fields | Globals

ex5.c

00001 /*=========================================================================
00002 
00003 GFX EXAMPLE CODE - #5
00004         "the evil eye, line drawing"
00005 
00006 Copyright (C) 2004  Rafael de Oliveira Jannone
00007 
00008 This example's source code is Public Domain.
00009 
00010 WARNING: The author makes no guarantees and holds no responsibility for 
00011 any damage, injury or loss that may result from the use of this source 
00012 code. USE IT AT YOUR OWN RISK.
00013 
00014 Contact the author:
00015         by e-mail : rafael AT jannone DOT org
00016         homepage  : http://jannone.org/gfxlib
00017         ICQ UIN   : 10115284
00018 
00019 =========================================================================*/
00020 
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <math.h>
00024 #include "gfx.h"
00025 #include "line.h"
00026 
00027 typedef struct {
00028         int x;
00029         int y;
00030 } point_t;
00031 
00032 #define MAX_POINT       12
00033 
00034 main() {
00035         u_char* buf = (u_char*)malloc(MODE2_MAX);
00036 
00037         double  M_PI;
00038         double  a;
00039         int     c, i;
00040         surface_t surf;
00041         point_t p[MAX_POINT];
00042 
00043         printf("calculating, wait...\n");
00044 
00045         M_PI = 8.0 * atan(1.0);
00046 
00047         // calculates points from circunference
00048         for (c = 0; c < MAX_POINT; c++) {
00049                 a = (M_PI * (double)c) / (double)MAX_POINT;
00050                 p[c].x = (int)(100.0 * cos(a) + 128.0);
00051                 p[c].y = (int)(80.0 * sin(a) + 96.0);
00052         }
00053 
00054         // clear the off-screen surface
00055         printf("clearing buffer...\n");
00056         memset(buf, MODE2_MAX, 0);
00057 
00058         printf("drawing...\n");
00059         surf.data.ram = buf;
00060 
00061         // draw the eye's lines into the surface (obs: we are NOT in graphic mode yet)
00062         for (c = 0; c < MAX_POINT; c++) 
00063                 for (i = c+1; i < MAX_POINT; i++)
00064                         surface_line(&surf, p[c].x, p[c].y, p[i].x, p[i].y);
00065 
00066         // set screen to graphic mode
00067         set_color(15, 1, 1);
00068         set_mode(mode_2);
00069         fill(MODE2_ATTR, 0xF1, MODE2_MAX);
00070 
00071         // finally show the surface
00072         vwrite(surf.data.ram, 0, MODE2_MAX);
00073 
00074         while (!get_trigger(0)) {}
00075 
00076         set_mode(mode_0);
00077 }

Generated on Thu Mar 3 19:55:01 2005 for GFX lib by  doxygen 1.4.1