Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- clc
- close all
- %% 0. Parameters of spray pattern
- % There are 2 parameters: spray and spread
- % 0a. Spray is about the 'central' points. This determines where each
- % magazine's bullet goes. For example, if we have a list with 30
- % numbers, the 17-th number of the list determines the position
- % of 17-th bullet in the magazine
- % 0b. Spread is the variation of this 'expected' position.
- % The bullet may not go to this exact expected spot, but in
- % a sligthly altered direction. Ofc, there is a higher
- % possibility the bullet will land close to the 'central'
- % points. More spread means higher possibility for the bullet
- % to be off-target.
- %% 1. Spray
- I = imread('AK47.png');
- % figure();
- % imshow(I);
- figure();
- 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];
- N = size(AK47, 1);
- AK47x = AK47(:, 1);
- AK47y = -AK47(:, 2);
- plot(AK47x, AK47y, 'ro', 'MarkerSize', 8.5);
- hold on
- plot(AK47x, AK47y, 'red');
- title('AK47 Spray Pattern');
- reds = ones(N, 1);
- greens = linspace(225, 0, N)' / 255;
- blues = zeros(N, 1);
- colors = [reds greens blues];
- % Mode 1
- mode1 = 1;
- spread1 = 0;
- bullets1 = spray_and_spread(AK47, N, spread1, mode1);
- % Mode 2
- spread2 = 2.5;
- mode2 = 2;
- bullets2 = spray_and_spread(AK47, N, spread2, mode2);
- % Mode 3
- spread3 = 2.5;
- mode3 = 3;
- bullets3 = spray_and_spread(AK47, N, spread3, mode3);
- % Plots
- plot_patterns(bullets1, bullets2, colors, N);
- title('CSGO vs Standard Spread');
- plot_patterns(bullets1, bullets3, colors, N);
- title('CSGO vs CS2');
- %% 2. Spread
- % There will be 3 modes:
- % 2a. No spread like CSGO
- % 2b. Standard spread in each bullet
- % 2c. Increasing spread like CS2 meaning that shooting consecutive
- % bullets will increase the spread factor in them, so the last ones
- % will experience a higher spread that the first ones
- function bullets = spray_and_spread(AK47, N, spread, mode)
- if(mode == 1)
- % No spread
- offset_x = zeros(N, 1);
- offset_y = zeros(N, 1);
- elseif(mode == 2)
- % Standard spread
- R = spread * rand(N, 1);
- angles = 2*pi * rand(N, 1);
- offset_x = R .* cos(angles);
- offset_y = R .* sin(angles);
- elseif(mode == 3)
- % Increasing spread
- spreads = spread * (1:N)';
- R = spreads .* rand(N, 1);
- angles = 2*pi * rand(N, 1);
- offset_x = R .* cos(angles);
- offset_y = R .* sin(angles);
- else
- % Random spread
- offset_x = randn(N, 1);
- offset_y = randn(N, 1);
- end
- bullets_temp = AK47 + [offset_x offset_y];
- bullets = [bullets_temp(:, 1) -bullets_temp(:, 2)];
- end
- %% Mode vs mode plot
- function plot_patterns(bullets1, bullets2, colors, N)
- x1 = bullets1(:, 1); y1 = bullets1(:, 2);
- x2 = bullets2(:, 1); y2 = bullets2(:, 2);
- figure();
- for i = 1 : N
- plot(x1(i), y1(i), 'Marker', 'o', 'Color', colors(i, :), 'MarkerSize', 8.5);
- hold on
- plot(x2(i), y2(i), 'Marker', 'x', 'Color', colors(i, :), 'MarkerSize', 8.5);
- hold on
- end
- plot(x1, y1, 'black');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement