Beispiel #1
0
t_handler	get_handler(char c)
{
    static t_handler	*handlers = NULL;

    if (handlers == NULL)
    {
        handlers = ft_memalloc(sizeof(*handlers) * 256);
        if (handlers != NULL)
            setup_arr(handlers);
    }
    return (handlers[(int)c]);
}
Beispiel #2
0
static void randblip (struct state *st, int doit)
{
    int n;
    int b = 0;
    if (!doit 
	&& (st->blastcount-- >= 0) 
	&& (RAND_FLOAT > st->anychan))
    {
	return;
    }
    
    if (st->blastcount < 0) 
    {
	b = 1;
	n = 2;
	st->blastcount = random_life_value (st);
	if (RAND_FLOAT < st->instantdeathchan)
	{
	    /* clear everything every so often to keep from getting into a
	     * rut */
	    setup_arr (st);
	    b = 0;
	}
    }
    else if (RAND_FLOAT <= st->minorchan) 
    {
	n = 2;
    }
    else 
    {
	n = random () % 3 + 3;
    }
    
    while (n--) 
    {
      int x = st->arr_width ? random () % st->arr_width : 0;
      int y = st->arr_height ? random () % st->arr_height : 0;
	int c;
	FLOAT s;
	if (b)
	{
	    c = 0;
	    s = RAND_FLOAT * (st->maxdeathspeed - st->mindeathspeed) + st->mindeathspeed;
	}
	else
	{
	    c = ((st->count - 1) ? random () % (st->count-1) : 0) + 1;
	    s = RAND_FLOAT * (st->maxlifespeed - st->minlifespeed) + st->minlifespeed;
	}
	newcell (st, &st->arr[y * st->arr_width + x], c, s);
    }
}
Beispiel #3
0
static void *
petri_init (Display *dpy, Window win)
{
    struct state *st = (struct state *) calloc (1, sizeof(*st));
    st->dpy = dpy;
    st->window = win;

    st->delay = get_integer_resource (st->dpy, "delay", "Delay");
    st->orthlim = 1;

    setup_display (st);
    setup_arr (st);
    randblip (st, 1);
    
    return st;
}