25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

135 satır
3.5 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_BLACK, CUCUL_DARKGRAY, CUCUL_LIGHTGRAY,
  26. CUCUL_WHITE, CUCUL_RED, CUCUL_LIGHTRED
  27. };
  28. char density[] = " ',+:;o&%w$W@#";
  29. int main(int argc, char *argv[])
  30. {
  31. cucul_canvas_t *cv;
  32. caca_display_t *dp;
  33. int neara, dista, nearb, distb, dist;
  34. int x, y;
  35. cv = cucul_create_canvas(0, 0);
  36. dp = caca_create_display(cv);
  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+1) + 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+1) + dist < dista)
  57. {
  58. nearb = neara; distb = dista; neara = 2; dista = dist;
  59. }
  60. else if(cucul_rand(-FUZZY, FUZZY+1) + 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+1) + dist < dista)
  67. {
  68. nearb = neara; distb = dista; neara = 3; dista = dist;
  69. }
  70. else if(cucul_rand(-FUZZY, FUZZY+1) + 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+1) + dist < dista)
  79. {
  80. nearb = neara; distb = dista; neara = 4; dista = dist;
  81. }
  82. else if(cucul_rand(-FUZZY, FUZZY+1) + 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+1) + dist < dista)
  90. {
  91. nearb = neara; distb = dista; neara = 5; dista = dist;
  92. }
  93. else if(cucul_rand(-FUZZY, FUZZY+1) + 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_ansi(cv, points[nearb], points[neara]);
  104. cucul_putchar(cv, x * cucul_get_canvas_width(cv) / 100,
  105. (100 - y) * cucul_get_canvas_height(cv) / 100, ch);
  106. }
  107. caca_refresh_display(dp);
  108. caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
  109. caca_free_display(dp);
  110. cucul_free_canvas(cv);
  111. return 0;
  112. }