Class ShadowFractions

java.lang.Object
swingtree.style.ShadowFractions

public final class ShadowFractions extends Object
A collection of shadow "falloff" functions that describe how a shadow color fades from its full strength into full transparency across the blur region of a ShadowConf. Each method here samples a particular falloff curve f(t) (shadow intensity as a function of the normalized distance t in [0, 1] away from the solid edge of the shadow) at evenly spaced positions and returns the resulting fractions as a Tuple of float values, as described by ShadowFractionsSupplier.

The functions in this class are also supposed to serve as an example which demonstrates how to create custom shadow falloff curves yourself. See UI.ShadowType for the real world phenomenon and the exact math behind each curve.

  • Method Summary

    Modifier and Type
    Method
    Description
    static sprouts.Tuple<Float>
    The exact edge profile of a hard edge convolved with a Gaussian kernel, which is the normalized error function (NOT a bell shape).
    static sprouts.Tuple<Float>
    Ease-out-bounce, inverted so the shadow settles toward transparency.
    static sprouts.Tuple<Float>
    A sharp drop near the edge with a long faint tail, normalized to 0 at t == 1.
    static sprouts.Tuple<Float>
    A constant rate fade from full shadow color to transparency, producing a perfectly straight falloff.
    static sprouts.Tuple<Float>
    A bell shaped (Gaussian) falloff, normalized so it reaches exactly 0 at t == 1.
    static sprouts.Tuple<Float>
    A smooth, symmetric S-curve, a cheap polynomial approximation of blur().
    static sprouts.Tuple<Float>
    A cosine wave under a linear decay envelope: fading concentric rings.
    static sprouts.Tuple<Float>
    Repeating linear ramps under a decay envelope: fading louvers.
    static sprouts.Tuple<Float>
    Posterize the linear falloff into N discrete bands (cel-shaded look).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • flat

      public static sprouts.Tuple<Float> flat()
      A constant rate fade from full shadow color to transparency, producing a perfectly straight falloff. Falloff: f(t) = 1 - t. As a straight line is fully described by its two endpoints, this needs only two fractions and so allocates the smallest possible tuple.
      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • penumbra

      public static sprouts.Tuple<Float> penumbra()
      A smooth, symmetric S-curve, a cheap polynomial approximation of blur(). Falloff (the "smoothstep" function): f(t) = 1 - t2(3 - 2t).
      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • blur

      public static sprouts.Tuple<Float> blur()
      The exact edge profile of a hard edge convolved with a Gaussian kernel, which is the normalized error function (NOT a bell shape). This is what a CSS box-shadow / Figma / Photoshop blur looks like.

      Falloff (normalized error function, with steepness k):
      f(t) = (erf(k/2) - erf(k(t - 1/2))) / (2 * erf(k/2))

      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • glow

      public static sprouts.Tuple<Float> glow()
      A bell shaped (Gaussian) falloff, normalized so it reaches exactly 0 at t == 1. Mimics a diffuse glow / halo rather than a cast shadow edge.

      Falloff (normalized Gaussian bell, with width k):
      f(t) = (exp(-k t2) - exp(-k)) / (1 - exp(-k))

      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • contact

      public static sprouts.Tuple<Float> contact()
      A sharp drop near the edge with a long faint tail, normalized to 0 at t == 1. Mimics a contact shadow / ambient occlusion.

      Falloff (normalized exponential decay, with rate k):
      f(t) = (exp(-k t) - exp(-k)) / (1 - exp(-k))

      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • stairs

      public static sprouts.Tuple<Float> stairs()
      Posterize the linear falloff into N discrete bands (cel-shaded look).

      Falloff (quantized linear, with N bands):
      f(t) = round((1 - t) * (N - 1)) / (N - 1)

      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • ripple

      public static sprouts.Tuple<Float> ripple()
      A cosine wave under a linear decay envelope: fading concentric rings.

      Falloff (damped cosine, with k ripples):
      f(t) = (1 - t) * (1/2 + 1/2 * cos(2πk t)), with k = 3

      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • sawtooth

      public static sprouts.Tuple<Float> sawtooth()
      Repeating linear ramps under a decay envelope: fading louvers.

      Falloff (decaying sawtooth, with k louvers):
      f(t) = (1 - t) * (1 - frac(k t)), with k = 4

      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.
    • bounce

      public static sprouts.Tuple<Float> bounce()
      Ease-out-bounce, inverted so the shadow settles toward transparency. Falloff: f(t) = 1 - easeOutBounce(t).
      Returns:
      A tuple of shadow falloff fractions sampled at evenly spaced positions.