Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

139 rindas
3.6 KiB

  1. /*
  2. * dithering libcaca dithering test program
  3. * Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include "common.h"
  15. #if !defined(__KERNEL__)
  16. # include <stdio.h>
  17. #endif
  18. #include "cucul.h"
  19. #include "caca.h"
  20. #define XRATIO 100*100
  21. #define YRATIO 70*70
  22. #define FUZZY 5000000
  23. unsigned int points[] =
  24. {
  25. CUCUL_COLOR_BLACK,
  26. CUCUL_COLOR_DARKGRAY,
  27. CUCUL_COLOR_LIGHTGRAY,
  28. CUCUL_COLOR_WHITE,
  29. CUCUL_COLOR_RED,
  30. CUCUL_COLOR_LIGHTRED
  31. };
  32. char density[] = " ',+:;o&%w$W@#";
  33. int main(int argc, char *argv[])
  34. {
  35. cucul_canvas_t *cv;
  36. caca_display_t *dp;
  37. int neara, dista, nearb, distb, dist;
  38. int x, y;
  39. cv = cucul_create_canvas(0, 0);
  40. dp = caca_create_display(cv);
  41. for(x = 0; x < 100; x++)
  42. for(y = 0; y < 100; y++)
  43. {
  44. char ch = '?';
  45. /* distance to black */
  46. dista = XRATIO * x * x;
  47. neara = 0;
  48. /* distance to 40% */
  49. dist = XRATIO * (x - 40) * (x - 40) + YRATIO * y * y;
  50. if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
  51. {
  52. nearb = neara; distb = dista; neara = 1; dista = dist;
  53. }
  54. else
  55. {
  56. nearb = 1; distb = dist;
  57. }
  58. /* check dist to 70% */
  59. dist = XRATIO * (x - 70) * (x - 70) + YRATIO * y * y;
  60. if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
  61. {
  62. nearb = neara; distb = dista; neara = 2; dista = dist;
  63. }
  64. else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
  65. {
  66. nearb = 2; distb = dist;
  67. }
  68. /* check dist to white */
  69. dist = XRATIO * (x - 100) * (x - 100) + YRATIO * y * y;
  70. if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
  71. {
  72. nearb = neara; distb = dista; neara = 3; dista = dist;
  73. }
  74. else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
  75. {
  76. nearb = 3; distb = dist;
  77. }
  78. #if 1
  79. /* check dist to dark */
  80. dist = XRATIO * (x - 40) * (x - 40) + YRATIO * (y - 100) * (y - 100);
  81. dist = dist * 12 / 16;
  82. if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
  83. {
  84. nearb = neara; distb = dista; neara = 4; dista = dist;
  85. }
  86. else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
  87. {
  88. nearb = 4; distb = dist;
  89. }
  90. /* check dist to light */
  91. dist = XRATIO * (x - 100) * (x - 100) + YRATIO * (y - 100) * (y - 100);
  92. dist = dist * 8 / 16;
  93. if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
  94. {
  95. nearb = neara; distb = dista; neara = 5; dista = dist;
  96. }
  97. else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
  98. {
  99. nearb = 5; distb = dist;
  100. }
  101. #endif
  102. /* dista can be > distb because of dithering fuzziness */
  103. if(dista > distb)
  104. ch = density[distb * 2 * 13 / (dista + distb)];
  105. else
  106. ch = density[dista * 2 * 13 / (dista + distb)];
  107. cucul_set_color(cv, points[nearb], points[neara]);
  108. cucul_putchar(cv, x * cucul_get_canvas_width(cv) / 100,
  109. (100 - y) * cucul_get_canvas_height(cv) / 100, ch);
  110. }
  111. caca_refresh_display(dp);
  112. caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
  113. caca_free_display(dp);
  114. cucul_free_canvas(cv);
  115. return 0;
  116. }