Skip to content

Commit 4cef8ce

Browse files
committed
Added further options to angle and abs arguments
1 parent 7cac420 commit 4cef8ce

File tree

5 files changed

+72
-37
lines changed

5 files changed

+72
-37
lines changed

DomainColoringToy/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DomainColoringToy"
22
uuid = "7cf40ad8-af6a-4ede-b3c6-2a9df3bce851"
33
authors = ["Evert Provoost <evert@eprovst.net>"]
4-
version = "0.3.0"
4+
version = "0.3.1"
55

66
[deps]
77
DomainColoring = "c24f3079-adb7-4533-8329-9f66732e5e85"

DomainColoringToy/src/DomainColoringToy.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
138138
for both if only one number is provided. If either is `:auto`, the
139139
viewport resolution is used.
140140
141-
- **`angle`** toggles coloring of the phase angle.
141+
- **`angle`** toggles coloring of the phase angle. Can also be set to
142+
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
142143
143144
- **`abs`** toggles the plotting of the natural logarithm of the
144145
magnitude as lightness ramps between level curves. If set to a number,

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DomainColoring"
22
uuid = "c24f3079-adb7-4533-8329-9f66732e5e85"
33
authors = ["Evert Provoost <evert@eprovst.net>"]
4-
version = "0.5.0"
4+
version = "0.5.1"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

docs/src/usage/general.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,18 @@ nothing # hide
178178
![](dcordermag.png)
179179

180180
If one does not want to look at the logarithm of the magnitude, but the
181-
magnitude itself, they can use the `transform` option, for instance:
181+
magnitude itself, they can use the `transform` option, or pass a
182+
function directly to `abs`, for instance:
182183
```@example
183184
using CairoMakie, DomainColoring # hide
184-
domaincolor(sqrt, (-1, 20, -5, 5), abs=(transform=z->z,))
185+
domaincolor(sqrt, (-1, 20, -5, 5), abs=z->z)
185186
save("dclinmag.png", current_figure()) # hide
186187
nothing # hide
187188
```
188189
![](dclinmag.png)
189190

190191
Finally, if we set the base to `Inf`, the magnitude is colored from
191-
black from zero to white at infinity, which we can use to illustrate the
192+
black at zero to white at infinity, which we can use to illustrate the
192193
Casorati–Weierstrass theorem:
193194
```@example
194195
using CairoMakie, DomainColoring # hide
@@ -201,8 +202,22 @@ nothing # hide
201202
The harshness of these white an black areas can be changed using the
202203
`sigma` parameter, try for instance:
203204
```julia
204-
domaincolor(z -> exp(1/z), .1, abs=(base=Inf, sigma=0.001))
205+
domaincolor(z -> exp(1/z), .1, abs=(sigma=0.001,))
205206
```
206207

207-
Finally, if one wants any of the previous plots without coloring the
208-
phase angle, they can use `angle = false`.
208+
If one wants to change the coloring of the phase angle, they can pass a
209+
`ColorScheme` (as an object or by name, see [their
210+
documentation](https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/))
211+
or a function `θ -> Color`, to `angle`. As an example of the latter, we
212+
can add a discretization effect:
213+
```@example
214+
using CairoMakie, DomainColoring # hide
215+
discrangle(θ) = DomainColoring.labsweep(π/10 * floor(10/π * θ))
216+
domaincolor(tan, angle=discrangle)
217+
save("dscangle.png", current_figure()) # hide
218+
nothing # hide
219+
```
220+
![](dscangle.png)
221+
222+
Finally, if no coloring of the phase is wanted, we can set
223+
`angle = false`.

src/DomainColoring.jl

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ function shadedplot(
125125
interpolate=true, axis=(autolimitaspect=1,),)
126126
end
127127

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 - 12cos(3θ),
147+
46cos+ .4) - 3,
148+
46sin+ .4) + 16)
149+
end
150+
151+
# Grid types supported by _grid
128152
@enum GridType begin
129153
CheckerGrid
130154
LineGrid
@@ -219,6 +243,15 @@ _grid(type, w, arg::Bool) = arg ? _grid(type, w) : 1.0
219243

220244
_grid(type, w, arg) = _grid(type, w; rect=arg)
221245

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+
222255
# Implements the magnitude logic for `domaincolorshader`
223256
# isnothing(transform) gives the default log, and saves us
224257
# from compiling an anonymous function each call. See `domaincolor`
@@ -228,19 +261,20 @@ function _add_magnitude(
228261
c;
229262
base = ℯ,
230263
transform = nothing,
231-
sigma = 0.02,
264+
sigma = nothing,
232265
)
233266

234267
# add magnitude if requested
235268
if base > 0
236-
if isfinite(base)
269+
if isfinite(base) && isnothing(sigma)
237270
if isnothing(transform)
238271
m = log(base, abs(w))
239272
else
240273
m = transform(abs(w))
241274
end
242275
isfinite(m) && (c = Lab(c.l + 20mod(m, 1) - 10, c.a, c.b))
243276
else
277+
isnothing(sigma) && (sigma = 0.02)
244278
m = log(abs(w))
245279
t = isfinite(m) ? exp(-sigma*m^2) : 0.0
246280
g = 100.0(m > 0)
@@ -254,30 +288,9 @@ _add_magnitude(w, c, args::NamedTuple) = _add_magnitude(w, c; args...)
254288

255289
_add_magnitude(w, c, arg::Bool) = arg ? _add_magnitude(w, c) : c
256290

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)
258292

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 - 12cos(3θ),
278-
46cos+ .4) - 3,
279-
46sin+ .4) + 16)
280-
end
293+
_add_magnitude(w, c, arg) = _add_magnitude(w, c; base=arg)
281294

282295
"""
283296
DomainColoring.domaincolorshader(
@@ -307,8 +320,13 @@ function domaincolorshader(
307320
(grid isa Bool) && (grid = true)
308321
end
309322

323+
# short circuit conversions
324+
if (abs isa Bool) && !abs && (grid isa Bool) && !grid
325+
return _color_angle(w, angle)
326+
end
327+
310328
# phase color
311-
c = angle ? labsweep(Base.angle(w)) : Lab(80.0, 0.0, 0.0)
329+
c = convert(Lab, _color_angle(w, angle))
312330

313331
# add magnitude
314332
c = _add_magnitude(w, c, abs)
@@ -355,7 +373,8 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
355373
real and imaginary axis, taking the same for both if only one number
356374
is provided.
357375
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`.
359378
360379
- **`abs`** toggles the plotting of the natural logarithm of the
361380
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
365384
parameters `base`, `transform`, or `sigma`. `base` changes the base of
366385
the logarithm, as before. `transform` is the function applied to the
367386
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`.
369388
370389
- **`grid`** plots points with integer real or imaginary part as black
371390
dots. More complicated arguments can be passed as a named tuple in a

0 commit comments

Comments
 (0)