Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

To implement datenwolfdatenwolf's suggestion to perturb curves with Perlin noise to give that "hand-drawn" look and feel, here's one way to use one-dimensional Perlin noise for the perturbation:

fBm = With[{permutations = Apply[Join, ConstantArray[RandomSample[Range[0, 255]], 2]]}, Compile[{{x, _Real}}, Module[{xf = Floor[x], xi, xa, u, i, j}, xi = Mod[xf, 16] + 1; xa = x - xf; u = xa*xa*xa*(10.0 + xa*(xa*6.0 - 15.0)); i = permutations[[permutations[[xi]] + 1]]; j = permutations[[permutations[[xi + 1]] + 1]]; (2 Boole[OddQ[i]] - 1)*xa*(1.0 - u) + (2 Boole[OddQ[j]] - 1)*(xa - 1)*u], "CompilationTarget" -> "WVM", RuntimeAttributes -> {Listable}]]; handdrawn[fun_, fr_, divisor_, color_, at_] := Graphics[{Directive[color, AbsoluteThickness[at]], BSplineCurve[Table[fun@x + fBm[fr x]/(5 divisor), {x, 0.01, 10, .1}]]}] 

I had previously used the one-dimensional Perlin noise routine in this answerthis answer.

In any event, here's a stripped-down version of chris's plot:

Show[ handdrawn[{#, 1.5 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 5)^2/2]} &, 30, 3, Darker[Cyan, 0.3], 3], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, White, 8], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, Darker[Red, 0.3], 3], handdrawn[{1, #} &, 30, 4, Black, 3], handdrawn[{#, 1} &, 30, 4, Black, 3], PlotRange -> All] 

xkcd-style curves

As a bonus, here's a "hand-drawn" arrow routine you can use:

hArrow[{p_, q_}, fr_, divisor_] := Arrow[BSplineCurve[Table[p (1 - u) + q u + RotationMatrix[Arg[#1 + I #2] & @@ (p - q)].{u, fBm[fr u]/(5 divisor)}, {u, 0, 1, 1/50}]]] 

Replicating the comic strip in the OP with these routines (along with using the "Humor Sans" font) is left as an exercise.

To implement datenwolf's suggestion to perturb curves with Perlin noise to give that "hand-drawn" look and feel, here's one way to use one-dimensional Perlin noise for the perturbation:

fBm = With[{permutations = Apply[Join, ConstantArray[RandomSample[Range[0, 255]], 2]]}, Compile[{{x, _Real}}, Module[{xf = Floor[x], xi, xa, u, i, j}, xi = Mod[xf, 16] + 1; xa = x - xf; u = xa*xa*xa*(10.0 + xa*(xa*6.0 - 15.0)); i = permutations[[permutations[[xi]] + 1]]; j = permutations[[permutations[[xi + 1]] + 1]]; (2 Boole[OddQ[i]] - 1)*xa*(1.0 - u) + (2 Boole[OddQ[j]] - 1)*(xa - 1)*u], "CompilationTarget" -> "WVM", RuntimeAttributes -> {Listable}]]; handdrawn[fun_, fr_, divisor_, color_, at_] := Graphics[{Directive[color, AbsoluteThickness[at]], BSplineCurve[Table[fun@x + fBm[fr x]/(5 divisor), {x, 0.01, 10, .1}]]}] 

I had previously used the one-dimensional Perlin noise routine in this answer.

In any event, here's a stripped-down version of chris's plot:

Show[ handdrawn[{#, 1.5 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 5)^2/2]} &, 30, 3, Darker[Cyan, 0.3], 3], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, White, 8], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, Darker[Red, 0.3], 3], handdrawn[{1, #} &, 30, 4, Black, 3], handdrawn[{#, 1} &, 30, 4, Black, 3], PlotRange -> All] 

xkcd-style curves

As a bonus, here's a "hand-drawn" arrow routine you can use:

hArrow[{p_, q_}, fr_, divisor_] := Arrow[BSplineCurve[Table[p (1 - u) + q u + RotationMatrix[Arg[#1 + I #2] & @@ (p - q)].{u, fBm[fr u]/(5 divisor)}, {u, 0, 1, 1/50}]]] 

Replicating the comic strip in the OP with these routines (along with using the "Humor Sans" font) is left as an exercise.

To implement datenwolf's suggestion to perturb curves with Perlin noise to give that "hand-drawn" look and feel, here's one way to use one-dimensional Perlin noise for the perturbation:

fBm = With[{permutations = Apply[Join, ConstantArray[RandomSample[Range[0, 255]], 2]]}, Compile[{{x, _Real}}, Module[{xf = Floor[x], xi, xa, u, i, j}, xi = Mod[xf, 16] + 1; xa = x - xf; u = xa*xa*xa*(10.0 + xa*(xa*6.0 - 15.0)); i = permutations[[permutations[[xi]] + 1]]; j = permutations[[permutations[[xi + 1]] + 1]]; (2 Boole[OddQ[i]] - 1)*xa*(1.0 - u) + (2 Boole[OddQ[j]] - 1)*(xa - 1)*u], "CompilationTarget" -> "WVM", RuntimeAttributes -> {Listable}]]; handdrawn[fun_, fr_, divisor_, color_, at_] := Graphics[{Directive[color, AbsoluteThickness[at]], BSplineCurve[Table[fun@x + fBm[fr x]/(5 divisor), {x, 0.01, 10, .1}]]}] 

I had previously used the one-dimensional Perlin noise routine in this answer.

In any event, here's a stripped-down version of chris's plot:

Show[ handdrawn[{#, 1.5 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 5)^2/2]} &, 30, 3, Darker[Cyan, 0.3], 3], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, White, 8], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, Darker[Red, 0.3], 3], handdrawn[{1, #} &, 30, 4, Black, 3], handdrawn[{#, 1} &, 30, 4, Black, 3], PlotRange -> All] 

xkcd-style curves

As a bonus, here's a "hand-drawn" arrow routine you can use:

hArrow[{p_, q_}, fr_, divisor_] := Arrow[BSplineCurve[Table[p (1 - u) + q u + RotationMatrix[Arg[#1 + I #2] & @@ (p - q)].{u, fBm[fr u]/(5 divisor)}, {u, 0, 1, 1/50}]]] 

Replicating the comic strip in the OP with these routines (along with using the "Humor Sans" font) is left as an exercise.

Source Link

To implement datenwolf's suggestion to perturb curves with Perlin noise to give that "hand-drawn" look and feel, here's one way to use one-dimensional Perlin noise for the perturbation:

fBm = With[{permutations = Apply[Join, ConstantArray[RandomSample[Range[0, 255]], 2]]}, Compile[{{x, _Real}}, Module[{xf = Floor[x], xi, xa, u, i, j}, xi = Mod[xf, 16] + 1; xa = x - xf; u = xa*xa*xa*(10.0 + xa*(xa*6.0 - 15.0)); i = permutations[[permutations[[xi]] + 1]]; j = permutations[[permutations[[xi + 1]] + 1]]; (2 Boole[OddQ[i]] - 1)*xa*(1.0 - u) + (2 Boole[OddQ[j]] - 1)*(xa - 1)*u], "CompilationTarget" -> "WVM", RuntimeAttributes -> {Listable}]]; handdrawn[fun_, fr_, divisor_, color_, at_] := Graphics[{Directive[color, AbsoluteThickness[at]], BSplineCurve[Table[fun@x + fBm[fr x]/(5 divisor), {x, 0.01, 10, .1}]]}] 

I had previously used the one-dimensional Perlin noise routine in this answer.

In any event, here's a stripped-down version of chris's plot:

Show[ handdrawn[{#, 1.5 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 5)^2/2]} &, 30, 3, Darker[Cyan, 0.3], 3], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, White, 8], handdrawn[{#, 3 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 7)^2/2]} &, 30, 3, Darker[Red, 0.3], 3], handdrawn[{1, #} &, 30, 4, Black, 3], handdrawn[{#, 1} &, 30, 4, Black, 3], PlotRange -> All] 

xkcd-style curves

As a bonus, here's a "hand-drawn" arrow routine you can use:

hArrow[{p_, q_}, fr_, divisor_] := Arrow[BSplineCurve[Table[p (1 - u) + q u + RotationMatrix[Arg[#1 + I #2] & @@ (p - q)].{u, fBm[fr u]/(5 divisor)}, {u, 0, 1, 1/50}]]] 

Replicating the comic strip in the OP with these routines (along with using the "Humor Sans" font) is left as an exercise.