Advertisement
Guest User

vizimpacts.m

a guest
Apr 10th, 2013
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function vizimpacts
  2.  
  3. res = 70;
  4.  
  5. guns = {'ak47', 'aug', 'awp', 'bizon', 'deagle', 'elite', 'famas', 'fiveseven', 'g3sg1', 'galilar', 'glock', 'hkp2000', 'm249', 'm4a1', 'mac10', 'mag7', 'mp7', 'mp9', 'negev', 'nova', 'p250', 'p90', 'sawedoff', 'scar20', 'sg556', 'ssg08', 'tec9', 'ump45', 'xm1014'};
  6. bullets = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 1 1 1 9 1 1 9 1 1 1 1 1 6];
  7. clipsize = [30 30 10 64 7 30 25 20 20 35 20 13 100 30 30 5 30 30 150 8 13 50 7 20 30 10 32 25 7];
  8. cycletime = [0.1 0.09 1.455 0.08 0.225 0.12 0.09 0.15 0.25 0.09 0.15 0.17 0.08 0.09 0.075 0.65 0.08 0.07 0.06 0.88 0.15 0.07 0.85 0.25 0.09 1.25 0.12 0.090 0.25];
  9.  
  10. for i=1:length(guns)
  11.     % subtract the position of the first bullet from the rest of the bullets in the mag
  12.     data = load(['data/nospread/weapon_' guns{i} '-stand.txt']);
  13.     data = data(1:bullets(i):end,4:5);
  14.     data = bsxfun(@minus,data,data(1,:));
  15.     % invert the horizontal axis to make it consistent with the player's view
  16.     data(:,1) = -data(:,1);
  17.  
  18.     hf = figure('InvertHardCopy','off','Color',[0.3 0.3 0.3]);
  19.  
  20.     % background text
  21.     axes('Position',[0 0 1 1]);
  22.     axis off;
  23.     text(0,0,guns{i},'Units','normalized','Color',[0.4 0.4 0.4],'FontWeight','bold','FontName','Tahoma','FontSize',70,'VerticalAlignment','bottom','HorizontalAlignment','left');
  24.  
  25.     % plot impacts
  26.     axes;
  27.     axis image;
  28.     axis off;
  29.  
  30.     % axis limits
  31.     xlim([-110 110]);
  32.     ylim([-5 300]);
  33.  
  34.     hold on;
  35.     line([0 0],[-5 300],'Color',[0.4 0.4 0.4],'LineWidth',5);
  36.     colors = [linspace(1,1,clipsize(i)); linspace(1,0,clipsize(i)); linspace(0,0,clipsize(i))]';
  37.     for j=1:clipsize(i)
  38.         scatter(data(j,1),data(j,2),100,'MarkerEdgeColor',colors(j,:),'MarkerFaceColor',colors(j,:));
  39.  
  40.         % save as image
  41.         fn = sprintf('images/%s-%03d.png',guns{i},j);
  42.         print(hf,'-dpng',['-r' num2str(res)],fn);
  43.     end
  44.  
  45.     close(hf);
  46.  
  47.     % build animation using ImageMagick and remove the intermediate images
  48.     system(sprintf('convert \\( -delay %d images/%s-*.png \\) \\( -delay 200 images/%s-%03d.png \\) images/%s.gif',round(cycletime(i)*100),guns{i},guns{i},clipsize(i),guns{i}));
  49.     delete(sprintf('images/%s-*.png',guns{i}));
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement