@@ -125,6 +125,30 @@ function shadedplot(
125
125
interpolate= true , axis= (autolimitaspect= 1 ,),)
126
126
end
127
127
128
+ """
129
+ DomainColoring.labsweep(θ)
130
+
131
+ Maps a phase angle **`θ`** to a color in CIE L\\ *a\\ *b\\ * space by
132
+ taking
133
+
134
+ ```math
135
+ \\ begin{aligned}
136
+ L^* &= 67 - 12 \\ cos(3\\ theta), \\\\
137
+ a^* &= 46 \\ cos(\\ theta + .4) - 3, \\ quad\\ text{and} \\\\
138
+ b^* &= 46 \\ sin(\\ theta + .4) - 16.
139
+ \\ end{aligned}
140
+ ```
141
+
142
+ See [Phase Wheel](@ref) for more information.
143
+ """
144
+ function labsweep (θ)
145
+ θ = mod (θ, 2 π)
146
+ Lab (67 - 12 cos (3 θ),
147
+ 46 cos (θ + .4 ) - 3 ,
148
+ 46 sin (θ + .4 ) + 16 )
149
+ end
150
+
151
+ # Grid types supported by _grid
128
152
@enum GridType begin
129
153
CheckerGrid
130
154
LineGrid
@@ -219,6 +243,15 @@ _grid(type, w, arg::Bool) = arg ? _grid(type, w) : 1.0
219
243
220
244
_grid (type, w, arg) = _grid (type, w; rect= arg)
221
245
246
+ # Implements the angle coloring logic for shaders.
247
+ _color_angle (w, arg:: Bool ) = arg ? labsweep (angle (w)) : Lab (80.0 , 0.0 , 0.0 )
248
+
249
+ _color_angle (w, arg:: Function ) = arg (mod (angle (w), 2 π))
250
+
251
+ _color_angle (w, arg:: ColorScheme ) = get (arg, mod (angle (w) / 2 π, 1 ))
252
+
253
+ _color_angle (w, arg:: Symbol ) = _color_angle (w, ColorSchemes. colorschemes[arg])
254
+
222
255
# Implements the magnitude logic for `domaincolorshader`
223
256
# isnothing(transform) gives the default log, and saves us
224
257
# from compiling an anonymous function each call. See `domaincolor`
@@ -228,19 +261,20 @@ function _add_magnitude(
228
261
c;
229
262
base = ℯ,
230
263
transform = nothing ,
231
- sigma = 0.02 ,
264
+ sigma = nothing ,
232
265
)
233
266
234
267
# add magnitude if requested
235
268
if base > 0
236
- if isfinite (base)
269
+ if isfinite (base) && isnothing (sigma)
237
270
if isnothing (transform)
238
271
m = log (base, abs (w))
239
272
else
240
273
m = transform (abs (w))
241
274
end
242
275
isfinite (m) && (c = Lab (c. l + 20 mod (m, 1 ) - 10 , c. a, c. b))
243
276
else
277
+ isnothing (sigma) && (sigma = 0.02 )
244
278
m = log (abs (w))
245
279
t = isfinite (m) ? exp (- sigma* m^ 2 ) : 0.0
246
280
g = 100.0 (m > 0 )
@@ -254,30 +288,9 @@ _add_magnitude(w, c, args::NamedTuple) = _add_magnitude(w, c; args...)
254
288
255
289
_add_magnitude (w, c, arg:: Bool ) = arg ? _add_magnitude (w, c) : c
256
290
257
- _add_magnitude (w, c, arg) = _add_magnitude (w, c, base = arg)
291
+ _add_magnitude (w, c, arg:: Function ) = _add_magnitude (w, c; transform = arg)
258
292
259
- """
260
- DomainColoring.labsweep(θ)
261
-
262
- Maps a phase angle **`θ`** to a color in CIE L\\ *a\\ *b\\ * space by
263
- taking
264
-
265
- ```math
266
- \\ begin{aligned}
267
- L^* &= 67 - 12 \\ cos(3\\ theta), \\\\
268
- a^* &= 46 \\ cos(\\ theta + .4) - 3, \\ quad\\ text{and} \\\\
269
- b^* &= 46 \\ sin(\\ theta + .4) - 16.
270
- \\ end{aligned}
271
- ```
272
-
273
- See [Phase Wheel](@ref) for more information.
274
- """
275
- function labsweep (θ)
276
- θ = mod (θ, 2 π)
277
- Lab (67 - 12 cos (3 θ),
278
- 46 cos (θ + .4 ) - 3 ,
279
- 46 sin (θ + .4 ) + 16 )
280
- end
293
+ _add_magnitude (w, c, arg) = _add_magnitude (w, c; base= arg)
281
294
282
295
"""
283
296
DomainColoring.domaincolorshader(
@@ -307,8 +320,13 @@ function domaincolorshader(
307
320
(grid isa Bool) && (grid = true )
308
321
end
309
322
323
+ # short circuit conversions
324
+ if (abs isa Bool) && ! abs && (grid isa Bool) && ! grid
325
+ return _color_angle (w, angle)
326
+ end
327
+
310
328
# phase color
311
- c = angle ? labsweep (Base . angle (w)) : Lab ( 80.0 , 0.0 , 0.0 )
329
+ c = convert ( Lab, _color_angle (w, angle) )
312
330
313
331
# add magnitude
314
332
c = _add_magnitude (w, c, abs)
@@ -355,7 +373,8 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
355
373
real and imaginary axis, taking the same for both if only one number
356
374
is provided.
357
375
358
- - **`angle`** toggles coloring of the phase angle.
376
+ - **`angle`** toggles coloring of the phase angle. Can also be set to
377
+ either the name of, or a `ColorScheme`, or a function `θ -> Color`.
359
378
360
379
- **`abs`** toggles the plotting of the natural logarithm of the
361
380
magnitude as lightness ramps between level curves. If set to a number,
@@ -365,7 +384,7 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
365
384
parameters `base`, `transform`, or `sigma`. `base` changes the base of
366
385
the logarithm, as before. `transform` is the function applied to the
367
386
magnitude (`m -> log(base, m)` by default), and `sigma` changes the
368
- rate at which zeros and poles are colored when `base = Inf`.
387
+ rate at which zeros and poles are colored and implies `base = Inf`.
369
388
370
389
- **`grid`** plots points with integer real or imaginary part as black
371
390
dots. More complicated arguments can be passed as a named tuple in a
0 commit comments