소스 검색

* Changed the cucul_rand() behaviour. Now cucul_rand(0, 10) returns random

values between 0 and 9 (used to be 0 and 10). Updated documentation
    accordingly.
tags/v0.99.beta14
Sam Hocevar sam 18 년 전
부모
커밋
e3f0d6c57d
4개의 변경된 파일34개의 추가작업 그리고 33개의 파일을 삭제
  1. +3
    -2
      cucul/cucul.c
  2. +1
    -1
      cucul/dither.c
  3. +21
    -21
      test/demo.c
  4. +9
    -9
      test/dithering.c

+ 3
- 2
cucul/cucul.c 파일 보기

@@ -241,11 +241,12 @@ void cucul_free_canvas(cucul_canvas_t *cv)
*
* \param min The lower bound of the integer range.
* \param max The upper bound of the integer range.
* \return A random integer comprised between \p min and \p max, inclusive.
* \return A random integer comprised between \p min and \p max - 1
* (inclusive).
*/
int cucul_rand(int min, int max)
{
return min + (int)((1.0*(max-min+1)) * rand() / (RAND_MAX+1.0));
return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0));
}

/*


+ 1
- 1
cucul/dither.c 파일 보기

@@ -1251,7 +1251,7 @@ static void init_random_dither(int line)

static unsigned int get_random_dither(void)
{
return cucul_rand(0x00, 0xff);
return cucul_rand(0x00, 0x100);
}

static void increment_random_dither(void)


+ 21
- 21
test/demo.c 파일 보기

@@ -310,8 +310,8 @@ static void demo_all(void)
/* Draw a trail behind the foreground sprite */
for(j = i - 60; j < i; j++)
{
int delta = cucul_rand(-5, 5);
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
int delta = cucul_rand(-5, 6);
cucul_set_color(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_putchar(cv, cucul_get_canvas_width(cv) / 2
+ cos(0.02*j) * (delta + cucul_get_canvas_width(cv) / 4),
cucul_get_canvas_height(cv) / 2
@@ -327,8 +327,8 @@ static void demo_all(void)

static void demo_dots(void)
{
int xmax = cucul_get_canvas_width(cv) - 1;
int ymax = cucul_get_canvas_height(cv) - 1;
int xmax = cucul_get_canvas_width(cv);
int ymax = cucul_get_canvas_height(cv);
int i;
static char chars[10] =
{
@@ -338,7 +338,7 @@ static void demo_dots(void)
for(i = 1000; i--;)
{
/* Putpixel */
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_set_color(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_putchar(cv, cucul_rand(0, xmax), cucul_rand(0, ymax),
chars[cucul_rand(0, 9)]);
}
@@ -376,11 +376,11 @@ static void demo_lines(void)
}
else
{
xa = cucul_rand(0, w - 1); ya = cucul_rand(0, h - 1);
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1);
xa = cucul_rand(0, w); ya = cucul_rand(0, h);
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
}

cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK);
if(outline > 1)
cucul_draw_thin_line(cv, xa, ya, xb, yb);
else
@@ -400,14 +400,14 @@ static void demo_boxes(void)
}
else
{
xa = cucul_rand(0, w - 1); ya = cucul_rand(0, h - 1);
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1);
xa = cucul_rand(0, w); ya = cucul_rand(0, h);
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
}

cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_set_color(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_fill_box(cv, xa, ya, xb, yb, "#");

cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK);
if(outline == 2)
cucul_draw_thin_box(cv, xa, ya, xb, yb);
else if(outline == 1)
@@ -435,10 +435,10 @@ static void demo_ellipses(void)
} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
}

cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_set_color(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_fill_ellipse(cv, x, y, a, b, "#");

cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK);
if(outline == 2)
cucul_draw_thin_ellipse(cv, x, y, a, b);
else if(outline == 1)
@@ -460,15 +460,15 @@ static void demo_triangles(void)
else
{

xa = cucul_rand(0, w - 1); ya = cucul_rand(0, h - 1);
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1);
xc = cucul_rand(0, w - 1); yc = cucul_rand(0, h - 1);
xa = cucul_rand(0, w); ya = cucul_rand(0, h);
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
xc = cucul_rand(0, w); yc = cucul_rand(0, h);
}

cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_set_color(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, "#");

cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK);
if(outline == 2)
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
else if(outline == 1)
@@ -477,8 +477,8 @@ static void demo_triangles(void)

static void demo_sprites(void)
{
cucul_draw_sprite(cv, cucul_rand(0, cucul_get_canvas_width(cv) - 1),
cucul_rand(0, cucul_get_canvas_height(cv) - 1), sprite, 0);
cucul_draw_sprite(cv, cucul_rand(0, cucul_get_canvas_width(cv)),
cucul_rand(0, cucul_get_canvas_height(cv)), sprite, 0);
}

#if 0


+ 9
- 9
test/dithering.c 파일 보기

@@ -54,7 +54,7 @@ int main(void)

/* distance to 40% */
dist = XRATIO * (x - 40) * (x - 40) + YRATIO * y * y;
if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
{
nearb = neara; distb = dista; neara = 1; dista = dist;
}
@@ -65,22 +65,22 @@ int main(void)

/* check dist to 70% */
dist = XRATIO * (x - 70) * (x - 70) + YRATIO * y * y;
if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
{
nearb = neara; distb = dista; neara = 2; dista = dist;
}
else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
{
nearb = 2; distb = dist;
}

/* check dist to white */
dist = XRATIO * (x - 100) * (x - 100) + YRATIO * y * y;
if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
{
nearb = neara; distb = dista; neara = 3; dista = dist;
}
else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
{
nearb = 3; distb = dist;
}
@@ -89,11 +89,11 @@ int main(void)
/* check dist to dark */
dist = XRATIO * (x - 40) * (x - 40) + YRATIO * (y - 100) * (y - 100);
dist = dist * 12 / 16;
if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
{
nearb = neara; distb = dista; neara = 4; dista = dist;
}
else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
{
nearb = 4; distb = dist;
}
@@ -101,11 +101,11 @@ int main(void)
/* check dist to light */
dist = XRATIO * (x - 100) * (x - 100) + YRATIO * (y - 100) * (y - 100);
dist = dist * 8 / 16;
if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
{
nearb = neara; distb = dista; neara = 5; dista = dist;
}
else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
{
nearb = 5; distb = dist;
}


불러오는 중...
취소
저장