colors, rotations, and more

This commit is contained in:
2024-10-11 00:58:24 -04:00
parent e29f27266a
commit 823a8f79d3
9 changed files with 367 additions and 149 deletions

View File

@@ -24,81 +24,53 @@
2 |OPQRSTU|
---------
As displayed in the above figure, the 0th element, 'A', in the sequence represents (0,0) in 2D space, while the 9th element, 'J' represents (2,1).
=> Calculating the two dimensional area of the console output yields the number of elements in the initial 1D sequence:
(7 * 3) = 21
This may appear obvious, however this is an important connection to make, when considering how the console represents its output.
--------------------------------------------------------------
The console application automatically transforms our 1D sequence, to a 2D sequence displayed on your monitor, based on the size of the console window.
The terminal automatically transforms our 1D sequence, to a 2D sequence displayed on your monitor, based on the size of the window.
As displayed in the above figure, the 0th element, 'A', in the sequence represents (0,0) in 2D space, while the 9th element, 'J' represents (2,1).
The console application will automatically draw the characters on your screen for you.
Because the console application is responsible for transforming our 1D array into a 2D output, we must provide the console with a 1D array.
Therefore in order to draw 2D and 3D elements on the screen, we must construct procedures in the code to represent the transformations from
Since the console is responsible for transforming our 1D array into a 2D output, we must provide the console with a 1D array.
In order to draw 2D and 3D elements on the screen, we must construct procedures in the code to represent the transformations from
higher dimensions, down to the first dimension.
This simple 2d -> 1d transformation is implemented as the `draw` procedure found in the `draw.jai` file in this module.
*/
BLANK_PIXEL : u8 : 0x20;
DEFAULT_PIXEL_CHAR : u8 : #char "#";
Vec2s64 :: struct {
x: s64;
y: s64;
}
Triangle :: struct {
p1: Vec2s64;
p3: Vec2s64;
p2: Vec2s64;
}
Quad :: struct {
p1: Vec2s64;
p2: Vec2s64;
p3: Vec2s64;
p4: Vec2s64;
}
Screen :: struct {
width : s64;
height: s64;
buffer: [..] Char_Info;
}
Char_Info :: struct {
color: COLOR;
char : PIXEL_CHAR;
}
COLOR :: enum u32 {
FG_BLACK :: 0x0000;
FG_DARK_BLUE :: 0x0001;
FG_DARK_GREEN :: 0x0002;
FG_DARK_CYAN :: 0x0003;
FG_DARK_RED :: 0x0004;
FG_DARK_MAGENTA :: 0x0005;
FG_DARK_YELLOW :: 0x0006;
FG_GREY :: 0x0007;
FG_DARK_GREY :: 0x0008;
FG_BLUE :: 0x0009;
FG_GREEN :: 0x000A;
FG_CYAN :: 0x000B;
FG_RED :: 0x000C;
FG_MAGENTA :: 0x000D;
FG_YELLOW :: 0x000E;
FG_WHITE :: 0x000F;
BG_BLACK :: 0x0000;
BG_DARK_BLUE :: 0x0010;
BG_DARK_GREEN :: 0x0020;
BG_DARK_CYAN :: 0x0030;
BG_DARK_RED :: 0x0040;
BG_DARK_MAGENTA :: 0x0050;
BG_DARK_YELLOW :: 0x0060;
BG_GREY :: 0x0070;
BG_DARK_GREY :: 0x0080;
BG_BLUE :: 0x0090;
BG_GREEN :: 0x00A0;
BG_CYAN :: 0x00B0;
BG_RED :: 0x00C0;
BG_MAGENTA :: 0x00D0;
BG_YELLOW :: 0x00E0;
BG_WHITE :: 0x00F0;
}
PIXEL_CHAR :: enum u32 {
PIXEL_SOLID :: 0x2588;
PIXEL_THREEQUARTERS :: 0x2593;
PIXEL_HALF :: 0x2592;
PIXEL_QUARTER :: 0x2591;
buffer: [..] u8;
}
init_screen :: (screen: *Screen, width: s64, height: s64) {
buffer : [..] Char_Info;
buffer : [..] u8;
array_resize(*buffer, width * height);
@@ -114,8 +86,35 @@ resize_screen :: (screen: *Screen, width: s64, height: s64) {
array_resize(*screen.buffer, width * height);
}
maybe_resize_screen :: (screen: *Screen) {
w, h := get_console_size();
should_update := false;
if w != screen.width {
should_update = true;
}
if h != screen.height {
should_update = true;
}
if should_update {
resize_screen(screen, w, h);
}
}
#load "draw.jai";
#load "rotate.jai";
#load "file_operations.jai";
#load "console.jai";
#load "math_extras.jai";
#if OS == .MACOS {
#load "macos/console.jai";
} else {
#assert false "Platform unsupported. Sorry.";
}
#scope_module