Discuss Scratch

NxNmultiply
Scratcher
100+ posts

Cross-language workaround

wait until <>
while(!());

Last edited by NxNmultiply (June 14, 2020 08:59:58)

NxNmultiply
Scratcher
100+ posts

Cross-language workaround

https://scratch.mit.edu/projects/407331121/

In C++:
#include <windows.h>
#include <stdint.h>
	const uint16_t width = 80;
	const uint16_t height = 30;
	SMALL_RECT testscreenrect={0, 0, width-1, height-1};
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	CHAR_INFO screen[width*height];
typedef struct _CONSOLE_SCREEN_BUFFER_INFOEX {
  ULONG      cbSize;
  COORD      dwSize;
  COORD      dwCursorPosition;
  WORD       wAttributes;
  SMALL_RECT srWindow;
  COORD      dwMaximumWindowSize;
  WORD       wPopupAttributes;
  BOOL       bFullscreenSupported;
  COLORREF   ColorTable[16];
} CONSOLE_SCREEN_BUFFER_INFOEX, *PCONSOLE_SCREEN_BUFFER_INFOEX;
extern "C" BOOL WINAPI GetConsoleScreenBufferInfoEx(
  HANDLE hConsoleOutput,
  PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
);
extern "C" BOOL WINAPI SetConsoleScreenBufferInfoEx(
  HANDLE hConsoleOutput,
  PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
);
void initscreen(){
	SetConsoleOutputCP(437);
	CONSOLE_CURSOR_INFO temp2={100, 0};
	SetConsoleCursorInfo(hConsole, &temp2);
	CONSOLE_SCREEN_BUFFER_INFO temp;
	GetConsoleScreenBufferInfo(hConsole, &temp);
	SetConsoleScreenBufferSize(hConsole, {width, temp.dwSize.Y});
	SetConsoleScreenBufferSize(hConsole, {temp.dwSize.X, height});
	SetConsoleScreenBufferSize(hConsole, {width, height});
	SetConsoleWindowInfo(hConsole, 1, &testscreenrect);
	SetConsoleScreenBufferSize(hConsole, {width, height});
	CONSOLE_SCREEN_BUFFER_INFOEX colorinfo;
	colorinfo.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
	HMODULE KERNEL32 = LoadLibrary("KERNEL32.dll");
	if (KERNEL32 != NULL){
		auto GetConsoleScreenBufferInfoExfunction = reinterpret_cast<decltype(GetConsoleScreenBufferInfoEx)*>(GetProcAddress(KERNEL32, "GetConsoleScreenBufferInfoEx"));
		if (GetConsoleScreenBufferInfoExfunction != NULL){
			GetConsoleScreenBufferInfoExfunction(hConsole, &colorinfo);
		}
	}
	colorinfo.dwSize = {width, height};
	colorinfo.srWindow.Left = 0;
	colorinfo.srWindow.Top = 0;
	colorinfo.srWindow.Right = width;
	colorinfo.srWindow.Bottom = height;
	for(int i=0; i<16; i++){
		colorinfo.ColorTable[i] = (i&1)*0xAA0000+(i&2)/2*0x00AA00+(i&4)/4*0x0000AA+(i&8)/8*0x555555;
	}
	if (KERNEL32 != NULL){
		auto SetConsoleScreenBufferInfoExfunction = reinterpret_cast<decltype(SetConsoleScreenBufferInfoEx)*>(GetProcAddress(KERNEL32, "SetConsoleScreenBufferInfoEx"));
		if (SetConsoleScreenBufferInfoExfunction != NULL){
			SetConsoleScreenBufferInfoExfunction(hConsole, &colorinfo);
		}
	}
}
int main(){
	initscreen();
	const char* colortable = "\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
\x00\x00\x00\x00\x10\x10\x10\x10\x20\x20\x20\x20\x30\x30\x30\x30\x40\x40\x40\x40\x50\x50\x50\x50\x60\x60\x60\x60\x70\x70\x70\x70\x80\x80\x80\x80\x90\x90\x90\x90\xa0\xa0\xa0\xa0\xb0\xb0\xb0\xb0\xc0\xc0\xc0\xc0\xd0\xd0\xd0\xd0\xe0\xe0\xe0\xe0\xf0\xf0\xf0\xf0pppppppppppppppp\
\x00\x00\x00\x00\x01\x01\x01\x01\x02\x02\x02\x02\x03\x03\x03\x03\x04\x04\x04\x04\x05\x05\x05\x05\x06\x06\x06\x06\x07\x07\x07\x07\x08\x08\x08\x08\x09\x09\x09\x09\x0a\x0a\x0a\x0a\x0b\x0b\x0b\x0b\x0c\x0c\x0c\x0c\x0d\x0d\x0d\x0d\x0e\x0e\x0e\x0e\x0f\x0f\x0f\x0fpppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\x09\x09\x0a\x0a\x0b\x0b\x0c\x0c\x0d\x0d\x0e\x0e\x0f\x0f\x10\x10\x11\x11\x12\x12\x13\x13\x14\x14\x15\x15\x16\x16\x17\x17\x18\x18\x19\x19\x1a\x1a\x1b\x1b\x1c\x1c\x1d\x1d\x1e\x1e\x1f\x1fpppppppppppppppp\
  !!\"\"##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??pppppppppppppppp\
@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\\\]]^^__pppppppppppppppp\
``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~\x7f\x7fpppppppppppppppp\
\x80\x80\x81\x81\x82\x82\x83\x83\x84\x84\x85\x85\x86\x86\x87\x87\x88\x88\x89\x89\x8a\x8a\x8b\x8b\x8c\x8c\x8d\x8d\x8e\x8e\x8f\x8f\x90\x90\x91\x91\x92\x92\x93\x93\x94\x94\x95\x95\x96\x96\x97\x97\x98\x98\x99\x99\x9a\x9a\x9b\x9b\x9c\x9c\x9d\x9d\x9e\x9e\x9f\x9fpppppppppppppppp\
\xa0\xa0\xa1\xa1\xa2\xa2\xa3\xa3\xa4\xa4\xa5\xa5\xa6\xa6\xa7\xa7\xa8\xa8\xa9\xa9\xaa\xaa\xab\xab\xac\xac\xad\xad\xae\xae\xaf\xaf\xb0\xb0\xb1\xb1\xb2\xb2\xb3\xb3\xb4\xb4\xb5\xb5\xb6\xb6\xb7\xb7\xb8\xb8\xb9\xb9\xba\xba\xbb\xbb\xbc\xbc\xbd\xbd\xbe\xbe\xbf\xbfpppppppppppppppp\
\xc0\xc0\xc1\xc1\xc2\xc2\xc3\xc3\xc4\xc4\xc5\xc5\xc6\xc6\xc7\xc7\xc8\xc8\xc9\xc9\xca\xca\xcb\xcb\xcc\xcc\xcd\xcd\xce\xce\xcf\xcf\xd0\xd0\xd1\xd1\xd2\xd2\xd3\xd3\xd4\xd4\xd5\xd5\xd6\xd6\xd7\xd7\xd8\xd8\xd9\xd9\xda\xda\xdb\xdb\xdc\xdc\xdd\xdd\xde\xde\xdf\xdfpppppppppppppppp\
\xe0\xe0\xe1\xe1\xe2\xe2\xe3\xe3\xe4\xe4\xe5\xe5\xe6\xe6\xe7\xe7\xe8\xe8\xe9\xe9\xea\xea\xeb\xeb\xec\xec\xed\xed\xee\xee\xef\xef\xf0\xf0\xf1\xf1\xf2\xf2\xf3\xf3\xf4\xf4\xf5\xf5\xf6\xf6\xf7\xf7\xf8\xf8\xf9\xf9\xfa\xfa\xfb\xfb\xfc\xfc\xfd\xfd\xfe\xfe\xff\xffpppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp";
	const char* texttable = "\
The quick brown fox jumps over the lazy dog.                                    \
                                                                                \
All CP437 characters:                                                           \
\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?                \
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f                \
\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf                \
\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff                \
                                                                                \
\xda\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc2\xc4\xbf  \xd6\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd2\xc4\xb7  \xd5\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xd1\xcd\xb8  \xc9\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcb\xcd\xbb          \
\xb3Single table\xb3 \xb3  \xbaMixed1 table\xba \xba  \xb3Mixed2 table\xb3 \xb3  \xba""Double table\xba \xba  \xf4       \
\xc3\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc5\xc4\xb4  \xc7\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd7\xc4\xb6  \xc6\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xd8\xcd\xb5  \xcc\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xce\xcd\xb9  \xb3       \
\xc0\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc1\xc4\xd9  \xd3\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd0\xc4\xbd  \xd4\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcf\xcd\xbe  \xc8\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xca\xcd\xbc  \xf5       \
                                                                                \
16 colors:                                                                      \
                                                                                \
\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb                \
                                                                                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
                                                                                \
                                                                                \
                                                                                \
                                                                                \
                                                                                \
";
	for(int i=0; i<width*height; i++){
		screen[i].Attributes = (uint8_t)colortable[i];
		screen[i].Char.AsciiChar = (uint8_t)texttable[i];
	}
	WriteConsoleOutput(hConsole, screen, {width, height}, {0, 0}, &testscreenrect);
	while(true);
}

