メインコンテンツまでスキップ

flip: Gradual Polarity Inversion Function

Controlled Transition Between Value and Its Complement

The flip function performs gradual polarity inversion by interpolating between a value and its complement (1-v). This enables controlled negative effects and bidirectional value transformations.

Mathematical Definition

For input value vv and transition parameter p[0,1]p \in [0,1]: flip(v,p)=v(1p)+(1v)p=v+p(12v)flip(v, p) = v(1-p) + (1-v)p = v + p(1-2v)

Transition States

ParameterMathematical ExpressionVisual ResultApplication
p=0p = 0flip(v,0)=vflip(v, 0) = vOriginal valueNo inversion
p=0.5p = 0.5flip(v,0.5)=0.5flip(v, 0.5) = 0.5Neutral gray50% inversion
p=1p = 1flip(v,1)=1vflip(v, 1) = 1-vComplete complementFull inversion

Bidirectional Property

The function exhibits symmetric behavior around the midpoint:

  • Forward: v1vv \rightarrow 1-v as p:01p: 0 \rightarrow 1
  • Reverse: 1vv1-v \rightarrow v as p:01p: 0 \rightarrow 1 applied to (1v)(1-v)
ライブエディター
const fragment = () => {
      const wave = uv.y.mul(20).add(iTime).sin().mul(0.5).add(0.5)
      const grad = uv.x.mul(wave)
      const color = vec3(uv.x, wave, grad)
      const amount = iTime.sin().abs()
      const flipped = flip(color, amount)
      return vec4(flipped, 1)
}