Logic in Bitbybit
View Full Source & Details on GitHub
bitbybit.logic works with booleans, the values true and false, and with decisions made from them: "is this number greater than 10?", "should this item of the pattern get a hole?".
Single booleans
booleanpasses atrueorfalsethrough unchanged, so a value can be set once in Rete or Blockly, named and reused.notflips a boolean, andnotListflips every boolean in a list.
Comparing values
compare compares first with second and gives a boolean. operator picks the comparison:
<,<=,>and>=;==and!=, which convert types first, so5 == "5"is true;===and!==, which do not, so5 === "5"is false.
Patterns from numbers
These turn a list of numbers into a list of booleans, one each, and are the usual way to decide which items of a pattern get a feature. Feed them distances, noise values or parameters along a curve, then pick items with bitbybit.lists.getByPattern.
thresholdBooleanListgives true for a number belowthresholdand false at or above it.thresholdGapsBooleanListgives true for a number inside any of the ranges ingapThresholds, each[min, max]with both ends included.twoThresholdRandomGradientblends between two thresholds: belowthresholdTotalTruea number is always true, abovethresholdTotalFalsealways false, and in between the chance of true falls innrLevelssteps, so the pattern fades out instead of switching sharply.
thresholdBooleanList and thresholdGapsBooleanList take inverse, which flips every result.
randomBooleans draws length random booleans with no numbers as input, each true with probability trueThreshold. It and twoThresholdRandomGradient give a different result on every run.
Letting values through
valueGategivesvaluewhenbooleanis true andundefinedwhen it is false. Use it to switch a branch of a script on or off.firstDefinedValueGategivesvalue1when it is defined andvalue2otherwise, so the second acts as a fallback. Onlyundefinedcounts as missing;null,0andfalsepass.
Every function
| Function | What it does |
|---|---|
boolean | Passes a boolean through unchanged, so a value can be given a name and reused. |
compare | Compares two values with an operator: less, less or equal, greater, greater or equal, equal or not equal, in the loose (==) or strict (===) form. |
firstDefinedValueGate | Picks the first of two values that is defined, so the second acts as a fallback. |
not | Flips a boolean: true becomes false and false becomes true. |
notList | Flips every boolean in a list. |
randomBooleans | Draws a list of random booleans, each true with a given probability. |
thresholdBooleanList | Turns numbers into booleans: true below the threshold, false at or above it. |
thresholdGapsBooleanList | Turns numbers into booleans: true when the number falls inside any of the given ranges, false otherwise. |
twoThresholdRandomGradient | Turns numbers into booleans with a random blend between two thresholds. |
valueGate | Lets a value through when the boolean is true and gives undefined when it is false. |