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, importjava.util.Arrays
and useArrays.fill()
function
In C
memset(buffer, ' ', 1760);
memset(zBuffer, 0, 7040);
In Java
Arrays.fill(zBuffer, 0);
Arrays.fill(buffer, ' ');
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) {
}
}
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;
}
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
Top comments (0)