-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| float A = 0, B = 0; | ||
| float i, j; | ||
| int k; | ||
| float z[1760]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size of z and b should be calculated based on the loop bounds to avoid potential buffer overflows. Consider using sizeof(z) / sizeof(z[0]) and sizeof(b) / sizeof(b[0]) instead of hardcoding the values.
| float i, j; | ||
| int k; | ||
| float z[1760]; | ||
| char b[1760]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good practice to use a constant for the terminal escape sequence to enhance readability and maintainability.
| } | ||
| } | ||
| } | ||
| printf("\x1b[H"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to use a more descriptive variable name than k for the loop counter.
| printf("\x1b[H"); | ||
| for(k = 0; k < 1761; k++) { | ||
| putchar(k % 80 ? b[k] : 10); | ||
| A += 0.00004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using usleep, consider using nanosleep for more precise timing control.
| int main() { | ||
| float A = 0, B = 0; | ||
| float i, j; | ||
| int k; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using bzero instead of memset for zeroing out memory. It might be slightly more efficient in this case.
| } | ||
| printf("\x1b[H"); | ||
| for(k = 0; k < 1761; k++) { | ||
| putchar(k % 80 ? b[k] : 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good practice to add a comment explaining why you're using usleep here. It's not immediately obvious from the code.
| float i, j; | ||
| int k; | ||
| float z[1760]; | ||
| char b[1760]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable z is declared with a size of 1760, but it is used with an index of o, which can potentially be greater than 1760. This could lead to out-of-bounds access and undefined behavior. Consider using a larger size for z to prevent this issue.
| float n = sin(B); | ||
| float t = c * h * g - f * e; | ||
| int x = 40 + 30 * D * (l * h * m - t * n); | ||
| int y= 12 + 15 * D * (l * h * n + t * m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable N is used as an index into the string ".,-~:;=!*#$@", but it can potentially be negative. This could lead to out-of-bounds access and undefined behavior. Consider using abs(N) or clamping the value to the range of the string length to prevent this issue.
| int N = 8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n); | ||
| if(22 > y && y > 0 && x > 0 && 80 > x && D > z[o]) { | ||
| z[o] = D; | ||
| b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code uses putchar to print characters, but it doesn't handle newline characters correctly. The k % 80 condition only checks for multiples of 80, which may not align with the desired output format. Consider using a separate loop to print newlines at the end of each line.
| } | ||
| } | ||
| } | ||
| printf("\x1b[H"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code uses usleep to pause execution for 30 milliseconds, which is a relatively short time. Consider using a longer delay or adjusting the update frequency of the donut animation to make it more visually appealing.
| int main() { | ||
| float A = 0, B = 0; | ||
| float i, j; | ||
| int k; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable z is declared as a float array but used as an array of integers. This could lead to unexpected behavior.
| memset(b,32,1760); | ||
| memset(z,0,7040); | ||
| for(j=0; j < 6.28; j += 0.07) { | ||
| for(i=0; i < 6.28; i += 0.02) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constant 6.28 is used multiple times. Consider defining a constant for it to improve readability and maintainability.
| float n = sin(B); | ||
| float t = c * h * g - f * e; | ||
| int x = 40 + 30 * D * (l * h * m - t * n); | ||
| int y= 12 + 15 * D * (l * h * n + t * m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable N is calculated but not used directly. This might indicate a potential bug or unused code.
| int x = 40 + 30 * D * (l * h * m - t * n); | ||
| int y= 12 + 15 * D * (l * h * n + t * m); | ||
| int o = x + 80 * y; | ||
| int N = 8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if condition checks for D > z[o] but z[o] is initialized to 0. This could lead to unexpected behavior in the first iteration.
| int o = x + 80 * y; | ||
| int N = 8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n); | ||
| if(22 > y && y > 0 && x > 0 && 80 > x && D > z[o]) { | ||
| z[o] = D; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable b is declared as a character array but assigned a string. This could lead to unexpected behavior and potential memory issues.
| } | ||
| } | ||
| printf("\x1b[H"); | ||
| for(k = 0; k < 1761; k++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usleep function call is used for a delay. Consider using a more platform-independent solution, like nanosleep.
| float i, j; | ||
| int k; | ||
| float z[1760]; | ||
| char b[1760]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good practice to use a descriptive variable name instead of a single letter for j and i. For example, angleJ and angleI.
| memset(b,32,1760); | ||
| memset(z,0,7040); | ||
| for(j=0; j < 6.28; j += 0.07) { | ||
| for(i=0; i < 6.28; i += 0.02) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's recommended to avoid using magic numbers. Consider defining constants for values like 6.28, 0.07, and 0.02. This will enhance code readability and maintainability.
| float D = 1 / (c * h * e + f * g + 5); | ||
| float l = cos(i); | ||
| float m = cos(B); | ||
| float n = sin(B); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using > and < for comparisons, using >= and <= would be more robust and prevent potential issues at the boundaries.
| b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0]; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using 10 as the newline character, use the constant \n for better readability.
| printf("\x1b[H"); | ||
| for(k = 0; k < 1761; k++) { | ||
| putchar(k % 80 ? b[k] : 10); | ||
| A += 0.00004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more descriptive variable name than A and B. Names like rotationAngleA and rotationAngleB would improve code understanding.
| float A = 0, B = 0; | ||
| float i, j; | ||
| int k; | ||
| float z[1760]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more descriptive variable name than z for the depth buffer. Something like depthBuffer or zBuffer would be more clear.
| float i, j; | ||
| int k; | ||
| float z[1760]; | ||
| char b[1760]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, b could be renamed to chars or outputChars for better readability.
| float z[1760]; | ||
| char b[1760]; | ||
| printf("\x1b[2J"); | ||
| for(;;) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a comment explaining the purpose of the memset calls would improve clarity.
| } | ||
| } | ||
| printf("\x1b[H"); | ||
| for(k = 0; k < 1761; k++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usleep function is non-portable. Consider using nanosleep for better portability.
| B += 0.00002; | ||
| } | ||
| usleep(30000); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to add a comment explaining the purpose of the return 0 statement.
No description provided.