On Thu, 2024-12-19 at 18:09 -0800, Keith Thompson wrote:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Ross Finlayson <ross.a.finlayson@gmail.com> writes:
On 12/18/2024 08:14 PM, Keith Thompson wrote:
wij <wyniijj5@gmail.com> writes:
[...]
But, what is the true thing the program is dealing with? What is 'pixel'?
Do you really not know what a pixel is?
[...]
Pixel = "picture element"
You do know what a pixel is. So why did you ask?
My apologies, I didn't pay enough attention to the attribution lines.
wij write "What is 'pixel'"; Ross wrote 'Pixel = "picture element"'.
class Pixel { /* Whatever suitable */ };
int main() {
Array2D<Pixel> img;
load_picture(img, "mydog.jpg");
draw_circle(img, cx,cy, dim);
// cout.set_graphics_mode(...); // if necessary
// for(ssize_t y=img.height()-1; y>=0; --y) {
// cout << StrSeg(&img(0,y), img.width()) << WY_ENDL;
// }
cout << img; // the about can be simplified to one line
};
'Pixel' is just something you can write into Array2D
---------- a_rawkey.cpp
#include <Wy.stdio.h>
#include <Wy.string.h>
using namespace Wy;
int main(int, char* [])
try {
const char usage[]="Type arrow keys (Up,Down,Left,Down) to move around, 'ESC' to exit." WY_ENDL;
Errno r;
cout << usage;
constexpr WeeStr KeyESC("\33");
constexpr WeeStr KeyUp("\33[A");
constexpr WeeStr KeyDown("\33[B");
constexpr WeeStr KeyRight("\33[C");
constexpr WeeStr KeyLeft("\33[D");
constexpr WeeStr CursorUp("\33[1A");
constexpr WeeStr CursorDown("\33[1B");
constexpr WeeStr CursorRight("\33[1C");
constexpr WeeStr CursorLeft("\33[1D");
WeeStr stroke;
for(;;) {
if((r=_get_rawkey(cin,stroke))!=Ok) {
WY_THROW(r);
}
if(stroke==KeyESC) {
break;
}
if(stroke==KeyUp) {
cout << CursorUp;
} else if(stroke==KeyLeft) {
cout << CursorLeft;
} else if(stroke==KeyDown) {
cout << CursorDown;
} else if(stroke==KeyRight) {
cout << CursorRight;
} else {};
}
return 0;
}
catch(const Errno& e) {
cerr << wrd(e) << WY_ENDL;
return e.c_errno();
}
catch(...) {
cerr << "main caught(...)" WY_ENDL;
throw;
};
------------
If the key code from raw mode tty is defined (maybe, but I don't know),
I think C++ writing vi like editor should be much simpler, no need for ncurses.
If back to 'graphics', Pixel can be CSI sequence in this case.
My purpose is a 'C++ graphics'. No need to consider various kinds of
graphics accelerators or 'GUI', which cannot be standardized and would be
wrong goal.
What I now trying to experiment is separating graphics things to another
process. By doing so, 'the C++ code' just plays with Array2D<Pixel>, no need
to include those (mostly) heavy graphics library.