#include<math.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>typedefstruct{doublea1;doublea2;doublea3;}singleRow;typedefstruct{singleRowa1;singleRowa2;singleRowa3;}Matrix;singleRowmultiply(singleRowm1,Matrixm2){singleRowres;res.a1=m1.a1*m2.a1.a1+m1.a2*m2.a2.a1+m1.a3*m2.a3.a1;res.a2=m1.a1*m2.a1.a2+m1.a2*m2.a2.a2+m1.a3*m2.a3.a2;res.a3=m1.a1*m2.a1.a3+m1.a2*m2.a2.a3+m1.a3*m2.a3.a3;returnres;}intmain(){intscreen_width=80,height=22;charbuffer[1760];floatzBuffer[1760];floatA=0,B=0;intR2=2,R1=1;printf("\x1b[2J");while(1){memset(buffer,' ',1760);memset(zBuffer,0,7040);for(floattheta=0;theta<6.28;theta+=0.07){for(floatphi=0;phi<6.28;phi+=0.02){singleRowcircle={2+cos(theta),sin(theta),0};// rotation on Y-axisMatrixRy={{cos(phi),0,sin(phi)},{0,1,0},{-sin(phi),0,cos(phi)}};// rotation on X-axisMatrixRx={{1,0,0},{0,cos(A),sin(A)},{0,-sin(A),cos(A)}};// rotation on Z-axisMatrixRz={{cos(B),sin(B),0},{-sin(B),cos(B),0},{0,0,1}};singleRowdonut=multiply(circle,Ry);singleRowrotateX=multiply(donut,Rx);// We will consider it as [Nx, Ny, Nz]singleRowspinningDonut=multiply(rotateX,Rz);floatreciNz=1/(spinningDonut.a3+5);intx=40+30*spinningDonut.a1*reciNz;inty=12+15*spinningDonut.a2*reciNz;// o is index of current bufferinto=x+screen_width*y;intL=8*(spinningDonut.a2-spinningDonut.a3+2*cos(B)*sin(A)*sin(phi)-2*cos(phi)*cos(theta)*sin(B)-2*cos(phi)*sin(B)+2*cos(A)*sin(phi));// donut luminicity will be seen by these characters// these 12charcharOut[]=".,-~:;=!*#$@";if(x<screen_width&&y<height&&zBuffer[o]<reciNz){zBuffer[o]=reciNz;// If L < 0, . will be bufferbuffer[o]=charOut[L>0?L:0];}}}// Clear screenprintf("\x1b[H");for(inti=0;i<1761;i++){// On every 80th character, new line will be printed// If there's a reminder then buffer printedputchar(i%80?buffer[i]:10);A+=0.00004;B+=0.00002;}// Timer to slow down speed a bitusleep(10000);}return0;}
The complete code for Java is
importjava.util.Arrays;classsingleRow{publicdoublea1;publicdoublea2;publicdoublea3;publicsingleRow(doublea1,doublea2,doublea3){this.a1=a1;this.a2=a2;this.a3=a3;}}classMatrix{publicsingleRowa1;publicsingleRowa2;publicsingleRowa3;publicMatrix(singleRowa1,singleRowa2,singleRowa3){this.a1=newsingleRow(a1.a1,a1.a2,a1.a3);this.a2=newsingleRow(a2.a1,a2.a2,a2.a3);this.a3=newsingleRow(a3.a1,a3.a2,a3.a3);}publicstaticsingleRowmultiply(singleRowm1,Matrixm2){singleRowres=newsingleRow(0,0,0);res.a1=(m1.a1*m2.a1.a1)+(m1.a2*m2.a2.a1)+(m1.a3*m2.a3.a1);res.a2=(m1.a1*m2.a1.a2)+(m1.a2*m2.a2.a2)+(m1.a3*m2.a3.a2);res.a3=(m1.a1*m2.a1.a3)+(m1.a2*m2.a2.a3)+(m1.a3*m2.a3.a3);returnres;}}publicclassMain{publicstaticvoidmain(){intscreen_width=80,height=22;char[]buffer=newchar[1760];double[]zBuffer=newdouble[1760];doubleA=0,B=0;intR2=2,R1=1;System.out.print("\u001b[2J");while(true){Arrays.fill(buffer,0,1760,' ');Arrays.fill(zBuffer,0,1760,0);for(floattheta=0;theta<6.28;theta+=0.07){for(floatphi=0;phi<6.28;phi+=0.02){singleRowcircle={2+Math.cos(theta),Math.sin(theta),0};// rotation on Y-axisMatrixRy=newMatrix(newsingleRow(Math.cos(phi),0,Math.sin(phi)),newsingleRow(0,1,0),newsingleRow(-Math.sin(phi),0,Math.cos(phi)));// rotation on X-axisMatrixRx=newMatrix(newsingleRow(1,0,0),newsingleRow(0,Math.cos(A),Math.sin(A)),newsingleRow(0,-Math.sin(A),Math.cos(A)));// rotation on Z-axisMatrixRz=newMatrix(newsingleRow(Math.cos(B),Math.sin(B),0),newsingleRow(-Math.sin(B),Math.cos(B),0),newsingleRow(0,0,1));singleRowdonut=Matrix.multiply(circle,Ry);singleRowrotateX=Matrix.multiply(donut,Rx);// We will consider it as [Nx, Ny, Nz]singleRowspinningDonut=Matrix.multiply(rotateX,Rz);floatreciNz=1/(spinningDonut.a3+5);intx=40+30*spinningDonut.a1*reciNz;inty=12+15*spinningDonut.a2*reciNz;// o is index of current bufferinto=x+screen_width*y;intL=8*(spinningDonut.a2-spinningDonut.a3+2*Math.cos(B)*Math.sin(A)*Math.sin(phi)-2*Math.cos(phi)*Math.cos(theta)*Math.sin(B)-2*Math.cos(phi)*Math.sin(B)+2*Math.cos(A)*Math.sin(phi));// donut luminicity will be seen by these characters// these 12char[]charOpts={'.',',','-','~',':',';','=','!','*','#','$','@'};if(x<screen_width&&y<height&&zBuffer[o]<reciNz){zBuffer[o]=reciNz;// If L < 0, . will be bufferbuffer[o]=charOut[L>0?L:0];}}}// Clear screenSystem.out.print("\u001b[H");for(inti=0;i<1761;i++){// On every 80th character, new line will be printed// If there's a reminder then buffer printedSystem.out.print(i%80?buffer[i]:10);A+=0.00004;B+=0.00002;}}}}
Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.
Top comments (0)