Skip to content

Instantly share code, notes, and snippets.

@OrganicIrradiation
Created March 23, 2015 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OrganicIrradiation/34f1fc4355bb76ef5fd5 to your computer and use it in GitHub Desktop.
Save OrganicIrradiation/34f1fc4355bb76ef5fd5 to your computer and use it in GitHub Desktop.
3D MATLAB noise (continued)
function s = noise3Dwrap (m,k)
s = zeros([m*3,m*3,m*3]);
w = m;
i = 0;
while w > 3
i = i + 1;
randArray = randn([m,m,m],'single');
randArray = repmat(randArray,[3 3 3]);
d = smooth3(randArray, 'gaussian',k,i);
s = s + i * d(1:(m*3), 1:(m*3), 1:(m*3));
w = w - ceil(w/2 - 1);
fprintf('%f\n',w)
end
s = s(m:(2*m-1),m:(2*m-1),m:(2*m-1));
s = (s - min(min(s(:,:)))) ./ (max(max(s(:,:))) - min(min(s(:,:))));
s = uint8(s.*255);
end
for v = 64:64:256
% Load texture
load(['noise3Dwrap' num2str(v) '.mat'])
for t = 1:2
if t == 1
theNoise = noiseStandard;
elseif t == 2
theNoise = noiseComparison;
end
% Generate GIF
imwrite(reshape(noiseStandard,[i i 1 i]),['noise3Dwrap' num2str(v) '-' num2str(t) '.gif'],'LoopCount',Inf,'DelayTime',0.10)
% Generate Video
writerObj = VideoWriter(['noise3Dwrap' num2str(v) '-' num2str(t) '.avi'],'Uncompressed AVI');
open(writerObj);
for k = 1:i
frame = noiseStandard(:,:,k);
writeVideo(writerObj,frame);
end
close(writerObj);
% Generate Poster (with black border for 16:9 widescreen display)
buffer = round((size(noiseStandard(:,:,1),2)*1.7777778-size(noiseStandard(:,:,1),2))/2);
poster = [zeros(size(noiseStandard(:,:,1),1),buffer),noiseStandard(:,:,1),zeros(size(noiseStandard(:,:,1),1),buffer)];
imwrite(poster,['noise3Dwrap' num2str(v) '-' num2str(t) '.png'])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment