Transparancy in overlapping circles
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have this functions (number of circles, how large the circles are(1,2)) that makes cicles in a image. But the circles now just overlap. I need them to be transparent. White circles need to make other circles more white and black more black. Help please, i'm stuck.
function [out] = bolle(aantal,grootte)
%%%%%%%%%%%%%%%%%%%%%%Maken van grijze achtergrond %%%%%%%%%%%%%%%%%%%%%%
white = ones(1000) ; % witte achtergrond 1000x1000
gray = 128 ; % grijze kleur
grayback = gray * white ; % achtergrond grijs maken
rad = 25 - grootte * 10 ; % instelbare grootte cirkels
back = grayback ;
back1 = back ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%Cirkels toevoegen %%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:aantal
xgr = size(back,1) ; % grootte x as achtergrond
ygr = size(back,2) ; % grootte y as achtergrond
Xmidden = floor(xgr * rand()) ; % willekeurig midden cirkel x
Ymidden = floor(ygr * rand()) ; % willekeurig midden cirkel y
Kleur = floor(255 * rand()) ; % willekeurig kleur cirkel
Radius = max(xgr,ygr) / rad * rand() ; % grootte cirkel
circle = bsxfun(@(x,y) (x - Xmidden).^2 + (y - Ymidden).^2 <= Radius.^2, (1:xgr).', 1:ygr) ; %cirkel
back(circle) = Kleur ; %cirkel invoegen
end
%%%%%%%%%%%%%%%%%%%%%%%%Plaatje laten zien %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pos(back)% put object on screen
0 commentaires
Réponses (1)
Walter Roberson
le 16 Mai 2012
That cannot be done with a single image array, not unless you do the transparency calculations yourself.
The easiest way to draw a circle in an axes is to use the rectangle() call (yes, seriously). You can specify the color and transparency of each rectangle.
You can also construct edges of a circle and patch() the circle into place, specifying a FaceColor and specifying AlphaData.
The above two methods build one object per circle, each with its alpha array, and then uses OpenGL to handle the transparency. (OpenGL is the only renderer that can do transparency.)
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!