Bresenham's Line Algorithm
Posted: Fri Dec 23, 2022 5:41 am
This hex is an implementation of Bresenham's Line Algorithm in Hex Casting. Adapted from this code. It makes extensive use of Hexal's macro feature. All macros used are documented below the main hex, along with suggested patterns. The full .hexpattern file is also included at the end of the post.
Video demo: https://youtu.be/x-YZOh4LHn8
Bresenham's Line Algorithm
This hex should be used with a CAD. It modifies itself to store the starting location for the line. Sneak to set the starting location without drawing a line.
Sign Purification
num -> 1 or 0 or -1
Signum function.
Vector Sign Purification
vec -> vec
Gets the sign of each vector component, returning the result as a vector.
Maximization Distillation
num, num -> num
Max function.
Hadamard's Distillation
vec, vec -> vec
Hadamard (pairwise) product.
Full .hexpattern file
Video demo: https://youtu.be/x-YZOh4LHn8
Bresenham's Line Algorithm
This hex should be used with a CAD. It modifies itself to store the starting location for the line. Sneak to set the starting location without drawing a line.
Code: Select all
{
// preamble to make this draw lines as a CAD hex
{
Bookkeeper's Gambit: - // previous block placeholder
}
Flock's Disintegration
Mind's Reflection
Compass' Purification
Mind's Reflection
Alidade's Purification
Archer's Distillation
Gemini Decomposition
Scribe's Reflection
Numerical Reflection: 1
Rotation Gambit
Surgeon's Exaltation
Scribe's Gambit
Mind's Reflection
Stadiometer's Purification
Numerical Reflection: 1.5
Maximus Distillation
{
Bookkeeper's Gambit: -
Charon's Gambit
}
Flock's Disintegration
Augur's Exaltation
Hermes' Gambit
// the actual algorithm starts here
// p0, p1 ->
Prospector's Gambit
Subtractive Distillation
Gemini Decomposition
Vector Sign Purification
Undertaker's Gambit
Hadamard's Distillation
Gemini Decomposition
Vector Disintegration
Maximization Distillation
Maximization Distillation
Numerical Reflection: 4
Fisherman's Gambit
Prospector's Gambit
Numerical Reflection: 2
Division Distillation
Gemini Decomposition
Gemini Decomposition
Vector Exaltation
Numerical Reflection: 2
Flock's Gambit
Rotation Gambit II
Undertaker's Gambit
Numerical Reflection: 1
Additive Distillation
Gemini Decomposition
Huginn's Gambit
Gemini's Gambit
Muninn's Reflection
Flock's Gambit
Rotation Gambit
Huginn's Gambit
Consideration: {
Muninn's Reflection
Flock's Disintegration
Rotation Gambit
Subtractive Distillation
Gemini Decomposition
Vector Sign Purification
Numerical Reflection: 1
Subtractive Distillation
Gemini Decomposition
Vector Sign Purification
Subtractive Distillation
Undertaker's Gambit
Numerical Reflection: 5
Fisherman's Gambit
Multiplicative Distillation
Subtractive Distillation
Rotation Gambit
Gemini Decomposition
// do something with the current point on the line
// here I just place a block to show off the algorithm
Gemini Decomposition
Break Block
Place Block
Rotation Gambit
Numerical Reflection: 4
Fisherman's Gambit
Hadamard's Distillation
Subtractive Distillation
Jester's Gambit
Numerical Reflection: 2
Flock's Gambit
Huginn's Gambit
Consideration: }
Jester's Gambit
Thoth's Gambit
Bookkeeper's Gambit: vvv
}
num -> 1 or 0 or -1
Signum function.
Code: Select all
{
Gemini Decomposition
Numerical Reflection: 0
Maximus Distillation
Numerical Reflection: 1
Numerical Reflection: 0
Augur's Exaltation
Jester's Gambit
Numerical Reflection: 0
Minimus Distillation
Numerical Reflection: -1
Rotation Gambit
Augur's Exaltation
}
vec -> vec
Gets the sign of each vector component, returning the result as a vector.
Code: Select all
{
Vector Disintegration
Sign Purification
Rotation Gambit
Sign Purification
Rotation Gambit
Sign Purification
Rotation Gambit
Vector Exaltation
}
num, num -> num
Max function.
Code: Select all
{
Dioscuri Gambit
Maximus Distillation
Rotation Gambit II
Augur's Exaltation
}
vec, vec -> vec
Hadamard (pairwise) product.
Code: Select all
{
Vector Disintegration
Numerical Reflection: 4
Fisherman's Gambit
Vector Disintegration
Numerical Reflection: 50
Swindler's Gambit
Multiplicative Distillation
Rotation Gambit II
Multiplicative Distillation
Numerical Reflection: 22
Swindler's Gambit
Multiplicative Distillation
Rotation Gambit II
Vector Exaltation
}
Code: Select all
#define Sign Purification = num -> 1 or 0 or -1
// SOUTH_EAST awdda
{
Gemini Decomposition
Numerical Reflection: 0
Maximus Distillation
Numerical Reflection: 1
Numerical Reflection: 0
Augur's Exaltation
Jester's Gambit
Numerical Reflection: 0
Minimus Distillation
Numerical Reflection: -1
Rotation Gambit
Augur's Exaltation
}
#define Vector Sign Purification = vec -> vec
// (sign(x), sign(y), sign(z))
// SOUTH_EAST awddaqqqq
{
Vector Disintegration
Sign Purification
Rotation Gambit
Sign Purification
Rotation Gambit
Sign Purification
Rotation Gambit
Vector Exaltation
}
#define Maximization Distillation = num, num -> num
// max(a, b)
// SOUTH_EAST edd
{
Dioscuri Gambit
Maximus Distillation
Rotation Gambit II
Augur's Exaltation
}
#define Hadamard's Distillation = vec, vec -> vec
// (AxBx, AyBy, AzBz)
// WEST awaqawa
{
Vector Disintegration
Numerical Reflection: 4
Fisherman's Gambit
Vector Disintegration
Numerical Reflection: 50
Swindler's Gambit
Multiplicative Distillation
Rotation Gambit II
Multiplicative Distillation
Numerical Reflection: 22
Swindler's Gambit
Multiplicative Distillation
Rotation Gambit II
Vector Exaltation
}
// Bresenham's Line Algorithm
// http://members.chello.at/easyfilter/bresenham.html
{
// preamble to make this draw lines as a CAD hex
{
Bookkeeper's Gambit: - // previous block placeholder
}
Flock's Disintegration
Mind's Reflection
Compass' Purification
Mind's Reflection
Alidade's Purification
Archer's Distillation
Gemini Decomposition
Scribe's Reflection
Numerical Reflection: 1
Rotation Gambit
Surgeon's Exaltation
Scribe's Gambit
Mind's Reflection
Stadiometer's Purification
Numerical Reflection: 1.5
Maximus Distillation
{
Bookkeeper's Gambit: -
Charon's Gambit
}
Flock's Disintegration
Augur's Exaltation
Hermes' Gambit
// the actual algorithm starts here
// p0, p1 ->
Prospector's Gambit
Subtractive Distillation
Gemini Decomposition
Vector Sign Purification
Undertaker's Gambit
Hadamard's Distillation
Gemini Decomposition
Vector Disintegration
Maximization Distillation
Maximization Distillation
Numerical Reflection: 4
Fisherman's Gambit
Prospector's Gambit
Numerical Reflection: 2
Division Distillation
Gemini Decomposition
Gemini Decomposition
Vector Exaltation
Numerical Reflection: 2
Flock's Gambit
Rotation Gambit II
Undertaker's Gambit
Numerical Reflection: 1
Additive Distillation
Gemini Decomposition
Huginn's Gambit
Gemini's Gambit
Muninn's Reflection
Flock's Gambit
Rotation Gambit
Huginn's Gambit
Consideration: {
Muninn's Reflection
Flock's Disintegration
Rotation Gambit
Subtractive Distillation
Gemini Decomposition
Vector Sign Purification
Numerical Reflection: 1
Subtractive Distillation
Gemini Decomposition
Vector Sign Purification
Subtractive Distillation
Undertaker's Gambit
Numerical Reflection: 5
Fisherman's Gambit
Multiplicative Distillation
Subtractive Distillation
Rotation Gambit
Gemini Decomposition
// do something with the current point on the line
// here I just place a block to show off the algorithm
Gemini Decomposition
Break Block
Place Block
Rotation Gambit
Numerical Reflection: 4
Fisherman's Gambit
Hadamard's Distillation
Subtractive Distillation
Jester's Gambit
Numerical Reflection: 2
Flock's Gambit
Huginn's Gambit
Consideration: }
Jester's Gambit
Thoth's Gambit
Bookkeeper's Gambit: vvv
}