25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
3.4 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 "cucul.h"
  15. #include "caca.h"
  16. #define XRATIO 100*100
  17. #define YRATIO 70*70
  18. #define FUZZY 5000000
  19. enum cucul_color points[] =
  20. {
  21. CUCUL_COLOR_BLACK,
  22. CUCUL_COLOR_DARKGRAY,
  23. CUCUL_COLOR_LIGHTGRAY,
  24. CUCUL_COLOR_WHITE,
  25. CUCUL_COLOR_RED,
  26. CUCUL_COLOR_LIGHTRED
  27. };
  28. char density[] = " -,+:;o&%w$W@#";
  29. int main(void)
  30. {
  31. cucul_t *qq;
  32. caca_t *kk;
  33. int neara, dista, nearb, distb, dist;
  34. int x, y;
  35. qq = cucul_init();
  36. kk = caca_attach(qq);
  37. for(x = 0; x < 100; x++)
  38. for(y = 0; y < 100; y++)
  39. {
  40. char ch = '?';
  41. /* distance to black */
  42. dista = XRATIO * x * x;
  43. neara = 0;
  44. /* distance to 40% */
  45. dist = XRATIO * (x - 40) * (x - 40) + YRATIO * y * y;
  46. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  47. {
  48. nearb = neara; distb = dista; neara = 1; dista = dist;
  49. }
  50. else
  51. {
  52. nearb = 1; distb = dist;
  53. }
  54. /* check dist to 70% */
  55. dist = XRATIO * (x - 70) * (x - 70) + YRATIO * y * y;
  56. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  57. {
  58. nearb = neara; distb = dista; neara = 2; dista = dist;
  59. }
  60. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  61. {
  62. nearb = 2; distb = dist;
  63. }
  64. /* check dist to white */
  65. dist = XRATIO * (x - 100) * (x - 100) + YRATIO * y * y;
  66. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  67. {
  68. nearb = neara; distb = dista; neara = 3; dista = dist;
  69. }
  70. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  71. {
  72. nearb = 3; distb = dist;
  73. }
  74. #if 1
  75. /* check dist to dark */
  76. dist = XRATIO * (x - 40) * (x - 40) + YRATIO * (y - 100) * (y - 100);
  77. dist = dist * 12 / 16;
  78. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  79. {
  80. nearb = neara; distb = dista; neara = 4; dista = dist;
  81. }
  82. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  83. {
  84. nearb = 4; distb = dist;
  85. }
  86. /* check dist to light */
  87. dist = XRATIO * (x - 100) * (x - 100) + YRATIO * (y - 100) * (y - 100);
  88. dist = dist * 8 / 16;
  89. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  90. {
  91. nearb = neara; distb = dista; neara = 5; dista = dist;
  92. }
  93. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  94. {
  95. nearb = 5; distb = dist;
  96. }
  97. #endif
  98. /* dista can be > distb because of dithering fuzziness */
  99. if(dista > distb)
  100. ch = density[distb * 2 * 13 / (dista + distb)];
  101. else
  102. ch = density[dista * 2 * 13 / (dista + distb)];
  103. cucul_set_color(qq, points[nearb], points[neara]);
  104. cucul_putchar(qq, x * cucul_get_width(qq) / 100,
  105. (100 - y) * cucul_get_height(qq) / 100, ch);
  106. }
  107. caca_display(kk);
  108. while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS));
  109. caca_detach(kk);
  110. cucul_end(qq);
  111. return 0;
  112. }