So, how does it work? It of course works (shown here on Windows Vista):


However, by changing the font, it is possible to achieve a different size of the project:

Last edited by NxNmultiply (July 1, 2020 07:31:58)

NxNmultiply
Scratcher
100+ posts

Cross-language workaround

Sheep_maker wrote:

NxNmultiply wrote:

(()mod())

The modulo operation does not exist on doubles, it is only a mathematical abstraction of Scratch (and Javascript). Therefore it must be implemented in software, therefore long double to handle intermediate precision.
Doesn't C++ have the % operator? It should be roughly identical to JavaScript's %, which is a remainder operator, so I think you could just translate Scratch's implementation of the mod block:
double mod(double n, double modulus) {
  double result = n % modulus;
  if (result / modulus < 0) result += modulus;
  return result;
}
The % is an integer operator.
Maximouse
Scratcher
1000+ posts

Cross-language workaround

NxNmultiply wrote:

The % is an integer operator.
There is std::fmod.

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.
Be strong

Paddle2See wrote:

It's impressive how many suggestions are duplicates!
NxNmultiply
Scratcher
100+ posts

Cross-language workaround

([sqrt v] of ())
#include <math.h>
sqrt();

#include <iostream>
char* answer;
std::cin >> answer; // or whatever was the last answer code
...;
(answer)
answer;

But if the project utilizes Unicode answer, the answer must be instead declared as an at least sixteen bit pointer, which char* isn't necessarily.

Last edited by NxNmultiply (July 4, 2020 12:44:00)

Boomer001
Scratcher
1000+ posts

Cross-language workaround

say [Hello world!]
in bash and PHP:
echo "Hello world!"

Be moist Be very moisty moist And stay moist Be the opposite of dry

CHECK OUT MY FORUM STATS



















Powered by DjangoBB

Standard | Mobile