Update GodDoodle.ZC

Run code through https://techiedelight.com/tools/clike
This commit is contained in:
Arsenic Blood 2023-10-08 22:40:37 -04:00 committed by GitHub
parent fcedd4b421
commit f0df38f5c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,192 +1,240 @@
#help_index "God;Graphics/Sprite;Sprites" #help_index "God;Graphics/Sprite;Sprites"
U0 GodDoodleDraw(CTask *task,CDC *dc) U0 GodDoodleDraw(CTask *task, CDC *dc)
{ {
GrBlot(dc,0,0,god.doodle_dc); GrBlot(dc, 0, 0, god.doodle_dc);
if (Blink) { if (Blink)
if (god.doodle_done) { {
dc->color=RED; if (god.doodle_done)
GrPrint(dc,(task->pix_width-FONT_WIDTH*29)>>1, {
(task->pix_height-3*FONT_HEIGHT)>>1, dc->color = RED;
"Press <ESC> to insert sprite."); GrPrint(dc, (task->pix_width - FONT_WIDTH * 29) >> 1,
GrPrint(dc,(task->pix_width-FONT_WIDTH*39)>>1, (task->pix_height - 3 * FONT_HEIGHT) >> 1,
(task->pix_height-3*FONT_HEIGHT)>>1+2*FONT_HEIGHT, "Press <ESC> to insert sprite.");
"Press <SHIFT-ESC> to throw-away sprite."); GrPrint(dc, (task->pix_width - FONT_WIDTH * 39) >> 1,
} else { (task->pix_height - 3 * FONT_HEIGHT) >> 1 + 2 * FONT_HEIGHT,
dc->color=GREEN; "Press <SHIFT-ESC> to throw-away sprite.");
GrPrint(dc,(task->pix_width-FONT_WIDTH*25)>>1, }
(task->pix_height-FONT_HEIGHT)>>1, else
"Press <SPACE> repeatedly."); {
} dc->color = GREEN;
} GrPrint(dc, (task->pix_width - FONT_WIDTH * 25) >> 1,
(task->pix_height - FONT_HEIGHT) >> 1,
"Press <SPACE> repeatedly.");
}
}
} }
U0 GodDoodleSmooth(I64 num) U0 GodDoodleSmooth(I64 num)
{ {
CDC *dc=DCExt(god.doodle_dc,0,0, CDC *dc = DCExt(god.doodle_dc, 0, 0,
god.doodle_dc->width-1,god.doodle_dc->height-1); god.doodle_dc->width - 1, god.doodle_dc->height - 1);
I64 i,x,y,x1,y1,c,histogram[16],best,best_cnt,c_old=god.doodle_dc->color; I64 i, x, y, x1, y1, c, histogram[16], best, best_cnt, c_old = god.doodle_dc->color;
for (y=0;y<god.doodle_dc->height;y++) for (y = 0; y < god.doodle_dc->height; y++)
for (x=0;x<god.doodle_dc->width;x++) { for (x = 0; x < god.doodle_dc->width; x++)
MemSet(histogram,0,sizeof(histogram)); {
for (y1=y-num;y1<=y+num;y1++) MemSet(histogram, 0, sizeof(histogram));
for (x1=x-num;x1<=x+num;x1++) { for (y1 = y - num; y1 <= y + num; y1++)
c=GrPeek(dc,x1,y1); for (x1 = x - num; x1 <= x + num; x1++)
if (0<=c<=15) {
histogram[c]++; c = GrPeek(dc, x1, y1);
} if (0 <= c <= 15)
best=BLACK; histogram[c]++;
best_cnt=-1; }
for (i=0;i<16;i++)
if (histogram[i]>best_cnt) { best = BLACK;
best=i; best_cnt = -1;
best_cnt=histogram[i]; for (i = 0; i < 16; i++)
} if (histogram[i] > best_cnt)
god.doodle_dc->color=best; {
GrPlot(god.doodle_dc,x,y); best = i;
} best_cnt = histogram[i];
god.doodle_dc->color=c_old; }
DCDel(dc);
god.doodle_dc->color = best;
GrPlot(god.doodle_dc, x, y);
}
god.doodle_dc->color = c_old;
DCDel(dc);
} }
U0 GodDoodleBitsIns(I64 num_bits,I64 n) U0 GodDoodleBitsIns(I64 num_bits, I64 n)
{//Insert bits into God doodle bit fifo. {
I64 i; //Insert bits into God doodle bit fifo.
for (i=0;i<num_bits;i++) { I64 i;
FifoU8Insert(god.doodle_fifo,n&1); for (i = 0; i < num_bits; i++)
n>>=1; {
} FifoU8Insert(god.doodle_fifo, n & 1);
n >>= 1;
}
} }
U0 GodDoodleHexIns(U8 *st) U0 GodDoodleHexIns(U8 *st)
{//Insert hex record into God doodle bit fifo. {
U8 buf[2]; //Insert hex record into God doodle bit fifo.
if (st) { U8 buf[2];
buf[1]=0; if (st)
while (*buf=*st++) {
if (Bt(char_bmp_hex_numeric,*buf)) buf[1] = 0;
GodDoodleBitsIns(4,rev_bits_table[Str2I64(buf,16)]>>4); while (*buf = *st++)
} if (Bt(char_bmp_hex_numeric, *buf))
GodDoodleBitsIns(4, rev_bits_table[Str2I64(buf, 16)] >> 4);
}
} }
I64 GodDoodleBits(I64 num_bits) I64 GodDoodleBits(I64 num_bits)
{ {
U8 b; U8 b;
I64 res=0; I64 res = 0;
while (num_bits) { while (num_bits)
if (FifoU8Remove(god.doodle_fifo,&b)) { {
res=res<<1+b; if (FifoU8Remove(god.doodle_fifo, &b))
num_bits--; {
} else { res = res << 1 + b;
god.doodle_ch=CharGet(,FALSE); num_bits--;
if (god.doodle_ch==CH_ESC||god.doodle_ch==CH_SHIFT_ESC) }
throw; else
else if (god.doodle_ch=='\n') { {
DCFill(god.doodle_dc,WHITE); god.doodle_ch = CharGet(, FALSE);
FifoU8Flush(god.doodle_fifo); if (god.doodle_ch == CH_ESC || god.doodle_ch == CH_SHIFT_ESC)
} else if ('0'<=god.doodle_ch<='9') throw;
GodDoodleSmooth(god.doodle_ch-'0'); else if (god.doodle_ch == '\n')
else {
GodDoodleBitsIns(GOD_GOOD_BITS,KbdMouseEventTime>>GOD_BAD_BITS); DCFill(god.doodle_dc, WHITE);
} FifoU8Flush(god.doodle_fifo);
} }
return res; else if ('0' <= god.doodle_ch <= '9')
GodDoodleSmooth(god.doodle_ch - '0');
else
GodDoodleBitsIns(GOD_GOOD_BITS, KbdMouseEventTime >> GOD_BAD_BITS);
}
}
return res;
} }
public U8 *GodDoodleSprite(U8 *hex=NULL) public U8 *GodDoodleSprite(U8 *hex = NULL)
{//Make God draw sprite. $LK+PU,"Holy Spirit Instructions",A="FI:::/Adam/God/HSNotes.DD"$ {
I64 i,j,w,h,x,y,ch; //Make God draw sprite. $LK+PU,"Holy Spirit Instructions",A="FI:::/Adam/God/HSNotes.DD"$
U8 *elems; I64 i, j, w, h, x, y, ch;
U8 *elems;
if (god.doodle_dc) return NULL; if (god.doodle_dc)
god.doodle_done=FALSE; return NULL;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$ god.doodle_done = FALSE;
AutoComplete; SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
WinBorder; AutoComplete;
WinMax; WinBorder;
WinMax;
if (!hex) if (!hex)
PopUpOk("The $LK+PU,"Holy Spirit",A="FI:::/Adam/God/HSNotes.DD"$ can puppet you.\n\n" PopUpOk("The $LK+PU,"Holy Spirit ",A="FI::: /Adam/God / HSNotes.DD "$ can puppet you.\n\n"
"Press $$GREEN$$<SPACE>$$FG$$ until it finishes."); "Press $$GREEN$$<SPACE>$$FG$$ until it finishes.");
god.doodle_ch=0; god.doodle_ch = 0;
god.doodle_dc=DCNew(Fs->pix_width,Fs->pix_height); god.doodle_dc = DCNew(Fs->pix_width, Fs->pix_height);
DCFill(god.doodle_dc,WHITE); DCFill(god.doodle_dc, WHITE);
w=god.doodle_dc->width; w = god.doodle_dc->width;
h=god.doodle_dc->height; h = god.doodle_dc->height;
Fs->draw_it=&GodDoodleDraw; Fs->draw_it = &GodDoodleDraw;
FifoU8Flush(god.doodle_fifo); FifoU8Flush(god.doodle_fifo);
GodDoodleHexIns(hex); GodDoodleHexIns(hex);
try { try
for (i=0;i<3;i++) { {
god.doodle_dc->color=RED; for (i = 0; i < 3; i++)
for (j=0;j<29;j++) {
switch [GodDoodleBits(3)] { god.doodle_dc->color = RED;
case 0: for (j = 0; j < 29; j++)
GrEllipse3(god.doodle_dc, switch[GodDoodleBits(3)]
(w-1)*GodDoodleBits(5)/15.5-w/2, {
(h-1)*GodDoodleBits(5)/15.5-h/2,0, case 0:
(w-1)*GodDoodleBits(5)/15.5,(h-1)*GodDoodleBits(5)/15.5); GrEllipse3(god.doodle_dc,
break; (w - 1) * GodDoodleBits(5) / 15.5 - w / 2,
case 1: (h - 1) * GodDoodleBits(5) / 15.5 - h / 2, 0,
GrCircle3(god.doodle_dc, (w - 1) * GodDoodleBits(5) / 15.5, (h - 1) * GodDoodleBits(5) / 15.5);
(w-1)*GodDoodleBits(5)/15.5-w/2, break;
(h-1)*GodDoodleBits(5)/15.5-h/2,0, case 1:
(w-1)*GodDoodleBits(5)/15.5); GrCircle3(god.doodle_dc,
break; (w - 1) * GodDoodleBits(5) / 15.5 - w / 2,
case 2: (h - 1) * GodDoodleBits(5) / 15.5 - h / 2, 0,
GrBorder(god.doodle_dc, (w - 1) * GodDoodleBits(5) / 15.5);
(w-1)*GodDoodleBits(5)/15.5-w/2, break;
(h-1)*GodDoodleBits(5)/15.5-h/2, case 2:
(w-1)*GodDoodleBits(5)/15.5,(h-1)*GodDoodleBits(5)/15.5); GrBorder(god.doodle_dc,
break; (w - 1) * GodDoodleBits(5) / 15.5 - w / 2,
case 3...7: (h - 1) * GodDoodleBits(5) / 15.5 - h / 2,
GrLine3(god.doodle_dc, (w - 1) * GodDoodleBits(5) / 15.5, (h - 1) * GodDoodleBits(5) / 15.5);
(w-1)*GodDoodleBits(4)/15,(h-1)*GodDoodleBits(4)/15,0, break;
(w-1)*GodDoodleBits(4)/15,(h-1)*GodDoodleBits(4)/15,0); case 3...7:
break; GrLine3(god.doodle_dc,
(w - 1) * GodDoodleBits(4) / 15, (h - 1) * GodDoodleBits(4) / 15, 0,
(w - 1) * GodDoodleBits(4) / 15, (h - 1) * GodDoodleBits(4) / 15, 0);
break;
}
for (j = 0; j < 6; j++)
{
x = (w - 1) * GodDoodleBits(5) / 31 + w / 64;
y = (h - 1) * GodDoodleBits(5) / 31 + h / 64;
switch[GodDoodleBits(2)]
{
case 0:
god.doodle_dc->color = BLACK;
break;
case 1:
god.doodle_dc->color = DKGRAY;
break;
case 2:
god.doodle_dc->color = LTGRAY;
break;
case 3:
god.doodle_dc->color = WHITE;
break;
}
GrFloodFill3(god.doodle_dc, x, y, 0);
}
GodDoodleSmooth(3);
}
god.doodle_done = TRUE;
if (!hex)
{
do ch = CharGet(, FALSE);
while (ch != CH_ESC && ch != CH_SHIFT_ESC);
}
else
ch = CH_ESC;
} }
for (j=0;j<6;j++) {
x=(w-1)*GodDoodleBits(5)/31+w/64; catch
y=(h-1)*GodDoodleBits(5)/31+h/64; {
switch [GodDoodleBits(2)] { Fs->catch_except = TRUE;
case 0: god.doodle_dc->color=BLACK; break; ch = CH_SHIFT_ESC;
case 1: god.doodle_dc->color=DKGRAY; break;
case 2: god.doodle_dc->color=LTGRAY; break;
case 3: god.doodle_dc->color=WHITE; break;
} }
GrFloodFill3(god.doodle_dc,x,y,0);
} DCFill;
GodDoodleSmooth(3); SettingsPop;
} if (ch == CH_ESC)
god.doodle_done=TRUE; elems = DC2Sprite(god.doodle_dc);
if (!hex) { else
do ch=CharGet(,FALSE); elems = NULL;
while (ch!=CH_ESC && ch!=CH_SHIFT_ESC); DCDel(god.doodle_dc);
} else god.doodle_dc = NULL;
ch=CH_ESC; return elems;
} catch {
Fs->catch_except=TRUE;
ch=CH_SHIFT_ESC;
}
DCFill;
SettingsPop;
if (ch==CH_ESC)
elems=DC2Sprite(god.doodle_dc);
else
elems=NULL;
DCDel(god.doodle_dc);
god.doodle_dc=NULL;
return elems;
} }
#help_index "God" #help_index "God"
public U0 GodDoodle(U8 *hex=NULL) public U0 GodDoodle(U8 *hex = NULL)
{//Make God draw sprite, insert in doc. $LK+PU,"Holy Spirit Instructions",A="FI:::/Adam/God/HSNotes.DD"$ {
U8 *elems; //Make God draw sprite, insert in doc. $LK+PU,"Holy Spirit Instructions",A="FI:::/Adam/God/HSNotes.DD"$
if (elems=GodDoodleSprite(hex)) { U8 *elems;
Sprite(elems); if (elems = GodDoodleSprite(hex))
Free(elems); {
} Sprite(elems);
} Free(elems);
}
}