-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowerPetal.m
117 lines (104 loc) · 4.72 KB
/
FlowerPetal.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function [petal, ladyBack, ladySpot, ladyHead, ladyEye, ladyAntenna] = FlowerPetal(petalMiddleRad)
% This function makes a petal that should attach to the edge of the center of the
% flower. The petalMiddleRad is the radians from the rightmost part of the
% circle at which place the center of the petal should approximately fall.
% The number of petals the flower will have are the number of entries in
% the petalMiddleRad input vector.
%
% To make the artwork have a more 'naturally messy' appearance and because it is
% cool, the petals of the flower will not be placed exactly as specified in
% petalMiddleRad but some noise will be added to the location of their
% center.
%
% Function written by Sven Wientjes s2677105
% Noise vector for petal attach locations:
petalNoiseCenter = datasample(-0.08:0.005:0.08, length(petalMiddleRad));
%% Create a ladybug body on the third petal
% We do this before the actual petals so the petals will overlap it
ladyButt = [cos(petalMiddleRad(3)+petalNoiseCenter(3)-0.3)*7.5+3 ...
sin(petalMiddleRad(3)+petalNoiseCenter(3)-0.3)*7.5+3];
ladyFront = [cos(petalMiddleRad(3)+petalNoiseCenter(3)-0.1)*9+3 ...
sin(petalMiddleRad(3) + petalNoiseCenter(3)-0.1)*9+3];
ladyDiameter = sqrt( (ladyFront(1)-ladyButt(1)).^2 + ...
(ladyFront(2)-ladyButt(2)).^2);
ladyMiddle = [(ladyButt(1)+ladyFront(1))/2, (ladyButt(2)+ladyFront(2))/2];
xpos = ladyMiddle(1) - ladyDiameter/2;
ypos = ladyMiddle(2) - ladyDiameter/2;
ladyBack = rectangle('Position', [xpos ypos ladyDiameter ladyDiameter], ...
'Curvature', [1 1], 'EdgeColor', 'r', 'FaceColor', 'r');
%% Create spots on the ladybug body
% Randomly, black spots will be created on the ladybug body that must fall
% within a square within the circular ladybug body. The square is 'shrunk'
% by the maximum possible diameter for the spots.
nSpots = datasample(3:12, 1);
spotIndex = 0;
xLims = [cos(0.75*pi)*ladyDiameter/2+ladyMiddle(1), ...
cos(0.25*pi)*ladyDiameter/2+ladyMiddle(1)-0.3];
yLims = [sin(1.25*pi)*ladyDiameter/2+ladyMiddle(2), ...
sin(0.75*pi)*ladyDiameter/2+ladyMiddle(2)-0.3];
while spotIndex < nSpots
spotDiameter = datasample(0.2:0.01:0.3, 1);
xLoc = datasample(xLims(1):0.05:xLims(2), 1);
yLoc = datasample(yLims(1):0.05:yLims(2), 1);
ladySpot = rectangle('Position', [xLoc yLoc spotDiameter spotDiameter], ...
'Curvature', [1 1], 'EdgeColor', 'k', 'FaceColor', 'k');
spotIndex = spotIndex + 1;
end
%% Create the petals!
for i = petalMiddleRad+petalNoiseCenter
petal = patch([cos(i+0.5)*3.5+3, ...
cos(i+0.45)*4.3+3, ...
cos(i+0.35)*6+3, ...
cos(i+0.3)*7.5+3, ...
cos(i+0.2)*8.5+3, ...
cos(i+0.1)*9+3, ...
cos(i-0.1)*9+3, ...
cos(i-0.2)*8.5+3, ...
cos(i-0.3)*7.5+3, ...
cos(i-0.35)*6+3, ...
cos(i-0.45)*4.3+3, ...
cos(i-0.5)*3.5+3], ...
[sin(i+0.5)*3.5+3, ...
sin(i+0.45)*4.3+3, ...
sin(i+0.35)*6+3, ...
sin(i+0.3)*7.5+3, ...
sin(i+0.2)*8.5+3, ...
sin(i+0.1)*9+3, ...
sin(i-0.1)*9+3, ...
sin(i-0.2)*8.5+3, ...
sin(i-0.3)*7.5+3, ...
sin(i-0.35)*6+3, ...
sin(i-0.45)*4.3+3, ...
sin(i-0.5)*3.5+3],...
[77,77,255]/255);
end
%% Create the ladybug head, eyes & antennas
% Make the head
ladyHeadMiddle = [cos(0.7*pi)*ladyDiameter/2+ladyMiddle(1) ...
sin(0.7*pi)*ladyDiameter/2+ladyMiddle(2)];
ladyHeadDiameter = datasample(0.9:0.01:1.1, 1);
xHead = ladyHeadMiddle(1) - ladyHeadDiameter/2;
yHead = ladyHeadMiddle(2) - ladyHeadDiameter/2;
ladyHead = rectangle('Position', [xHead yHead ladyHeadDiameter ladyHeadDiameter], ...
'Curvature', [1 1], 'EdgeColor', 'k', 'FaceColor', 'k');
% Make two eyes
eyeDiameter = 0.2;
for i = [0.25*pi 0.75*pi]
eyeMiddle = [cos(i)*ladyHeadDiameter/3+ladyHeadMiddle(1) ...
sin(i)*ladyHeadDiameter/3+ladyHeadMiddle(2)];
xEye = eyeMiddle(1) - eyeDiameter/2;
yEye = eyeMiddle(2) - eyeDiameter/2;
ladyEye = rectangle('Position', [xEye yEye eyeDiameter eyeDiameter] ...
,'Curvature', [1 1], 'EdgeColor', 'w', 'FaceColor', 'w');
% Make two antennae
for i = [0.25*pi 0.75*pi]
ladyAntenna = patch([cos(i)* ladyHeadDiameter/2+ ladyHeadMiddle(1) ...
cos(i)* ladyHeadDiameter/2*1.5+ ladyHeadMiddle(1), ...
cos(i-0.2)* ladyHeadDiameter/2*1.5+ ladyHeadMiddle(1), ...
cos(i-0.2)* ladyHeadDiameter/2+ ladyHeadMiddle(1)], ...
[sin(i)* ladyHeadDiameter/2+ ladyHeadMiddle(2), ...
sin(i)* ladyHeadDiameter/2*1.5+ ladyHeadMiddle(2), ...
sin(i-0.2)* ladyHeadDiameter/2*1.5+ ladyHeadMiddle(2), ...
sin(i-0.2)* ladyHeadDiameter/2+ ladyHeadMiddle(2)], 'y');
end
end