aboutsummaryrefslogtreecommitdiffstats
path: root/demos/modules/gdisp/gdisp_streaming
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-09-24 16:12:03 +1000
committerinmarket <andrewh@inmarket.com.au>2013-09-24 16:12:03 +1000
commitf16d80e099fd7e7fad241d8d08525920235893e5 (patch)
treeb1520a253930cf41472f3535b8079d6309a8e264 /demos/modules/gdisp/gdisp_streaming
parentd704c2f6d05ecaffa644213f728ed2d0182eeaee (diff)
downloaduGFX-f16d80e099fd7e7fad241d8d08525920235893e5.tar.gz
uGFX-f16d80e099fd7e7fad241d8d08525920235893e5.tar.bz2
uGFX-f16d80e099fd7e7fad241d8d08525920235893e5.zip
New streaming demo
Diffstat (limited to 'demos/modules/gdisp/gdisp_streaming')
-rw-r--r--demos/modules/gdisp/gdisp_streaming/gfxconf.h42
-rw-r--r--demos/modules/gdisp/gdisp_streaming/main.c106
2 files changed, 148 insertions, 0 deletions
diff --git a/demos/modules/gdisp/gdisp_streaming/gfxconf.h b/demos/modules/gdisp/gdisp_streaming/gfxconf.h
new file mode 100644
index 00000000..0b5701ba
--- /dev/null
+++ b/demos/modules/gdisp/gdisp_streaming/gfxconf.h
@@ -0,0 +1,42 @@
+/**
+ * This file has a different license to the rest of the GFX system.
+ * You can copy, modify and distribute this file as you see fit.
+ * You do not need to publish your source modifications to this file.
+ * The only thing you are not permitted to do is to relicense it
+ * under a different license.
+ */
+
+#ifndef _GFXCONF_H
+#define _GFXCONF_H
+
+/* The operating system to use - one of these must be defined */
+//#define GFX_USE_OS_CHIBIOS TRUE
+//#define GFX_USE_OS_WIN32 FALSE
+//#define GFX_USE_OS_POSIX FALSE
+
+/* GFX sub-systems to turn on */
+#define GFX_USE_GDISP TRUE
+#define GFX_USE_GMISC TRUE
+
+/* Features for the GDISP sub-system. */
+#define GDISP_NEED_VALIDATION TRUE
+#define GDISP_NEED_CLIP FALSE
+#define GDISP_NEED_TEXT FALSE
+#define GDISP_NEED_CIRCLE FALSE
+#define GDISP_NEED_ELLIPSE FALSE
+#define GDISP_NEED_ARC FALSE
+#define GDISP_NEED_SCROLL FALSE
+#define GDISP_NEED_PIXELREAD FALSE
+#define GDISP_NEED_CONTROL TRUE
+#define GDISP_NEED_MULTITHREAD FALSE
+#define GDISP_NEED_STREAMING TRUE
+
+/* Builtin Fonts */
+#define GDISP_INCLUDE_FONT_UI2 FALSE
+
+#define GFX_USE_GMISC TRUE
+#define GMISC_NEED_FIXEDTRIG FALSE
+#define GMISC_NEED_FASTTRIG FALSE
+#define GMISC_NEED_INVSQRT TRUE
+
+#endif /* _GFXCONF_H */
diff --git a/demos/modules/gdisp/gdisp_streaming/main.c b/demos/modules/gdisp/gdisp_streaming/main.c
new file mode 100644
index 00000000..cc5eb8b3
--- /dev/null
+++ b/demos/modules/gdisp/gdisp_streaming/main.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu <joel@unormal.org>
+ * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket
+ * Derived from the 2011 IOCCC submission by peter.eastman@gmail.com
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gfx.h"
+#include <math.h>
+
+#define Lightgrey ()
+#define Midgrey ()
+#define Darkgrey (HTML2COLOR(0x303030))
+
+#define BALLCOLOR1 Red
+#define BALLCOLOR2 Yellow
+#define WALLCOLOR HTML2COLOR(0x303030)
+#define BACKCOLOR HTML2COLOR(0xC0C0C0)
+#define FLOORCOLOR HTML2COLOR(0x606060)
+#define SHADOW (255-255*0.2)
+
+int main(void) {
+ coord_t width, height, x, y, i, l, m, n, floor;
+ color_t colour;
+ float ii, spin, o, spinspeed, h, f, g;
+
+ gfxInit();
+ gdispSetOrientation(GDISP_ROTATE_90);
+
+ width = gdispGetWidth();
+ height = gdispGetHeight();
+
+ i=height/5+height%2+1;
+ ii = 1.0/i;
+ floor=height/5-1;
+ spin=0.0;
+ l=width/2;
+ m=height/4;
+ n=.01*width;
+ o=0.0;
+ spinspeed=0.1;
+
+ while(1) {
+ // Draw one frame
+ gdispStreamStart(0, 0, width, height);
+ for (y=0; h = (m-y)*ii, y<height; y++) {
+ for (x=0; x < width; x++) {
+ g=(l-x)*ii;
+ f=-.3*g+.954*h;
+ if (g*g < 1-h*h) {
+ /* The inside of the ball */
+ if ((((int)(9-spin+(.954*g+.3*h)*invsqrt(1-f*f))+(int)(2+f*2))&1))
+ colour = BALLCOLOR1;
+ else
+ colour = BALLCOLOR2;
+ } else {
+ // The background (walls and floor)
+ if (y > height-floor) {
+ if (x < height-y || height-y > width-x)
+ colour = WALLCOLOR;
+ else
+ colour = FLOORCOLOR;
+ } else if (x<floor || x>width-floor)
+ colour = WALLCOLOR;
+ else
+ colour = BACKCOLOR;
+
+ // The ball shadow is darker
+ if (g*(g+.4)+h*(h+.1) < 1)
+ colour = gdispBlendColor(colour, Black, SHADOW);
+ }
+ gdispStreamColor(colour); /* pixel to the LCD */
+ }
+ }
+ gdispStreamStop();
+
+ // Motion
+ spin += spinspeed;
+ m += o;
+ o = m > height-1.75*floor ? -.04*height : o+.002*height;
+ n = (l+=n)<i || l>width-i ? spinspeed=-spinspeed,-n : n;
+ }
+}