You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

144 lines
3.4 KiB

  1. /*
  2. * matrix matrix effect with HDAPS support
  3. * Copyright (c) 2006 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(HAVE_INTTYPES_H)
  16. # include <inttypes.h>
  17. #endif
  18. #if !defined(__KERNEL__)
  19. # include <stdio.h>
  20. # include <math.h>
  21. #endif
  22. #include "cucul.h"
  23. #include "caca.h"
  24. #define MAXDROPS 500
  25. #define MINLEN 15
  26. #define MAXLEN 30
  27. struct drop
  28. {
  29. int x, y, speed, len;
  30. char str[MAXLEN];
  31. }
  32. drop[MAXDROPS];
  33. int main(void)
  34. {
  35. cucul_canvas_t *cv;
  36. caca_display_t *dp;
  37. int i, j;
  38. int w, h, xo, yo, dx = 0, dy = 0, newdx, newdy;
  39. int have_hdaps = 1;
  40. cv = cucul_create_canvas(0, 0);
  41. dp = caca_create_display(cv);
  42. caca_set_display_time(dp, 20000);
  43. for(i = 0; i < MAXDROPS; i++)
  44. {
  45. drop[i].x = cucul_rand(0, 1000);
  46. drop[i].y = cucul_rand(0, 1000);
  47. drop[i].speed = 5 + cucul_rand(0, 30);
  48. drop[i].len = MINLEN + cucul_rand(0, (MAXLEN - MINLEN));
  49. for(j = 0; j < MAXLEN; j++)
  50. drop[i].str[j] = cucul_rand('0', 'z');
  51. }
  52. for(;;)
  53. {
  54. int sensorx = -387, sensory = -387;
  55. /* IBM HDAPS support */
  56. if(have_hdaps)
  57. {
  58. FILE *f = fopen("/sys/devices/platform/hdaps/position", "r");
  59. if(f)
  60. {
  61. fscanf(f, "(%d,%d)", &sensorx, &sensory);
  62. fclose(f);
  63. }
  64. else
  65. have_hdaps = 0;
  66. }
  67. w = cucul_get_canvas_width(cv);
  68. h = cucul_get_canvas_height(cv);
  69. xo = w / 2;
  70. yo = h / 2;
  71. //newdx = 1000.0 * cos((M_PI / 360.0) * (sensorx + 387));
  72. //newdy = -1000.0 * sin((M_PI / 360.0) * (sensorx + 387));
  73. newdx = sensorx + 387;
  74. newdy = 100;
  75. if(newdx > -10 && newdx < 10)
  76. newdx = 0;
  77. dx = (newdx + 3 * dx) / 4;
  78. dy = (newdy + 3 * dy) / 4;
  79. cucul_clear_canvas(cv);
  80. for(i = 0; i < MAXDROPS && i < (w * h / 32); i++)
  81. {
  82. int x, y;
  83. drop[i].y += drop[i].speed;
  84. if(drop[i].y > 1000)
  85. {
  86. drop[i].y -= 1000;
  87. drop[i].x = cucul_rand(0, 1000);
  88. }
  89. x = drop[i].x * w / 1000 / 2 * 2;
  90. y = drop[i].y * (h + MAXLEN) / 1000;
  91. x += (y - h / 2) * dx / dy;
  92. for(j = 0; j < drop[i].len; j++)
  93. {
  94. unsigned int fg;
  95. if(j < 2)
  96. fg = CUCUL_COLOR_WHITE;
  97. else if(j < drop[i].len / 4)
  98. fg = CUCUL_COLOR_LIGHTGREEN;
  99. else if(j < drop[i].len * 4 / 5)
  100. fg = CUCUL_COLOR_GREEN;
  101. else
  102. fg = CUCUL_COLOR_DARKGRAY;
  103. cucul_set_color(cv, fg, CUCUL_COLOR_BLACK);
  104. cucul_putchar(cv, (x * dy + dy / 2 - j * dx) / dy, y - j,
  105. drop[i].str[(y - j) % drop[i].len]);
  106. }
  107. }
  108. caca_refresh_display(dp);
  109. if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0))
  110. break;
  111. }
  112. caca_free_display(dp);
  113. cucul_free_canvas(cv);
  114. return 0;
  115. }