Bitbybit Docs
    Preparing search index...

    Class Logic

    Booleans and decisions: comparing values, flipping booleans, turning lists of numbers into lists of booleans by thresholds, drawing random booleans, and gating a value so it passes only when a condition holds. The threshold methods are the usual way to decide which items of a pattern get a feature and which do not.

    Index

    Constructors

    create

    • Passes a boolean through unchanged, so a value can be given a name and reused.

      Example: true -> true

      Parameters

      Returns boolean

      The same boolean

    • Draws a list of random booleans, each true with a given probability.

      Example: length 5 with trueThreshold 0.7 -> perhaps [true, true, false, true, true]

      Parameters

      Returns boolean[]

      The random booleans

      const flags = bitbybit.logic.randomBooleans({ length: 5, trueThreshold: 0.7 });
      
    • Turns numbers into booleans with a random blend between two thresholds.

      Below the first threshold a number is always true, above the second always false; in between, the chance of true falls in steps from one to the other, so a pattern fades out instead of switching sharply. Example: [0.1, 0.9] with thresholds 0.3 and 0.7 -> [true, false]

      Parameters

      Returns boolean[]

      One boolean per number

      const fade = bitbybit.logic.twoThresholdRandomGradient({
      numbers: [0.1, 0.4, 0.6, 0.9],
      thresholdTotalTrue: 0.3,
      thresholdTotalFalse: 0.7,
      nrLevels: 10,
      });
    • Turns numbers into booleans: true below the threshold, false at or above it.

      inverse flips every result. Example: [0.3, 0.7, 0.5] with threshold 0.6 -> [true, false, true]

      Parameters

      Returns boolean[]

      One boolean per number

      const below = bitbybit.logic.thresholdBooleanList({ numbers: [0.3, 0.7, 0.5], threshold: 0.6, inverse: false });
      
    • Turns numbers into booleans: true when the number falls inside any of the given ranges, false otherwise.

      Each range is [min, max] with both ends included; inverse flips every result. Example: [0.2, 0.5, 0.8] with ranges [[0.3, 0.6], [0.7, 0.9]] -> [false, true, true]

      Parameters

      Returns boolean[]

      One boolean per number

      const inside = bitbybit.logic.thresholdGapsBooleanList({
      numbers: [0.2, 0.5, 0.8],
      gapThresholds: [[0.3, 0.6], [0.7, 0.9]],
      inverse: false,
      });

    edit

    • Flips a boolean: true becomes false and false becomes true.

      Example: true -> false

      Parameters

      Returns boolean

      The opposite boolean

    • Flips every boolean in a list.

      Example: [true, false, true] -> [false, true, false]

      Parameters

      Returns boolean[]

      The flipped booleans, in the same order

    operations

    • Compares two values with an operator: less, less or equal, greater, greater or equal, equal or not equal, in the loose (==) or strict (===) form.

      Example: 5 greater than 3 -> true; 'hello' strictly equal to 'world' -> false

      Type Parameters

      • T

      Parameters

      Returns boolean

      The result of the comparison

      const bigger = bitbybit.logic.compare({ first: 5, second: 3, operator: Bit.Inputs.Logic.BooleanOperatorsEnum.greater });
      
    • Lets a value through when the boolean is true and gives undefined when it is false.

      Example: 42 with true -> 42; 42 with false -> undefined

      Type Parameters

      • T

      Parameters

      • inputs: ValueGateDto<T>

        The value and the boolean that opens the gate

      Returns T

      The value, or undefined when the gate is closed

      const maybe = bitbybit.logic.valueGate({ value: 42, boolean: true });
      
    • Picks the first of two values that is defined, so the second acts as a fallback.

      Example: 42 and 10 -> 42; undefined and 10 -> 10

      Type Parameters

      • T
      • U

      Parameters

      Returns T | U

      The first defined value, or undefined when both are missing

      const chosen = bitbybit.logic.firstDefinedValueGate({ value1: undefined, value2: 10 });