You are on page 1of 3

2021-09-30

#include <term.h>
#include <stdio.h>
#include <unistd.h>
#include <iostream>

inline void gotoxy(int x, int y){


putp(tparm(cursor_address, y, x));
}

int main(void){
int r, g, b;
int fg_color, bg_color;
const double sin60=0.86602540378444, cos30=sin60;
const double cos60=0.5, sin30=cos60;
int xc, yc;
int x, y;
int rep;
int n, step;

setupterm(NULL, STDOUT_FILENO, NULL); // Carrega parâmetros do terminal e


associa a saída padrão (stdout).

// columns e lines são variáveis globais da terminfo.


xc=columns/2;
yc=lines/2;

// putp() envia para o terminal um parâmetro da Terminfo.


// Os parâmetros, por sua vez, são variáveis globais ou macros.
putp(exit_attribute_mode);
rep=0;
do {
step=1;
n=1;
while(n>0){
putp(exit_attribute_mode);
putp(clear_screen);
for(r=0; r<n; r++){
for(g=0; g<n; g++){
for(b=0; b<n; b++){
bg_color=4*b+2*g+r;
fg_color=(r+g+b>2? 0: 7);
x=xc+5*(g-r)*cos30;
y=yc-2*(b-(g+r)*sin30);
putp(tparm(set_a_foreground, fg_color));
- 1/3 -
2021-09-30
putp(tparm(set_a_background, bg_color));
gotoxy(x, y-1);
std::cout << " OTOTOTO ";
gotoxy(x, y);
printf(" %3d ", bg_color);
}
}
}
fflush(stdout); // Força atualização imediata do terminal (stdio
normalmente bufferiza operações).
//sleep(1);
usleep(250000);
if(n==2)
step=-step;
n+=step;
}
} while(rep++<10);
rep=0;

if(max_colors>16){ // max_colors é uma variável global da Terminfo.


do {
step=1;
n=1;
while(n>0){
putp(exit_attribute_mode);
putp(clear_screen);
for(r=0; r<n; r++){
for(g=0; g<n; g++){
for(b=0; b<n; b++){
bg_color=16+36*r+6*g+b;
fg_color=16+(r+g+b>8? 0: 215);
x=xc+5*(g-r)*cos30;
y=yc-2*(b-(g+r)*sin30);
putp(tparm(set_a_foreground, fg_color));
putp(tparm(set_a_background, bg_color));
gotoxy(x, y-1);
printf(" ");
gotoxy(x, y);
printf(" %3d ", bg_color);
}
}
}
fflush(stdout);
//sleep(1);
usleep(250000);
- 2/3 -
2021-09-30
if(n==6)
step=-step;
n+=step;
}
} while(rep++<10);
}
putp(exit_attribute_mode);
putp(tparm(cursor_address, lines-3, 0));
for(int cor=0; cor<max_colors; cor++){
putp(tparm(set_a_foreground, cor));
printf("Cor %d normal ", cor);
putp(enter_bold_mode);
printf("e \"bold\".\n");
putp(exit_attribute_mode);
}
putp(exit_attribute_mode);
printf("Cor reset normal ");
putp(enter_bold_mode);
printf("e \"bold\".\n");
putp(exit_attribute_mode);

return 0;
}

- 3/3 -

You might also like