Advertisement
makispaiktis

AK47 Spray Pattern

Jan 29th, 2024 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. clear all
  2. clc
  3. close all
  4.  
  5. %% 0. Parameters of spray pattern
  6. % There are 2 parameters: spray and spread
  7. % 0a. Spray is about the 'central' points. This determines where each
  8. % magazine's bullet goes. For example, if we have a list with 30
  9. % numbers, the 17-th number of the list determines the position
  10. % of 17-th bullet in the magazine
  11. % 0b. Spread is the variation of this 'expected' position.
  12. % The bullet may not go to this exact expected spot, but in
  13. % a sligthly altered direction. Ofc, there is a higher
  14. % possibility the bullet will land close to the 'central'
  15. % points. More spread means higher possibility for the bullet
  16. % to be off-target.
  17.  
  18.  
  19.  
  20. %% 1. Spray
  21. I = imread('AK47.png');
  22. % figure();
  23. % imshow(I);
  24. figure();
  25. AK47 = [206 780; 211 764; 207 701; 212 589; 221 477; 180 366; 151 268; 98 192; 160 135; 315 157; 339 97; 386 134; 401 89; 486 119; 495 98; 363 89; 293 58; 235 34; 144 36; 106 37; 80 60; 22 74; 92 75; 60 37; 51 27; 113 17; 131 28; 236 30; 388 94; 443 92];
  26. N = size(AK47, 1);
  27. AK47x = AK47(:, 1);
  28. AK47y = -AK47(:, 2);
  29. plot(AK47x, AK47y, 'ro', 'MarkerSize', 8.5);
  30. hold on
  31. plot(AK47x, AK47y, 'red');
  32. title('AK47 Spray Pattern');
  33. reds = ones(N, 1);
  34. greens = linspace(225, 0, N)' / 255;
  35. blues = zeros(N, 1);
  36. colors = [reds greens blues];
  37.  
  38. % Mode 1
  39. mode1 = 1;
  40. spread1 = 0;
  41. bullets1 = spray_and_spread(AK47, N, spread1, mode1);
  42.  
  43. % Mode 2
  44. spread2 = 2.5;
  45. mode2 = 2;
  46. bullets2 = spray_and_spread(AK47, N, spread2, mode2);
  47.  
  48. % Mode 3
  49. spread3 = 2.5;
  50. mode3 = 3;
  51. bullets3 = spray_and_spread(AK47, N, spread3, mode3);
  52.  
  53. % Plots
  54. plot_patterns(bullets1, bullets2, colors, N);
  55. title('CSGO vs Standard Spread');
  56. plot_patterns(bullets1, bullets3, colors, N);
  57. title('CSGO vs CS2');
  58.  
  59.  
  60. %% 2. Spread
  61. % There will be 3 modes:
  62. % 2a. No spread like CSGO
  63. % 2b. Standard spread in each bullet
  64. % 2c. Increasing spread like CS2 meaning that shooting consecutive
  65. % bullets will increase the spread factor in them, so the last ones
  66. % will experience a higher spread that the first ones
  67.  
  68. function bullets = spray_and_spread(AK47, N, spread, mode)
  69.  
  70. if(mode == 1)
  71. % No spread
  72. offset_x = zeros(N, 1);
  73. offset_y = zeros(N, 1);
  74. elseif(mode == 2)
  75. % Standard spread
  76. R = spread * rand(N, 1);
  77. angles = 2*pi * rand(N, 1);
  78. offset_x = R .* cos(angles);
  79. offset_y = R .* sin(angles);
  80. elseif(mode == 3)
  81. % Increasing spread
  82. spreads = spread * (1:N)';
  83. R = spreads .* rand(N, 1);
  84. angles = 2*pi * rand(N, 1);
  85. offset_x = R .* cos(angles);
  86. offset_y = R .* sin(angles);
  87. else
  88. % Random spread
  89. offset_x = randn(N, 1);
  90. offset_y = randn(N, 1);
  91. end
  92.  
  93. bullets_temp = AK47 + [offset_x offset_y];
  94. bullets = [bullets_temp(:, 1) -bullets_temp(:, 2)];
  95.  
  96. end
  97.  
  98.  
  99.  
  100. %% Mode vs mode plot
  101. function plot_patterns(bullets1, bullets2, colors, N)
  102.  
  103. x1 = bullets1(:, 1); y1 = bullets1(:, 2);
  104. x2 = bullets2(:, 1); y2 = bullets2(:, 2);
  105. figure();
  106. for i = 1 : N
  107. plot(x1(i), y1(i), 'Marker', 'o', 'Color', colors(i, :), 'MarkerSize', 8.5);
  108. hold on
  109. plot(x2(i), y2(i), 'Marker', 'x', 'Color', colors(i, :), 'MarkerSize', 8.5);
  110. hold on
  111. end
  112. plot(x1, y1, 'black');
  113.  
  114. end
  115.  
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement