drawing clouds background* in matlab?
7 次查看(过去 30 天)
显示 更早的评论
hi everyone, i started using matlab about 3 months ago and am just aware of the basic computing i.e. for loops , while loops, if conditions. i have been given a game as a project. i was thinking of drawing its graphics first. i wanted to draw moving clouds in the background. i do not know any function to draw this nor could i think of any way to somehow create my own function. kindly help me in doing that. regards, khurram
0 个评论
回答(2 个)
Jan
2012-4-10
You can draw an image in an axes object:
AxesH = axes('Units', 'normalized', 'Position', [0, 0, 1, 1]);
img = imread('clouds.jpg'); % <- your file name here
image(img, 'Parent', AxesH);
Now you can crop the wanted rectangle from the loaded image, e.g. by:
moved = img(1:200, 1:300)
Image Analyst
2012-4-10
Try this demo. I wrote it using Peter Kovesi's program. Be sure to download his m-file like my instructions say to. This program will generate cloud images one at a time until you say quit.
% Demo to make cloud-like images.
% Uses the noiseonf routine of Peter Kovesi:
% Copyright (c) 1996-2005 Peter Kovesi
% School of Computer Science & Software Engineering
% The University of Western Australia
% http://www.csse.uwa.edu.au/
% You can download noiseonf.m here:
% http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/Misc/noiseonf.m
clc;
close all;
workspace;
clear;
fontSize = 16;
index = 1;
for h = 0.5:.1:3
%===============================================
% Create the image.
% THIS IS THE KEY PART!
grayImage = noiseonf(800, 1.7);
%===============================================
% Display it
imshow(grayImage, []);
% Enlarge figure to full screen.
% Need to re-enlarge it every single time for some reason.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Clouds Demo','numbertitle','off')
if index == 1
promptMessage = sprintf('I will show you images like this one.\nClick Accept when you see an image you like.');
button = questdlg(promptMessage, 'Instructions', 'Continue. Try Another', 'Accept this one', 'Quit Program', 'Continue. Try Another');
if strcmpi(button, 'Accept this one') > 0
break;
elseif strcmpi(button, 'Quit Program') > 0
close all;
return;
end
index = index + 1;
else
promptMessage = sprintf('This is h = %.1f', h);
title(promptMessage, 'FontSize', fontSize);
button = questdlg(promptMessage, 'Instructions', 'Continue. Try Another', 'Accept', 'Quit Program', 'Continue. Try Another');
if strcmpi(button, 'Accept') > 0
break;
elseif strcmpi(button, 'Quit Program') > 0
return;
end
end
end
% Convert to a uint8 (8 bit gray scale) image.
% grayImage = uint8(255 * mat2gray(grayImage));
uiwait(msgbox('Done with demo!'));
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!