Create output of rectangles with 200 different colours
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi , I have been asked to create 200 different output of rectangles, all with different colours. Thank you in advacne for help
0 Kommentare
Antworten (2)
Adam Danz
am 18 Aug. 2021
Bearbeitet: Adam Danz
am 18 Aug. 2021
pos is a 1x4 vector defining [LeftSide, BottomSide, Width, Height].
See the FaceColor and EdgeColor name-values pairs to control color.
You could call it in a loop to produce multiple rectangles.
hold on
for i = 1:20
rectangle('position', rand(1,4).*randi(5,1,4), ...
'FaceColor', rand(1,3), 'EdgeColor','k')
end
axis tight
axis equal
0 Kommentare
DGM
am 18 Aug. 2021
Bearbeitet: DGM
am 19 Aug. 2021
Adam already covered the sensible solution. I'll post my own.
MIMT randspots() generates an image containing random colored shapes:
% create a 800x1000 image containing 200 rectangles
% blob dimensions vary between 20-60 px
% blob opacity varies between 10-80%
A = randspots([800 1000 3],200,[20 60],[0.1 0.8],'rectangle');
I've been meaning to rewrite it, but I haven't bothered yet. The syntax is clumsy, but it works.
If neither of these solutions are what you're after, then you'll need to be more specific.
EDIT:
Ah. I guess if you're working from a color table, then randspots doesn't apply. As the name implies, all it can do is random.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!