summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xd.c130
1 files changed, 128 insertions, 2 deletions
diff --git a/xd.c b/xd.c
index e17461f..9f7a037 100644
--- a/xd.c
+++ b/xd.c
@@ -64,6 +64,8 @@ static const char id[]="$Id$";
#define RND(x) (rand()%(x))
#define RND2(h,l) ((rand()%((h)-(l)))+(l))
+#define XY(x,y) ((x) + (y) * width)
+
/* ---------------------------------------- TYPES
*/
typedef enum {UsesImage, UsesPixmap} DType;
@@ -170,10 +172,11 @@ static void TriangleDemo2(void);
static void FollowDemo(void);
static void CatwalkDemo(void);
static void GravityDemo(void);
+static void SnowDemo(void);
/* ---------------------------------------- GLOBAL VARS
*/
-#define NO_DEMOS 18
+#define NO_DEMOS 19
static int demo=NO_DEMOS-1;
@@ -271,6 +274,11 @@ static DemoInfo demotbl[NO_DEMOS]=
GravityDemo,
UsesPixmap
},
+ {
+ "Snow Demo (LMB reset)",
+ SnowDemo,
+ UsesPixmap
+ },
};
/* ---------------------------------------- X11 VARS
@@ -4057,7 +4065,7 @@ static void GravityDemo(void)
gravobj[f].dx = sintab[a] * 0.1;
gravobj[f].dy = costab[a] * 0.1;
- gravobj[f].mass = 1;
+ gravobj[f].mass = 10;
gravobj[f].alive = TRUE;
}
@@ -4164,4 +4172,122 @@ static void GravityDemo(void)
#undef GRAV_SIZE
+/* ---------------------------------------- SNOW DEMO
+ */
+
+#define SNOW_LINES 20
+#define SNOW_FLAKES 10000
+
+static void SnowDemo(void)
+{
+ static int init = FALSE;
+
+ static int *map;
+
+ typedef struct
+ {
+ int x,y;
+ } Flake;
+
+ static Flake *snow;
+
+ int f,r;
+ int x,y;
+ int xi, yi;
+
+ if (!init || mouse_b&Button1Mask)
+ {
+ Cls();
+
+ map = Grab(sizeof *map * width * height);
+ snow = Grab(sizeof *snow * SNOW_FLAKES);
+
+ Line(0, 0, 0, height - 1, red);
+ Line(width - 1, 0, width - 1, height - 1, red);
+ Line(0, height - 1, width - 1, height - 1, red);
+
+ for(x = 0; x < width; x++)
+ {
+ for(y = 0; y < height; y++)
+ {
+ if (x == 0 || x == width - 1 || y == height - 1)
+ {
+ map[XY(x,y)] = 1;
+ }
+ else
+ {
+ map[XY(x,y)] = 0;
+ }
+ }
+ }
+
+ for(f = 0; f < SNOW_LINES; f++)
+ {
+ x = RND(width);
+ y = RND(height);
+ do
+ {
+ xi = RND2(1, -1);
+ } while (xi == 0);
+ yi = 0;
+
+ for(r = RND(50) + 10; r > 0; r--)
+ {
+ if (x > 0 && x < width && y > 0 && y < height)
+ {
+ Plot(x, y, red);
+ map[XY(x,y)] = 1;
+ x += xi;
+ y += yi;
+ }
+ }
+ }
+
+ for(f = 0; f < SNOW_FLAKES; f++)
+ {
+ do
+ {
+ snow[f].x = RND(width - 2) + 1;
+ snow[f].y = RND(height);
+ } while (map[XY(snow[f].x, snow[f].y)]);
+ }
+
+ init=TRUE;
+ }
+
+ for(f = 0; f < SNOW_FLAKES; f++)
+ {
+ if (map[XY(snow[f].x, snow[f].y + 1)] == 0)
+ {
+ Plot(snow[f].x, snow[f].y, black);
+ snow[f].y++;
+ Plot(snow[f].x, snow[f].y, white);
+ }
+ else if (map[XY(snow[f].x + 1, snow[f].y + 1)] == 0)
+ {
+ Plot(snow[f].x, snow[f].y, black);
+ snow[f].x++;
+ snow[f].y++;
+ Plot(snow[f].x, snow[f].y, white);
+ }
+ else if (map[XY(snow[f].x - 1, snow[f].y + 1)] == 0)
+ {
+ Plot(snow[f].x, snow[f].y, black);
+ snow[f].x--;
+ snow[f].y++;
+ Plot(snow[f].x, snow[f].y, white);
+ }
+ else
+ {
+ Plot(snow[f].x, snow[f].y, white);
+ map[XY(snow[f].x, snow[f].y)] = 1;
+ snow[f].x = RND(width - 2) + 1;
+ snow[f].y = 0;
+ }
+ }
+}
+
+#undef SNOW_LINES
+
+
/* END OF FILE */