One donut for all (quick and dirty)

Everything else that doesn't fall into one of the other PB categories.
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

One donut for all (quick and dirty)

Post 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()
Jeromyal
Enthusiast
Enthusiast
Posts: 216
Joined: Wed Jul 17, 2013 8:49 am

Re: One donut for all (quick and dirty)

Post by Jeromyal »

MMMM Donuts, is there anything they can't do?
User avatar
NicTheQuick
Addict
Addict
Posts: 1520
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: One donut for all (quick and dirty)

Post by NicTheQuick »

It's not for all. It does not run on Linux. :cry:
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
BarryG
Addict
Addict
Posts: 4174
Joined: Thu Apr 18, 2019 8:17 am

Re: One donut for all (quick and dirty)

Post 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?
Little John
Addict
Addict
Posts: 4789
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: One donut for all (quick and dirty)

Post 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:
benubi
Enthusiast
Enthusiast
Posts: 220
Joined: Tue Mar 29, 2005 4:01 pm

Re: One donut for all (quick and dirty)

Post 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:
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: One donut for all (quick and dirty)

Post 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
BarryG
Addict
Addict
Posts: 4174
Joined: Thu Apr 18, 2019 8:17 am

Re: One donut for all (quick and dirty)

Post 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:
User avatar
Kiffi
Addict
Addict
Posts: 1503
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: One donut for all (quick and dirty)

Post by Kiffi »

Hygge
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: One donut for all (quick and dirty)

Post 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:
▓▓▓▓▓▒▒▒▒▒░░░░░
Post Reply