amroamroamro

intxor

May 3rd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.66 KB | None | 0 0
  1. % https://www.reddit.com/r/dataisbeautiful/comments/8gltik/3d_plot_of_the_bitwise_xor_of_integers_32_to_32/
  2. % https://imgur.com/wbnRfyO
  3.  
  4. % plot
  5. [X,Y] = meshgrid(-32:32);
  6. Z = bitxor(X, Y, 'int32');
  7. scatter3(X(:), Y(:), Z(:), 12, '.')
  8. axis vis3d tight, box on
  9.  
  10. % animation
  11. createGIF('out.gif', gcf)
  12. for i=1:120
  13.     camorbit(3, 0)
  14.     drawnow
  15.     createGIF('out.gif', gcf)
  16. end
  17.  
  18. function createGIF(fname, h)
  19.     [im, map] = rgb2ind(frame2im(getframe(h)), 256);
  20.     if exist(fname, 'file') == 2
  21.         opts = {'WriteMode','append'};
  22.     else
  23.         opts = {'LoopCount',Inf};
  24.     end
  25.     imwrite(im, map, fname, 'gif', 'DelayTime',1/25, opts{:});
  26. end
Add Comment
Please, Sign In to add comment