形式
C
投稿日時
2020-08-15 10:23
公開期間
無期限
  1. #include "image.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. /* This was used in The Pronoun Game to generate the CRT pattern. */
  6. #define ALPHA 32
  7. #define W 256
  8. #define H 192
  9. int main(int argc, char *argv[]){
  10. struct AImg_Image img;
  11. unsigned x, y;
  12. unsigned c, r, g, b, a;
  13. unsigned char rand_buffer[W * H];
  14. img.w = W;
  15. img.h = H;
  16. img.pixels = malloc(img.w * img.h << 2);
  17. if(argc > 1){
  18. if(sscanf(argv[1], "%i", (int*)x) == 1){
  19. srand(x);
  20. }
  21. else{
  22. printf("Bad seed: %s\n", argv[2]);
  23. return EXIT_FAILURE;
  24. }
  25. }
  26. for(x = 0; x < sizeof(rand_buffer); x++){
  27. rand_buffer[x] = rand();
  28. }
  29. /* Scale the scanlines */
  30. for(y = 0; y < img.h; y++){
  31. for(x = 0; x < img.w; x++){
  32. a = ALPHA;
  33. switch(y & 7){
  34. case 0:
  35. case 2:
  36. /* Draw the faint shading... */
  37. r = g = b = 128;
  38. break;
  39. case 1:
  40. case 5:
  41. /* Draw the strong shading... */
  42. r = g = b = 96;
  43. break;
  44. case 3:
  45. case 4:
  46. /* High Colorize... */
  47. r = g = b = 128;
  48. switch( (x >> 2) % 3){
  49. case 0:
  50. /* Red */
  51. r = 192;
  52. break;
  53. case 1:
  54. /* Green */
  55. g = 192;
  56. break;
  57. case 2:
  58. /* Blue */
  59. b = 192;
  60. break;
  61. }
  62. break;
  63. case 6:
  64. case 7:
  65. /* Low Colorize... */
  66. r = g = b = 96;
  67. a = ALPHA + 16;
  68. switch( (x >> 2) % 3){
  69. case 0:
  70. /* Red */
  71. r = 128;
  72. break;
  73. case 1:
  74. /* Green */
  75. g = 128;
  76. break;
  77. case 2:
  78. /* Blue */
  79. b = 128;
  80. break;
  81. }
  82. break;
  83. }
  84. c = (rand_buffer[(x / 3) + ((y / 5) * W)] & 0xF);
  85. r += c;
  86. g += c;
  87. b += c;
  88. *AImg_Pixel(&img, x, y) = AImg_RGBAToRaw(r, g, b, a);
  89. }
  90. }
  91. AImg_SaveAuto(&img, "crt_filter.png");
  92. AImg_DestroyImage(&img);
  93. return EXIT_SUCCESS;
  94. }
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト