Code Ribbon Pink October
21 views (last 30 days)
Show older comments
Ortalain
on 14 Oct 2024
Moved: Star Strider
on 12 Nov 2024 at 15:10
Hello Family,
As part of Pink October: a month dedicated to raising awareness of breast cancer, which takes place in many countries around the world. It aims to inform the public about the importance of early detection, support breast cancer research, and show solidarity with those affected by the disease.
I'd like to create the “pink ribbon” for this month using MATLAB, to show what's possible. Can someone help me with the code, as I still can't get it right?
The most recent code is :
t = linspace(0, 2*pi, 1000); % Partie supérieure (arc ouvert)
x1 = sin(t);
y1 = cos(t) + 1; % Partie gauche (descente)
x2 = -0.5 + 0.5 * cos(t/2);
y2 = -1 - t/pi; % Partie droite (descente)
x3 = 0.5 - 0.5 * cos(t/2);
y3 = -1 - t/pi;
figure; hold on; % Arc supérieur (boucle du ruban) - non rempli
plot(x1, y1, 'm', 'LineWidth', 5); % Descente gauche
fill(x2, y2, 'm', 'EdgeColor', 'm', 'LineWidth', 5); % Descente droite
fill(x3, y3, 'm', 'EdgeColor', 'm', 'LineWidth', 5);
axis equal; axis off; title('Ruban Rose'); hold off;
0 Comments
Accepted Answer
praguna manvi
on 7 Nov 2024 at 9:03
Here's a snippet to draw a pink ribbon using the “fill” function in MATLAB:
% Set up the figure
figure;
hold on;
axis equal;
axis off;
title('Ruban Rose');
% Define a scale for the ribbon
s = 20;
% Center the ribbon in the plot
xOffset = 0;
yOffset = 0;
% Define the control points for the ribbon and flip the y-coordinates
x = ([0.23, 0.34, 0.50, 0.37, 0.24, 0.22, 0.22, 0.16, 0.00, -0.15, -0.18, -0.18, -0.19, -0.32, -0.44, -0.30, -0.30, -0.22, -0.54, -0.40, -0.01, 0.25, 0.71, 0.23] * s) + xOffset;
y = -([0.14, -0.05, -0.39, -0.65, -0.92, -0.98, -0.98, -1.09, -1.08, -1.07, -0.96, -0.96, -0.94, -0.64, -0.35, -0.02, -0.02, 0.12, 0.90, 1.29, 0.57, 1.09, 1.13, 0.14] * s) + yOffset;
% Draw the ribbon using fill
fill(x, y, [234/255, 128/255, 176/255], 'EdgeColor', 'none', 'FaceAlpha', 0.75);
% Define the control points for the inner part of the ribbon and flip the y-coordinates
x_inner = ([0.12, 0.05, 0.00, 0.00, -0.06, -0.11, -0.16, -0.19, -0.19, -0.13, 0.00, 0.13, 0.23, 0.23, 0.19, 0.12] * s) + xOffset;
y_inner = -([-0.52, -0.39, -0.30, -0.30, -0.39, -0.50, -0.61, -0.75, -0.75, -0.83, -0.84, -0.85, -0.78, -0.78, -0.65, -0.52] * s) + yOffset;
% Draw the inner part of the ribbon
fill(x_inner, y_inner, [234/255, 128/255, 176/255], 'EdgeColor', 'none', 'FaceAlpha', 0.75);
hold off;
1 Comment
More Answers (0)
See Also
Categories
Find more on Biotech and Pharmaceutical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!