Logo

dev-resources.site

for different kinds of informations.

Explaining donut like 5 years old Part-3

Published at
12/11/2024
Categories
c
cpp
java
Author
bhjaipal
Categories
3 categories in total
c
open
cpp
open
java
open
Author
8 person written this
bhjaipal
open
Explaining donut like 5 years old Part-3

First fill zBuffer with 0s and buffer with spaces (32 in ascii)

For C, We use string.h library
As float takes 4 bytes, 4 * 1760 = 7040
In java, import java.util.Arrays and use Arrays.fill() function

In C

memset(buffer, ' ', 1760);
memset(zBuffer, 0, 7040);
Enter fullscreen mode Exit fullscreen mode

In Java

Arrays.fill(zBuffer, 0);
Arrays.fill(buffer, ' ');
Enter fullscreen mode Exit fullscreen mode

put 2 nested for loops

for (float theta = 0; theta < 6.28; theta += 0.07) {
    for (float phi = 0; phi < 6.28; phi += 0.02) {
    }
}
Enter fullscreen mode Exit fullscreen mode

First we will understand remaining code after outer for-loop

print "\x1b[H" which clears screen

create for-loop to print all characters in buffer-array

for (int i = 0; i <1761; i++) {
     putchar(i % 80 ? buffer[i] : 10);
     A += 0.00004;
     B += 0.00002;
}
Enter fullscreen mode Exit fullscreen mode

if i is not divisible by 80 i.e. there is some remainder then print the buffer[i] character else newline (\n or 10 in ascii)

then increment A and B so they can rotate in X and Z axis but make them small so that rotation looks smooth

In C, add usleep(10000); because spinning will be very fast so we have to slow it a bit
add unistd.h for accessing this function

c Article's
30 articles in total
Favicon
Top 5 Backend Programming Languages to Learn in 2024
Favicon
Week 2: Diving Deeper into Dynamic Memory, Structures, and Beyond in C Programming
Favicon
The 10 fastest programming languages in the world
Favicon
As 10 Linguagens de Programação mais velozes do mundo
Favicon
This turned out to be my best-performing technical article. Unfortunately I do not have the time to write more like it.
Favicon
Parsing command-line arguments in C
Favicon
Develop a weather application code using c language with date
Favicon
Working with Matter Team Membership Using the IntApp Walls API
Favicon
Reading UTF-8 char by char in C
Favicon
[Rust Self-Study] 1.0. Intro
Favicon
Gone back to learn C Programming 23 years later.
Favicon
Data access in code, using repositories, even with ORMs
Favicon
MockManager in unit tests - a builder pattern used for mocks
Favicon
Explaining donut like 5 years old Part-4 (Last)
Favicon
Explaining donut like 5 years old Part-3
Favicon
How to 100% CPU
Favicon
Explaining donut like 5 years old Part-3
Favicon
How do you print in c language?
Favicon
Tester c'est tricher, compiler c'est douter
Favicon
Pointers in C Programming - Lay Man's Analogy
Favicon
LogInsight
Favicon
Rust in Systems Programming: Why Devs Are Choosing Rust Over C and C++
Favicon
Discover File Splitter & Merger: A Revolutionary Tool for Managing Large Files
Favicon
Unused variables in C/C++: why and how?
Favicon
Jas - My x64 assembler
Favicon
How Does Deep Learning Work? Can You Write Simple Deep Learning Code at Home?
Favicon
Day 1 : Introduction of DSA
Favicon
Cybersecurity: The Shielding the Virtual Universe
Favicon
OKMX8MP-C GDB Remote Debugging Skills
Favicon
Publishing My First AUR Package: CPIG

Featured ones: