Skip to content

Commit 36a061c

Browse files
Merge pull request #82 from bitbybit-dev/develop
updated docs
2 parents d99973b + 38f4aae commit 36a061c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1229
-151
lines changed

docs/docusaurus.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ const config: Config = {
102102
},
103103
{ to: "/learn/code/intro", label: "Code", position: "left" },
104104
{ to: "/learn/3d-bits/intro", label: "3D Bits", position: "left" },
105+
{ to: "/learn/npm-packages/threejs", label: "ThreeJS", position: "left" },
106+
{ to: "/learn/npm-packages/babylonjs", label: "BabylonJS", position: "left" },
105107
{ to: "/blog", label: "Blog", position: "left" },
106108
{ to: "https://bitbybit.dev", label: "Home", position: "left" },
107109
{
@@ -111,6 +113,13 @@ const config: Config = {
111113
className: "navbar__button--support", // Custom class for styling
112114
"aria-label": "Support the Project Mission", // For accessibility
113115
},
116+
{
117+
href: "https://bitbybit.dev/auth/sign-up",
118+
label: "Sign Up",
119+
position: "right",
120+
className: "navbar__button--support",
121+
"aria-label": "Sign Up to Bitbybit.dev",
122+
},
114123
{
115124
href: "https://github.com/bitbybit-dev/bitbybit",
116125
label: "GitHub",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Base",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Base Algorithms in Bitbybit",
7+
"description": "Base algorithms in Bitbybit provide foundational algorithms & object types, such as vectors, matrixes, points, lines, polylines, triangles and meshes. Learn how to use these algorithms to create complex shapes, grids and designs.",
8+
"slug": "/code/common/base"
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "Color",
3+
"link": {
4+
"type": "generated-index",
5+
"title": "Colors in Bitbybit",
6+
"description": "Introduction to colors in Bitbybit.",
7+
"slug": "/code/common/base/color"
8+
}
9+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
sidebar_position: 1
3+
title: Colors in Bitbybit
4+
sidebar_label: Colors in Bitbybit
5+
description: An overview of the Color class in Bitbybit, explaining how to work with hex and RGB color formats, convert between them, and perform basic color manipulations.
6+
tags: [code, color]
7+
---
8+
9+
<img
10+
class="category-icon-small"
11+
src="https://s.bitbybit.dev/assets/icons/white/color-icon.svg"
12+
alt="Color category icon"
13+
title="Color category icon" />
14+
15+
[View Full Source & Details on GitHub](https://github.com/bitbybit-dev/bitbybit/blob/master/packages/dev/base/lib/api/services/color.ts)
16+
17+
The `Color` class in Bitbybit provides tools for defining, converting, and manipulating colors, primarily focusing on hexadecimal (hex) and RGB (Red, Green, Blue) color formats.
18+
19+
**Understanding Color Formats in Bitbybit:**
20+
21+
* **Hex Color (`Inputs.Base.Color`):** This is a string representation of a color, commonly used in web design and graphics, like `#FF0000` (for red) or `#00FF00` (for green).
22+
* **RGB Color (`Inputs.Base.ColorRGB`):** This is an object representing color with separate red, green, and blue components, typically as numbers. For example, `{ r: 255, g: 0, b: 0 }` for red.
23+
* The `Color` class can handle RGB values in different ranges (e.g., 0-255, 0-1, or 0-100) and will remap them as needed for conversions.
24+
25+
## Core Capabilities of the Color Class
26+
27+
The `Color` class makes it easy to work with these common color formats. Here's what it can do. For precise input parameters and detailed behavior (like how RGB ranges are handled), please consult the [full Color API documentation](https://docs.bitbybit.dev/classes/Bit.Color.html) or the GitHub source linked above.
28+
29+
### 1. Creating and Representing Colors
30+
31+
* **Hex Color Input (`hexColor()`):** If you already have a hex color string (e.g., from a color picker), this function simply returns it. It's useful in visual programming environments to explicitly define a color input.
32+
33+
### 2. Converting Between Color Formats
34+
35+
This is a key function of the class, allowing you to switch between hex and RGB representations:
36+
* **Hex to RGB (`hexToRgb()`):** Converts a hex color string (e.g., `#FF0000`) into an RGB object (e.g., `{ r: 255, g: 0, b: 0 }`).
37+
* **Hex to RGB Mapped (`hexToRgbMapped()`):** Converts a hex color to an RGB object, but then remaps the R, G, and B values from the standard 0-255 range to a custom range you specify (e.g., 0-1).
38+
* **RGB to Hex (`rgbToHex()`):** Converts individual R, G, and B numerical values into a hex color string. It can intelligently handle input RGB values that are not in the 0-255 range by remapping them if you provide their original `min` and `max` range.
39+
* **RGB Object to Hex (`rgbObjToHex()`):** Similar to `rgbToHex()`, but takes an RGB object (`{r, g, b}`) as input instead of separate R, G, B parameters.
40+
41+
### 3. Extracting Color Components
42+
43+
Get individual R, G, or B values from a color:
44+
* **From Hex (Mapped):**
45+
* `getRedParam()`: Gets the red component from a hex color, remapped to a specified range.
46+
* `getGreenParam()`: Gets the green component from a hex color, remapped to a specified range.
47+
* `getBlueParam()`: Gets the blue component from a hex color, remapped to a specified range.
48+
* **From RGB Object:**
49+
* `rgbToRed()`: Extracts the `r` value from an RGB object.
50+
* `rgbToGreen()`: Extracts the `g` value from an RGB object.
51+
* `rgbToBlue()`: Extracts the `b` value from an RGB object.
52+
53+
### 4. Basic Color Manipulation
54+
55+
* **Invert Color (`invert()`):**
56+
* Takes a hex color and produces its photographic negative (e.g., red becomes cyan, white becomes black).
57+
* It also offers an option to invert to pure black or white based on the original color's perceived brightness, which can be useful for ensuring text visibility against a colored background.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "Dates",
3+
"link": {
4+
"type": "generated-index",
5+
"title": "Dates in Bitbybit",
6+
"description": "Introduction to dates in Bitbybit.",
7+
"slug": "/code/common/base/dates"
8+
}
9+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
sidebar_position: 1
3+
title: Dates in Bitbybit
4+
sidebar_label: Dates in Bitbybit
5+
description: An overview of the Dates class in Bitbybit, explaining how to create, access, modify, and format date and time information.
6+
tags: [code, dates]
7+
---
8+
9+
<img
10+
class="category-icon-small"
11+
src="https://s.bitbybit.dev/assets/icons/white/dates-icon.svg"
12+
alt="Dates category icon"
13+
title="Dates category icon" />
14+
15+
[View Full Source & Details on GitHub](https://github.com/bitbybit-dev/bitbybit/blob/master/packages/dev/base/lib/api/services/dates.ts)
16+
17+
The `Dates` class in Bitbybit provides a collection of tools for working with dates and times. It largely leverages the built-in JavaScript `Date` object, offering convenient methods to create, manipulate, and query date information.
18+
19+
**What is a Date in Bitbybit?**
20+
21+
A "Date" in Bitbybit refers to a standard JavaScript `Date` object. This object encapsulates a specific moment in time, including the year, month, day, hour, minute, second, and millisecond.
22+
23+
## Core Capabilities of the Dates Class
24+
25+
The `Dates` class simplifies common date and time operations. Here's a high-level look at its features. For the exact input parameters (like DTOs) and detailed behavior (e.g., how months are 0-indexed), please consult the [full Dates API documentation](https://docs.bitbybit.dev/classes/Bit.Dates.html) or the GitHub source linked above.
26+
27+
### 1. Creating Dates
28+
29+
Need to define a specific date or get the current time?
30+
* **Current Date & Time (`now()`):** Get a `Date` object representing the exact moment the function is called.
31+
* **Specific Date (`createDate()`):** Create a `Date` object by providing individual components like year, month (0-11), day, hours, minutes, seconds, and milliseconds.
32+
* **Specific UTC Date (`createDateUTC()`):** Similar to `createDate()`, but interprets the provided components as Coordinated Universal Time (UTC).
33+
* **From Timestamp (`createFromUnixTimeStamp()`):** Create a `Date` object from a Unix timestamp (the number of milliseconds since January 1, 1970, UTC).
34+
35+
### 2. Converting Dates to Strings (Formatting)
36+
37+
Displaying dates in a human-readable format:
38+
* **Basic String (`toString()`):** Get a general string representation of the date (format depends on the system's locale).
39+
* **Date Part Only (`toDateString()`):** Get just the date portion as a string (e.g., "Mon Jan 01 2024").
40+
* **Time Part Only (`toTimeString()`):** Get just the time portion as a string (e.g., "14:30:00 GMT+0000").
41+
* **ISO Format (`toISOString()`):** Get the date in the standard ISO 8601 format (e.g., "2024-01-01T14:30:00.000Z"). This is often used for data interchange.
42+
* **JSON Format (`toJSON()`):** Get the date as a string suitable for JSON serialization (typically ISO format).
43+
* **UTC String (`toUTCString()`):** Get the date as a string formatted according to UTC conventions (e.g., "Mon, 01 Jan 2024 14:30:00 GMT").
44+
45+
### 3. Getting Specific Parts of a Date
46+
47+
Extracting individual components from a `Date` object. Most "get" methods have both a local time version and a UTC version:
48+
* **Year:** `getYear()` / `getUTCYear()`
49+
* **Month:** `getMonth()` (0 for January, 11 for December) / `getUTCMonth()`
50+
* **Day of the Month:** `getDayOfMonth()` (1-31) / `getUTCDay()` (Note: `getUTCDay()` in JS Date returns day of week for UTC, but here it seems to mean day of month for UTC based on pairing with `setUTCDay` which takes day of month).
51+
* **Day of the Week:** `getWeekday()` (0 for Sunday, 6 for Saturday - local time)
52+
* **Hours:** `getHours()` (0-23) / `getUTCHours()`
53+
* **Minutes:** `getMinutes()` (0-59) / `getUTCMinutes()`
54+
* **Seconds:** `getSeconds()` (0-59) / `getUTCSeconds()`
55+
* **Milliseconds:** `getMilliseconds()` (0-999) / `getUTCMilliseconds()`
56+
* **Total Time (`getTime()`):** Get the raw numeric value of the date, represented as milliseconds since the Unix epoch (January 1, 1970, UTC).
57+
58+
### 4. Setting Parts of a Date (Modifying Dates)
59+
60+
Changing components of an existing `Date` object. These methods typically return a *new* `Date` object with the modification, leaving the original unchanged. Like "get" methods, "set" methods often have local and UTC versions:
61+
* **Year:** `setYear()` / `setUTCYear()`
62+
* **Month:** `setMonth()` / `setUTCMonth()`
63+
* **Day of the Month:** `setDayOfMonth()` / `setUTCDay()`
64+
* **Hours:** `setHours()` / `setUTCHours()`
65+
* **Minutes:** `setMinutes()` / `setUTCMinutes()`
66+
* **Seconds:** `setSeconds()` / `setUTCSeconds()`
67+
* **Milliseconds:** `setMilliseconds()` / `setUTCMilliseconds()`
68+
* **Total Time (`setTime()`):** Set the date based on a Unix timestamp (milliseconds since epoch).
69+
70+
### 5. Parsing Date Strings
71+
72+
* **Parse Date String (`parseDate()`):** Convert a string representation of a date into a Unix timestamp (number of milliseconds since epoch). The success of parsing depends on the format of the string and the browser's parsing capabilities.
73+
74+
## Important Notes:
75+
76+
* **Local Time vs. UTC:** Be mindful of whether you're working with local time (which depends on the user's system timezone) or UTC (a global time standard). The class provides methods for both.
77+
* **Month Indexing:** When creating dates or getting/setting months, remember that months are typically 0-indexed in JavaScript (0 for January, 1 for February, ..., 11 for December).
78+
* **Immutability:** The "set" methods in this class are designed to be immutable: they return a *new* `Date` object with the changes, rather than modifying the original `Date` object you passed in. This is generally a safer approach.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
sidebar_position: 1
3+
title: Introduction to Base Algorithms of Bitbybit
4+
sidebar_label: Base Algorithms of Bitbybit
5+
description: Discover the foundational capabilities of the @bitbybit-dev/base NPM package, your core toolkit for geometric and utility functions in Bitbybit.
6+
tags: [code, base]
7+
---
8+
9+
[View Package Source on GitHub](https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/base)
10+
[NPM Package](https://www.npmjs.com/package/@bitbybit-dev/base)
11+
12+
Welcome to the **`@bitbybit-dev/base`** package! This is the foundational layer of the Bitbybit ecosystem, providing a rich set of core utilities for mathematics, geometry, data manipulation, and more. Whether you're building complex 3D models, performing geometric analysis, or just need robust utility functions, the `base` package is your starting point.
13+
14+
Think of this package as your essential toolbox, filled with well-defined, reliable tools that other Bitbybit functionalities and your own projects can build upon.
15+
16+
## What's Inside? A Tour of Core Capabilities
17+
18+
The `@bitbybit-dev/base` package is organized into several key classes, each specializing in a different area:
19+
20+
### `Vector` - The Language of Position and Direction
21+
At its core, a vector (or a point) in Bitbybit is simply an array of numbers (e.g., `[x, y, z]`). The `Vector` class provides a comprehensive suite for:
22+
* **Creating** vectors and number sequences (like linear spans or eased distributions).
23+
* Performing fundamental **vector math**: addition, subtraction, dot product, cross product, scaling.
24+
* **Analyzing** vectors: calculating length (norm), normalizing (to get direction), finding distances, and measuring angles.
25+
* [Learn more about the Vector class...](./vector/intro)
26+
27+
### `Point` - Defining Locations in Space
28+
While structurally similar to vectors, the `Point` class focuses on operations related to specific locations:
29+
* **Creating** individual points or patterned arrangements (like spirals or hexagonal grids).
30+
* **Transforming** points: moving (translating), rotating, and scaling them in 3D space.
31+
* **Analyzing** collections of points: finding the closest point, calculating bounding boxes, or determining the average position.
32+
* [Learn more about the Point class...](./point/intro)
33+
34+
### `Line` - Working with Straight Segments
35+
The `Line` class deals with straight line segments defined by start and end points:
36+
* **Creating** lines from various inputs (pairs of points, sequences of points).
37+
* **Getting information** like length, endpoints, or points along the line.
38+
* **Transforming** lines and converting between different line/segment representations.
39+
* Performing **intersections** between lines.
40+
* [Learn more about the Line class...](./line/intro)
41+
42+
### `Polyline` - Paths and Sequences of Lines
43+
Polylines are sequences of connected line segments, forming paths or outlines:
44+
* **Creating** polylines from lists of points, specifying if they are open or closed.
45+
* **Analyzing** polylines: calculating total length or getting their constituent points.
46+
* **Modifying** polylines: reversing direction or applying transformations.
47+
* Finding **intersections** (self-intersections or intersections between two polylines).
48+
* Advanced utilities like **sorting scattered segments** into continuous polylines.
49+
* [Learn more about the Polyline class...](./polyline/intro)
50+
51+
### `Math` - Your Numerical Toolkit
52+
The `Math` class offers a wide array of numerical operations:
53+
* **Basic arithmetic** and standard mathematical functions (square root, absolute value, logarithms, trigonometry).
54+
* **Number generation** (random numbers, Pi).
55+
* **Number manipulation** like remapping values from one range to another.
56+
* Powerful **easing functions** for creating smooth, non-linear transitions and distributions.
57+
* [Learn more about the Math class...](./math/intro)
58+
59+
### `Lists` - Managing Your Data Collections
60+
Lists (arrays) are fundamental for storing collections of data. The `Lists` class provides extensive tools for:
61+
* **Creating** and populating lists (e.g., repeating items).
62+
* **Accessing** items by index, getting sub-lists, or retrieving items based on patterns.
63+
* **Modifying** lists: adding, removing, or replacing items.
64+
* **Restructuring** lists: reversing, grouping, or transposing (flipping) 2D lists.
65+
* **Sorting** lists of numbers, text, or objects by property values.
66+
* [Learn more about the Lists class...](./lists/intro)
67+
68+
### `Color` - Working with Colors
69+
The `Color` class helps you define, convert, and manipulate colors, primarily focusing on:
70+
* **Hexadecimal** (e.g., `#FF0000`) and **RGB** (Red, Green, Blue) color formats.
71+
* **Converting** seamlessly between these formats.
72+
* **Extracting** individual color components (R, G, B).
73+
* Performing basic manipulations like **inverting** a color.
74+
* [Learn more about the Color class...](./color/intro)
75+
76+
### `Logic` - Making Decisions
77+
The `Logic` class is all about boolean values (`true`/`false`) and conditional operations:
78+
* **Creating** boolean values and lists of booleans (e.g., from random generation or by thresholding numerical data).
79+
* Performing **comparisons** between values (equal to, greater than, etc.).
80+
* Implementing **conditional logic** with "gates" that pass through data only if a condition is met.
81+
* [Learn more about the Logic class...](./logic/intro)
82+
83+
### `Text` - Manipulating and Representing Text
84+
The `Text` class provides tools for string operations and an exciting feature for 3D:
85+
* Basic **string manipulation**: splitting, joining, replacing, and formatting text.
86+
* Converting various data types **to strings**.
87+
* Generating **vector text**: converting text characters into 2D vector paths, suitable for creating 3D text objects in your scenes.
88+
* [Learn more about the Text class...](./text/intro) <!-- Link to Text API page -->
89+
90+
### `Dates` - Handling Date and Time
91+
The `Dates` class provides utilities for working with date and time information:
92+
* **Creating** `Date` objects (current time, specific dates, from timestamps).
93+
* **Converting** dates to various string formats (ISO, locale-specific, UTC).
94+
* **Getting and setting** individual components of a date (year, month, day, hour, etc.), with support for both local time and UTC.
95+
* **Parsing** date strings into `Date` objects.
96+
* [Learn more about the Dates class...](./dates/intro) <!-- Link to Dates API page -->
97+
98+
### `Mesh Utilities` - Low-Level Mesh Operations
99+
The `MeshBitByBit` class offers specialized functions for working directly with mesh triangles and planes:
100+
* Calculating **distances to planes** and defining **triangle planes**.
101+
* Performing **intersections** between triangles and, by extension, between entire meshes to find intersection segments or polylines.
102+
* These are more advanced tools for detailed geometric analysis.
103+
* [Learn more about the Mesh Utilities class...](./mesh/intro)
104+
105+
## Get Started!
106+
107+
The `@bitbybit-dev/base` package is designed to be intuitive and powerful. Dive into the documentation for each class to explore their methods in detail and see how they can accelerate your development with Bitbybit.
108+
109+
Happy coding!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Line",
3+
"position": 2,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Lines in Bitbybit",
7+
"description": "Introduction to lines in Bitbybit.",
8+
"slug": "/code/common/base/line"
9+
}
10+
}

0 commit comments

Comments
 (0)