Rename GP_Context -> GP_Pixmap
[gfxprim.git] / demos / c_simple / sin_AA.c
blob0191918a2e80a5a70568e2eefe8e630d2fce76af
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Simple example that shows HLineAA() usage.
29 #include <stdio.h>
30 #include <errno.h>
31 #include <string.h>
33 #include <GP.h>
35 static void redraw(GP_Pixmap *pixmap)
37 static float param = 1;
38 static float param2 = 0.01;
39 static int flag = 1;
40 GP_Pixel b = GP_RGBToPixmapPixel(0xbe, 0xbe, 0x9e, pixmap);
41 unsigned int y;
43 GP_Fill(pixmap, b);
45 for (y = 0; y < pixmap->w; y++) {
46 GP_Coord x0, x1, l1, l2;
48 x0 = (pixmap->w)<<7;
49 x1 = (pixmap->w)<<7;
51 l1 = (pixmap->w)<<5;
52 l2 = (pixmap->w)<<3;
54 GP_Pixel p = GP_RGBToPixmapPixel(120 - 3 * param, abs(40 * param), 0, pixmap);
56 l2 *= 4.00 * y / pixmap->h;
58 l1 *= param;
60 x0 += l1 * sin(param2 * y) + l2;
61 x1 -= l1 * cos(param2 * y) + l2;
63 GP_HLineAA(pixmap, x0, x1, y<<8, p);
66 if (flag) {
67 param -= 0.02;
69 if (param <= -2.40) {
70 flag = 0;
71 param2 += 0.01;
73 if (param2 > 0.02)
74 param2 = 0.01;
76 } else {
77 param += 0.02;
79 if (param >= 2.40)
80 flag = 1;
84 int main(void)
86 GP_Backend *backend;
87 static int pause_flag = 0;
89 /* Initalize backend */
90 backend = GP_BackendX11Init(NULL, 0, 0, 800, 600, "sin AA", 0);
92 if (backend == NULL) {
93 fprintf(stderr, "Failed to initalize backend\n");
94 return 1;
97 /* Wait for events */
98 for (;;) {
99 if (!pause_flag) {
100 redraw(backend->pixmap);
101 GP_BackendFlip(backend);
104 GP_BackendPoll(backend);
106 GP_Event ev;
108 while (GP_BackendGetEvent(backend, &ev)) {
109 if (ev.type == GP_EV_KEY && ev.code == GP_EV_KEY_DOWN) {
110 switch (ev.val.val) {
111 case GP_KEY_ESC:
112 case GP_KEY_Q:
113 GP_BackendExit(backend);
114 return 0;
115 case GP_KEY_P:
116 pause_flag = !pause_flag;
117 break;
122 usleep(10000);
125 return 0;