Created
March 23, 2015 10:10
-
-
Save OrganicIrradiation/2a927ab7f9cfeb1bff78 to your computer and use it in GitHub Desktop.
2D and 3D Perlin Noise in MATLAB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = (cos(s * pi - pi) + 1) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function s = noise3D (m,k) | |
s = zeros([m,m,m]); | |
w = m; | |
i = 0; | |
while w > 3 | |
i = i + 1; | |
d = smooth3(randn([m,m,m]), 'gaussian',k,i); | |
s = s + i * d(1:m, 1:m, 1:m); | |
w = w - ceil(w/2 - 1); | |
end | |
s = (s - min(min(s(:,:)))) ./ (max(max(s(:,:))) - min(min(s(:,:)))); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = (s - min(min(s(:,:)))) ./ (max(max(s(:,:))) - min(min(s(:,:)))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function s = perlin (m) | |
s = zeros(m); # output image | |
w = m; # width of current layer | |
i = 0; # iterations | |
while w > 3 | |
i = i + 1; | |
d = interp2(randn(w), i-1, "spline"); | |
s = s + i * d(1:m, 1:m); | |
w -= ceil(w/2 - 1); | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function s = perlin2D (m) | |
s = zeros([m,m]); % Prepare output image (size: m x m) | |
w = m; | |
i = 0; | |
while w > 3 | |
i = i + 1; | |
d = interp2(randn([m,m]), i-1, 'spline'); | |
s = s + i * d(1:m, 1:m); | |
w = w - ceil(w/2 - 1); | |
end | |
s = (s - min(min(s(:,:)))) ./ (max(max(s(:,:))) - min(min(s(:,:)))); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function s = perlin3D (m) | |
s = zeros([m,m,m]); % Prepare output image (size: m x m x m) | |
w = m; | |
i = 0; | |
while w > 3 | |
i = i + 1; | |
d = interp3(randn([m,m,m]), i-1, 'spline'); | |
s = s + i * d(1:m, 1:m, 1:m); | |
w = w - ceil(w/2 - 1); | |
end | |
s = (s - min(min(s(:,:)))) ./ (max(max(s(:,:))) - min(min(s(:,:)))); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am afraid that this is probably value noise instead of Perlin noise.