summaryrefslogtreecommitdiff
path: root/xd.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2018-11-08 13:17:28 +0000
committerIan C <ianc@noddybox.co.uk>2018-11-08 13:17:28 +0000
commit875c3cf912367151fa81aab04b05b809bf3b7f6d (patch)
treeb644dad3e943cb2eefa6091c950b9b5b51b9c539 /xd.c
parente32b3db3ed1ffae943e6b965b9905df5cb687120 (diff)
Added rain demo.
Diffstat (limited to 'xd.c')
-rw-r--r--xd.c112
1 files changed, 111 insertions, 1 deletions
diff --git a/xd.c b/xd.c
index 638aa2f..600850b 100644
--- a/xd.c
+++ b/xd.c
@@ -176,10 +176,11 @@ static void SnowDemo(void);
static void RoadDemo(void);
static void CoasterDemo(void);
static void FireworkDemo(void);
+static void RainDemo(void);
/* ---------------------------------------- GLOBAL VARS
*/
-#define NO_DEMOS 22
+#define NO_DEMOS 23
static int demo=NO_DEMOS-1;
@@ -297,6 +298,11 @@ static DemoInfo demotbl[NO_DEMOS]=
FireworkDemo,
UsesPixmap
},
+ {
+ "Rain Demo",
+ RainDemo,
+ UsesPixmap
+ },
};
/* ---------------------------------------- X11 VARS
@@ -350,6 +356,8 @@ static void LineP(XPoint *p1,XPoint *p2,int col);
static void Plot(int x,int y,int col);
static void Circle(int x,int y,int r,int col);
static void FCircle(int x,int y,int r,int col);
+static void Ellipse(int x,int y,int rx,int ry,int col);
+static void FEllipse(int x,int y,int rx,int ry,int col);
static void Print(int x,int y,int col,char *fmt,...);
static void Rect(int x,int y,int w,int h,int col);
static void FRect(int x,int y,int w,int h,int col);
@@ -747,6 +755,32 @@ static void FCircle(int x,int y,int r,int col)
}
+static void Ellipse(int x,int y,int rx,int ry,int col)
+{
+ if (rx < 1 && ry < 1)
+ {
+ Plot(x,y,col);
+ return;
+ }
+
+ SetCol(col);
+ XDrawArc(disp,pix,gc,x-rx,y-ry,rx*2,ry*2,0,64*360);
+}
+
+
+static void FEllipse(int x,int y,int rx,int ry,int col)
+{
+ if (rx < 1 && ry < 1)
+ {
+ Plot(x,y,col);
+ return;
+ }
+
+ SetCol(col);
+ XFillArc(disp,pix,gc,x-rx,y-ry,rx*2,ry*2,0,64*360);
+}
+
+
static void Print(int x,int y,int col,char *fmt,...)
{
char s[1024];
@@ -5047,4 +5081,80 @@ static void FireworkDemo(void)
#undef DY_ADJ
+/* ---------------------------------------- RAIN DEMO
+ */
+
+#define MAX_DROPS 40
+#define MAX_RADIUS 40
+
+static void RainDemo(void)
+{
+ static int init = FALSE;
+
+ typedef struct
+ {
+ int alive;
+ int x,y;
+ int r;
+ int life;
+ } Drop;
+
+ static Drop drop[MAX_DROPS];
+
+ int f;
+
+ if (!init)
+ {
+ init=TRUE;
+ }
+
+ Cls();
+
+ if (RND(100) > 95)
+ {
+ for(f = 0; f < MAX_DROPS && drop[f].alive; f++)
+ {
+ }
+
+ if (f < MAX_DROPS)
+ {
+ drop[f].alive = TRUE;
+ drop[f].life = RND2(height-20, height/2);
+ drop[f].y = 0;
+ drop[f].r = 0;
+ drop[f].x = RND(width);
+ }
+ }
+
+ for(f = 0; f < MAX_DROPS; f++)
+ {
+ if (drop[f].alive)
+ {
+ if (drop[f].life > 0)
+ {
+ drop[f].y++;
+ drop[f].life--;
+
+ FCircle(drop[f].x, drop[f].y, 3, blue);
+ Line(drop[f].x, drop[f].y, drop[f].x, drop[f].y - 5, blue);
+ }
+ else
+ {
+ if (drop[f].r < MAX_RADIUS)
+ {
+ drop[f].r++;
+ Ellipse(drop[f].x, drop[f].y, drop[f].r, drop[f].r/3, blue);
+ }
+ else
+ {
+ drop[f].alive = FALSE;
+ }
+ }
+ }
+ }
+}
+
+#undef MAX_DROPS
+
+
/* END OF FILE */