Page 1 of 1

One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 7:16 am
by Michael Vogel

Code: Select all

; Define (Windows)

	EnableExplicit

	Macro ConsoleHandle()
		GetStdHandle_( #STD_OUTPUT_HANDLE ) 
	EndMacro

	Structure tConsole_COORD
		StructureUnion
			coord.COORD
			long.l
		EndStructureUnion
	EndStructure

	Procedure ConsoleBufferLocate(x,y)

		Protected ConsoleBufferInfo.CONSOLE_SCREEN_BUFFER_INFO
		Protected hConsole
		Protected location.tConsole_COORD

		hConsole = ConsoleHandle()
		GetConsoleScreenBufferInfo_( hConsole,@ConsoleBufferInfo )
		If y >= ConsoleBufferInfo\dwSize\y Or x >= ConsoleBufferInfo\dwSize\x
			ProcedureReturn #False
		EndIf

		location\coord\x = x
		location\coord\y = y
		SetConsoleCursorPosition_( hConsole,location\long )

		ProcedureReturn #True
	EndProcedure

	DataSection
		ShaderChar:
		Data.a " ·*¤############"
		ShaderColF:
		Data.a "@HHHHGO@HGOHGOGO"
		ShaderColB:
		Data.a "@@@@@@@HHHHGGGOO"
		ShaderNorm:
		Data.a " .,-~:;=!*¤#$Ø@©"
	EndDataSection

; EndDefine

OpenConsole("Donut based on a1k0n.net",#PB_Ascii)
ConsoleCursor(0)
   

Macro R(mul,shift,x,y)

	r=x;
	x-(mul*y)>>shift
	y+(mul*r)>>shift
	r=(3145728-x*x-y*y)>>11
	x=(x*r)>>10
	y=(y*r)>>10

EndMacro

Global Dim b.a(2000)
Global Dim z.a(2000)


Procedure Main()

	Protected sA=1024
	Protected cA=0
	Protected sB=1024
	Protected cB=0
	Protected r
	Protected r1,r2
	Protected k2

	Protected i,si,ci
	Protected j,sj,cj

	Protected x0,x1,x2,x3,x4,x5,x6,x7
	Protected x,y,n,o,z

	Repeat

		FillMemory(@b(1),2000,0,#PB_Ascii);		Text Buffer
		FillMemory(@z(1),2000,127,#PB_Ascii);	Z-Buffer

		sj=0
		cj=1024
		For j=0 To 90
			si=0
			ci=1024
			For i=0 To 324
				R1=1
				R2=2048
				K2=5100*1024

				x0=R1*cj+R2
				x1=(ci*x0)>>10
				x2=(cA*sj)>>10
				x3=(si*x0)>>10
				x4=R1*x2 - ((sA*x3)>>10)
				x5=(sA*sj)>>10
				x6=K2 + R1*1024*x5 + cA*x3
				x7=(cj*si)>>10
				x=40 + 30*(cB*x1 - sB*x4)/x6
				y=12 + 15*(cB*x4 + sB*x1)/x6
				N=((((-cA*x7 - cB*(((-sA*x7)>>10) + x2) - ci*((cj*sB)>>10))>>10) - x5) * 22)>>11; 0-15
				o=x + 80 * y
				z=(x6-K2)>>15

				If (25 > y And y > 0 And x > 0 And 80 > x And z<z(o))
					z(o)=z
					If n>=0
						b(o)=n
					EndIf
				EndIf
				R(5,8,ci,si)
			Next
			R(9,7,cj,sj)
		Next j

		ConsoleBufferLocate(0,0)
		ConsoleColor(15,0)
		For i=1 To 2000
			j=b(i)
			If GetKeyState_(#VK_SHIFT)&128
				ConsoleColor(PeekA(?ShaderColF+j)-'@',PeekA(?ShaderColB+j)-'@')
				Print(Chr(PeekA(?ShaderChar+j)))
			Else
				Print(Chr(PeekA(?ShaderNorm+j)))
			EndIf
			If i%80=0
				PrintN("")
			EndIf
			R(7,10,cA,sA);
			R(5,9,cB,sB);
		Next i
		Delay(25)
	Until Inkey()
	
EndProcedure

Main()

Re: One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 7:24 am
by Jeromyal
MMMM Donuts, is there anything they can't do?

Re: One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 8:39 am
by NicTheQuick
It's not for all. It does not run on Linux. :cry:

Re: One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 8:42 am
by BarryG
Michael Vogel wrote: Thu Jun 22, 2023 7:16 amN=((((-cA*x7 - cB*(((-sA*x7)>>10) + x2) - ci*((cj*sB)>>10))>>10) - x5) * 22)>>11
:shock: How do you even understand what that does?

Re: One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 9:48 am
by Little John
BarryG wrote: Thu Jun 22, 2023 8:42 am
Michael Vogel wrote: Thu Jun 22, 2023 7:16 amN=((((-cA*x7 - cB*(((-sA*x7)>>10) + x2) - ci*((cj*sB)>>10))>>10) - x5) * 22)>>11
:shock: How do you even understand what that does?
Math problems?
Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]. :mrgreen:

Re: One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 1:28 pm
by benubi
BarryG wrote: Thu Jun 22, 2023 8:42 am
Michael Vogel wrote: Thu Jun 22, 2023 7:16 amN=((((-cA*x7 - cB*(((-sA*x7)>>10) + x2) - ci*((cj*sB)>>10))>>10) - x5) * 22)>>11
:shock: How do you even understand what that does?
He simply eats better donuts than you or me. :lol:

Re: One donut for all (quick and dirty)

Posted: Thu Jun 22, 2023 5:16 pm
by Michael Vogel
NicTheQuick wrote: Thu Jun 22, 2023 8:39 am It's not for all. It does not run on Linux. :cry:
If you have a function to set the cursor to the top left console position then it shouldn't be to difficult to feed Linux... :idea:
BTW the expression with VK_SHIFT can be removed as well.

And for the math part - it looks a bit complicated at the first moment but it has been well explained here: https://www.a1k0n.net/2011/07/20/donut-math.html

Re: One donut for all (quick and dirty)

Posted: Fri Jun 23, 2023 1:04 am
by BarryG
Michael Vogel wrote: Thu Jun 22, 2023 5:16 pmAnd for the math part - it looks a bit complicated at the first moment but it has been well explained here: https://www.a1k0n.net/2011/07/20/donut-math.html
https://youtu.be/q6gRZ7iq4W4?t=114 :lol:

Re: One donut for all (quick and dirty)

Posted: Fri Jun 23, 2023 7:44 am
by Kiffi

Re: One donut for all (quick and dirty)

Posted: Sat Jun 24, 2023 4:25 pm
by Nituvious
I wan to start a petition that requires all eye candy/graphic programming to be accompanied by a screenshot for those of us who can't build the example :mrgreen: