-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbrewcbsim.ado
180 lines (129 loc) · 6.53 KB
/
brewcbsim.ado
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
********************************************************************************
* Description of the Program - *
* This program is used to preview how a color may be perceived by individuals *
* with varying forms of colorblindness. *
* *
* Dependencies - *
* libbrewscheme - colorblind, cbtype, Protanopia, Deuteranopia, and *
* Tritanopia classes and associated methods. *
* *
* Program Output - *
* *
* Lines - *
* 179 *
* *
********************************************************************************
*! brewcbsim
*! v 1.0.2
*! 10MAY2017
// Drops program if loaded in memory
cap prog drop brewcbsim
// Defines program with R-class property
prog def brewcbsim, rclass
// Version of Stata to use for interpretation of code
version 13.1
// Syntax structure of program
syntax anything(name = colors id = "Red, Green, Blue Color or named color styles")
// Check for brewscheme Mata library
qui: brewlibcheck
// Clear existing returned value
return clear
// Create a new brewcolors object
mata: x = brewcolors()
// Get a list of all named color styles currently installed
mata: x.getNames(1)
// Macro to store constructor for the graph
loc cbsim
// Macro to store the x-labels
loc xlabels
// Macro to define y-axis labels
loc ylabs 10 "Specified" 8 "Achromatopsia" 6 "Protanopia" 4 "Deuteranopia" 2 "Tritanopia"
// Loop over colors passed to program
forv i = 1/`: word count `colors'' {
// Get the token for this iteration
loc color "`: word `i' of `colors''"
// If the argument is only a single word and is a named color style
if `: word count `color'' == 1 & `: list color in colornames' == 1 {
// Get the named color style
mata: x.brewNameSearch("`color'")
// Define baseline points
loc cbbase (scatteri 10 `i' (12) "`rgb'", mlc(black) ms(S) ///
mc("`rgb'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for Achromatopsia
loc achrom (scatteri 8 `i' (12) "`achromatopsia'", mlc(black) ///
ms(S) mc("`achromatopsia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for protanopia
loc protan (scatteri 6 `i' (12) "`protanopia'", mlc(black) ms(S) ///
mc("`protanopia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for deuteranopia
loc deuteran (scatteri 4 `i' (12) "`deuteranopia'", mlc(black) ///
ms(S) mc("`deuteranopia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for tritanopia
loc tritan (scatteri 2 `i' (12) "`tritanopia'", mlc(black) ms(S) ///
mc("`tritanopia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Add the RGB value to a macro to store all the RGB values
loc thebaseline "`rgb'"
// Add the entry to the macro to build the graph command
loc cbsim `cbsim' `cbbase' `achrom' `protan' `deuteran' `tritan'
// The current xaxis label
loc thisxlab `i' "`color'"
// Add xlabel entry
loc xlabels `xlabels' `thisxlab'
} // End IF Block for named color styles
// If the argument is an RGB color string
else if `: word count `color'' == 3 {
// Used to parse/clean/format the string to be passed to the mata
// function on the next line
loc transcolors `: word 1 of `color'' `: word 2 of `color'' `: word 3 of `color''
// Get the translated colors
mata: translateColor(`: subinstr loc transcolors `" "' `", "', all')
// Define baseline points
loc cbbase (scatteri 10 `i' (12) "`baseline'", mlc(black) ms(S) ///
mc("`baseline'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for Achromatopsia
loc achrom (scatteri 8 `i' (12) "`achromatopsia'", mlc(black) ///
ms(S) mc("`achromatopsia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for protanopia
loc protan (scatteri 6 `i' (12) "`protanopia'", mlc(black) ms(S) ///
mc("`protanopia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for deuteranopia
loc deuteran (scatteri 4 `i' (12) "`deuteranopia'", mlc(black) ///
ms(S) mc("`deuteranopia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Define point for tritanopia
loc tritan (scatteri 2 `i' (12) "`tritanopia'", mlc(black) ms(S) ///
mc("`tritanopia'") mlabc(black) msize(5) mlabgap(3) mlabs(vsmall))
// Gets the baseline color passed to the program
loc thebaseline "`baseline'"
// Add the entry to the macro to build the graph command
loc cbsim `cbsim' `cbbase' `achrom' `protan' `deuteran' `tritan'
// The current xaxis label
loc thisxlab `i' "`baseline'"
// Add xlabel entry
loc xlabels `xlabels' `thisxlab'
} // End ELSEIF Block for RGB color strings
// For any other values
else {
// Print error message to the Stata console
di as err "IGNORED: `color' is not a valid named color style or RGB color string."
} // End ELSE Block for invalid arguments
// Add the RGB value to a macro to store all the RGB values
ret loc original`i' `"`thebaseline'"'
// Add the achromatopsia value to a macro for achromatopsia values
ret loc achromatopsic`i' `"`achromatopsia'"'
// Add the protanopia value to a macro for protanopia values
ret loc protanopic`i' `"`protanopia'"'
// Add the deuteranopia value to a macro for deuteranopia values
ret loc deuteranopic`i' `"`deuteranopia'"'
// Add the tritanopia value to a macro for tritanopia values
ret loc tritanopic`i' `"`tritanopia'"'
} // End Loop over the arguments
// Create the graph to show the colors
tw `cbsim', ti("brewscheme - Color Sight Simulator", ///
size(large) c(black) margin(l = 10 r = 10 b = 10 t = 5) span) ///
graphr(ic(white) fc(white) lc(white)) yti("Vision Type") ///
plotr(ic(white) fc(white) lc(white)) legend(off) ///
xlab(`xlabels', labs(vsmall)) ylab(`ylabs', angle(0) labs(small) nogrid) ///
xsca(range(0.5 `= 0.5 + `: word count `colors''')) ///
ysca(range(1.5(1)10.5)) xti("User Specified Colors", margin(t=2))
// End of program definition
end