Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

135 righe
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. struct caca_event ev;
  32. cucul_t *qq;
  33. caca_t *kk;
  34. int neara, dista, nearb, distb, dist;
  35. int x, y;
  36. qq = cucul_create(0, 0);
  37. kk = caca_attach(qq);
  38. for(x = 0; x < 100; x++)
  39. for(y = 0; y < 100; y++)
  40. {
  41. char ch = '?';
  42. /* distance to black */
  43. dista = XRATIO * x * x;
  44. neara = 0;
  45. /* distance to 40% */
  46. dist = XRATIO * (x - 40) * (x - 40) + YRATIO * y * y;
  47. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  48. {
  49. nearb = neara; distb = dista; neara = 1; dista = dist;
  50. }
  51. else
  52. {
  53. nearb = 1; distb = dist;
  54. }
  55. /* check dist to 70% */
  56. dist = XRATIO * (x - 70) * (x - 70) + YRATIO * y * y;
  57. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  58. {
  59. nearb = neara; distb = dista; neara = 2; dista = dist;
  60. }
  61. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  62. {
  63. nearb = 2; distb = dist;
  64. }
  65. /* check dist to white */
  66. dist = XRATIO * (x - 100) * (x - 100) + YRATIO * y * y;
  67. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  68. {
  69. nearb = neara; distb = dista; neara = 3; dista = dist;
  70. }
  71. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  72. {
  73. nearb = 3; distb = dist;
  74. }
  75. #if 1
  76. /* check dist to dark */
  77. dist = XRATIO * (x - 40) * (x - 40) + YRATIO * (y - 100) * (y - 100);
  78. dist = dist * 12 / 16;
  79. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  80. {
  81. nearb = neara; distb = dista; neara = 4; dista = dist;
  82. }
  83. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  84. {
  85. nearb = 4; distb = dist;
  86. }
  87. /* check dist to light */
  88. dist = XRATIO * (x - 100) * (x - 100) + YRATIO * (y - 100) * (y - 100);
  89. dist = dist * 8 / 16;
  90. if(cucul_rand(-FUZZY, FUZZY) + dist < dista)
  91. {
  92. nearb = neara; distb = dista; neara = 5; dista = dist;
  93. }
  94. else if(cucul_rand(-FUZZY, FUZZY) + dist < distb)
  95. {
  96. nearb = 5; distb = dist;
  97. }
  98. #endif
  99. /* dista can be > distb because of dithering fuzziness */
  100. if(dista > distb)
  101. ch = density[distb * 2 * 13 / (dista + distb)];
  102. else
  103. ch = density[dista * 2 * 13 / (dista + distb)];
  104. cucul_set_color(qq, points[nearb], points[neara]);
  105. cucul_putchar(qq, x * cucul_get_width(qq) / 100,
  106. (100 - y) * cucul_get_height(qq) / 100, ch);
  107. }
  108. caca_display(kk);
  109. caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
  110. caca_detach(kk);
  111. cucul_free(qq);
  112. return 0;
  113. }