Linux SVGA e programmi grafici in C

Zhong

Nuovo Utente
88
25
CPU
i8
Scheda Madre
supermicro
HDD
nas array
RAM
dual ecc
GPU
rage
Audio
beep
Monitor
lcd
PSU
rack supply
Case
hot rack
OS
red hatt
Buongiorno gente :ciaociao:

dunque, avevo bisogno di scrivere alcuni programmi in C per visualizzare alcune funzioni matematiche,
ma i vecchi programmi in Turbo C (ms-dos) erano limitati a soli 640k di memoria totale.
(parlare di 640k di ram rispetto agli 8 Gigabyte attuali, sembra quasi preistoria informatica :sisi: )
e allora bisognava trovare qualcosa di più moderno, come il Linux e le librerie SVGA.

Purtroppo nel mondo linux esistono mille versioni diverse, sia del sistema operativo, sia dei programmi utente,
e il fatto che qualcosa non funziona come dovrebbe, è praticamente la regola di qualsiasi software.
dopo N+1 prove ho trovato qualcosa che funziona abbastanza bene....
e allora e passiamo subito ai fatti. :look:

Istalliamo su un Hard disk pulito, una copia di Linux mint 17.1 Mate 32 bit ...
senza modificare nulla, ne istallare sfondi e cose strane.

e dopo 1 ora circa di spippolamenti vari ...
colleghiamo internet e...

dal menu --> all application --> software manager
lanciamo il software manager e ricerchiamo la parola chiave svga
Dovrebbe apparire qualcosa di simile :

Screenshot.png

per non sbagliare istalliamo tutti i 3 file (libsvga1 / libsvga1-dev / svgabin) ma non dosbox.
Fatto questo siamo pronti per scrivere il nostro primo programma grafico nel file svga.c

Codice:
/* Yellow circle, compile with gcc svga.c -lvga -lm */ 
 
#include <stdio.h> 
#include <math.h> 
#include <vga.h> 
 
int main(void) 
{ int x,y;   
  float a; 
 
   if (vga_init() < 0) return -1 ;            /* detect video */
   vga_setmode(G1024x768x256);   /* set VGA 1024x768pixel - some low resolution dont work */  
   vga_setcolor(14);                          /* color of pixel : 14 = yellow */ 
    
    for (a=0; a<6.28; a+=0.001) 
   { x=(int)(512+100*cos(a));   
     y=(int)(384-100*sin(a)); 
     vga_drawpixel(x, y);                   /* draw pixel */ 
   } 
  
  getc(stdin);                            /* press a key for exit "/
  vga_setmode(TEXT);                      /* restore textmode */
  
   return 0; 
}

fine parte prima. :ciaociao:

- - - Updated - - -

seconda parte...

con il copia incolla si trasferisce il programma sul file di testo svga.c
(oppure si scarica il file in allegato)
poi si apre il terminal dei comandi e si compila con :

$ su [+ password]

# gcc -o svga svga.c -lvga -lm

la direttiva di compilazione -lvga crea il link alle librerie grafiche
la direttiva -lm crea il link alle librerie matematiche (cos(x), sin(x), ...)
(solo video 1024x768 nativo (mint 17.1 mate) e senza aggiungere sfondi o altri programmi)

se il compilatore non dà errori, si può eseguire con :

# ./svga

oppure se si compila senza direttiva di output

# gcc svga.c -lvga -lm

si esegue con :

# ./a.out

sullo schermo dovrebbe apparire un cerchio giallo nella risoluzione 1024x768 256 colori come questo :

Circle.JPG

poi per uscire dal programma basta premere un tasto qualsiasi.
se tutto va' bene, si dovrebbe tornare al desktop classico di linux mate. :sisi:

- - - Updated - - -

file allegato : 'Untitled Post' | TextUploader.com

- - - Updated - - -

In aggiunta ho anche istallato alcune utility che sembrano non dare problemi :

$ sudo apt-get install rdfind (per cancellare i files duplicati)

$ sudo apt-get install smartmontools (per controllare i parametri smart dell' hard disk)

Da software manager GHex (per visualizzare i codici esadecimali di qualsiasi file)

Per concludere bisogna ricordare sempre il safety idiot USA Style, cioè :
specialmente in questo caso, per i nostri esperimenti di programmazione, bisogna utilizzare un Hard Disk con istallazione pulita,
e senza dati personali, importanti o altri hard disk accessibili dal sistema locale o remoto ! (nas ecc. ecc.)
la possibilià del crash di sistema è altissima ! si possono perdere tutti i dati !
poi non resta che resettare, riavviare, o reistallare tutto.

ciaooooo ! :ciaociao:
 
Ultima modifica:
  • Like
Reactions: Ico Bellungi

Zhong

Nuovo Utente
88
25
CPU
i8
Scheda Madre
supermicro
HDD
nas array
RAM
dual ecc
GPU
rage
Audio
beep
Monitor
lcd
PSU
rack supply
Case
hot rack
OS
red hatt
--- aggiunto ---

Dunque, durante lo sviluppo di molti programmi potrebbe capitare che l'esecuzione genera un loop infinito,
oppure che la simulazione numerica richiede 10^4 anni di calcolo numerico.
Allora in tutti questi casi bisogna interrompere il programma in esecuzione.
Purtroppo interrompere il programma grafico genera lo schermo nero....
ma esiste un modo per tornare al desktop e non perdere il lavoro :

Ctrl+C interrompe il programma grafico il loop infinito e visualizza il black screen.

Ctrl+Alt+F8 riabilita il desktop grafico originale.

Questa procedura funziona bene per il linux mint 17.1 mate 32 bit.
con altri sistemi bisogna provare, magari anche per tentativi...

:ciaociao:
 

Zhong

Nuovo Utente
88
25
CPU
i8
Scheda Madre
supermicro
HDD
nas array
RAM
dual ecc
GPU
rage
Audio
beep
Monitor
lcd
PSU
rack supply
Case
hot rack
OS
red hatt
Alcuni trucchi : Per eseguire il prgramma bisogna entrare nella modalità superuser.
sull' istallazione dell' hard disk basta digitare il comando :
$ su
[password]
invece sulle distro live talvolta funziona il comando :
$ sudo su

inoltre è possibile elencare tutti i comandi grafici della libreria,
esplorando il file vga.h del sorgente. : Welcome To SVGAlib

e frà i più interessanti troviamo :
Codice:
      int vga_setcolor(int color);
      int vga_drawpixel(int x, int y);
      int vga_drawline(int x1, int y1, int x2, int y2);
      int vga_getpixel(int x, int y);

ma forse alcune istruzioni potrebbero non funzionare bene.
(ad esempio sul mio mint 17.3 mate 64 bit mi si pianta e appare una scritta che parla di mouse-device.. boh..)

in allegato il file vga.h

'Untitled Post' | TextUploader.com
 

Zhong

Nuovo Utente
88
25
CPU
i8
Scheda Madre
supermicro
HDD
nas array
RAM
dual ecc
GPU
rage
Audio
beep
Monitor
lcd
PSU
rack supply
Case
hot rack
OS
red hatt
Cosa si può fare di bello in una noiosissima domenica pomeriggio ? :grat:
chi non ricorda le serate passate a programmare il sinclair o il commodore ? :asd:

Commodor.jpg

Ecco allora che mi sono scritto un piccolo programma grafico per visualizzare le funzioni matematiche..
Insomma una cosa preistorica, che però (talvolta) è molto più flessibile dei vari pacchetti software già pronti.
(e comunque il sorgente può essere adattato anche ai nuovissimi raspberry e simili)

il font di caratteri grafico proviene dal sito ufficiale delle Welcome To SVGAlib

- - - Updated - - -

Codice:
/* 
 * SVGALib C-Linux Disegna una funzione 3d  
 * Author : ekkssen IX 
 */ 
 
# include <stdio.h> 
# include <stdlib.h>    // exit  
# include <math.h> 
# include <vga.h> 
 
# define Pi 3.1415926  // Pi-greco 
 
int xo=512, yo=384;    // centro schermo  
 
 
char getpixel (int x, int y) 
{ return vga_getpixel(x,y); } // read a pixel 
 
void putpixel (int x,int y, int c) 
{ vga_setcolor(c);    // set color   
  vga_drawpixel(x,y); // draw pixel  
} 
 
/*  Font di 256 caratteri SVGA 8x8. 
 *  Ogni carattere è rappresentato da 8 unsigned char 
 *  per un totale di 2048 numeri.  
 *  Ogni intero rappresenta una riga di 8 pixel del carattere visualizzato 
 */ 
 
unsigned char font1[2048] = 
{   124,130,186,162,186,130,124,0,126,129,165,129,165,153,129,126, 
    126,129,165,129,153,165,129,126,108,246,246,254,124,56,16,0, 
    16,56,124,254,124,56,16,0,16,56,84,254,84,16,56,0, 
    56,124,254,254,108,16,56,0,16,24,20,20,48,112,96,0, 
    254,254,254,238,254,254,254,0,236,138,138,170,170,170,236,0, 
    142,136,136,140,136,136,232,0,174,170,170,234,170,170,174,0, 
    238,136,136,204,136,136,136,0,238,138,138,142,140,138,234,0, 
    62,34,62,34,102,238,204,0,16,84,40,198,40,84,16,0, 
    240,248,252,254,252,248,240,0,30,62,126,254,126,62,30,0, 
    16,56,124,16,124,56,16,0,238,238,238,238,238,0,238,0, 
    254,68,68,68,68,68,68,0,126,128,188,198,122,2,252,0, 
    0,0,0,0,255,255,0,0,16,56,124,16,124,56,16,254, 
    16,56,124,254,56,56,56,0,56,56,56,254,124,56,16,0, 
    16,24,252,254,252,24,16,0,16,48,126,254,126,48,16,0, 
    144,72,36,18,36,72,144,0,18,36,72,144,72,36,18,0, 
    16,40,68,146,40,68,130,0,130,68,40,146,68,40,16,0, 
    0,0,0,0,0,0,0,0,16,16,16,16,16,0,16,0, 
    40,40,40,0,0,0,0,0,68,254,68,68,68,254,68,0, 
    16,126,144,124,18,252,16,0,66,164,72,16,36,74,132,0, 
    56,68,56,112,138,132,122,0,16,16,32,0,0,0,0,0, 
    8,16,16,16,16,16,8,0,32,16,16,16,16,16,32,0, 
    16,84,56,254,56,84,16,0,16,16,16,254,16,16,16,0, 
    0,0,0,0,0,16,16,32,0,0,0,254,0,0,0,0, 
    0,0,0,0,0,0,16,0,2,4,8,16,32,64,128,0, 
    124,130,130,130,130,130,124,0,240,16,16,16,16,16,254,0, 
    252,2,2,124,128,128,254,0,252,2,2,28,2,2,252,0, 
    130,130,130,126,2,2,2,0,254,128,252,2,2,2,252,0, 
    126,128,252,130,130,130,124,0,252,2,2,2,2,2,2,0, 
    124,130,130,124,130,130,124,0,126,130,130,126,2,2,252,0, 
    0,0,0,16,0,0,16,0,0,0,0,16,0,0,16,32, 
    8,16,32,64,32,16,8,0,0,0,0,254,0,254,0,0, 
    64,32,16,8,16,32,64,0,56,68,4,8,16,0,16,0, 
    60,66,154,170,156,64,62,0,124,130,130,254,130,130,130,0, 
    252,130,130,252,130,130,252,0,124,130,128,128,128,130,124,0, 
    252,130,130,130,130,130,252,0,254,128,128,240,128,128,254,0, 
    254,128,128,240,128,128,128,0,124,130,128,142,130,130,124,0, 
    130,130,130,254,130,130,130,0,254,16,16,16,16,16,254,0, 
    62,2,2,2,130,130,124,0,130,132,136,240,136,132,130,0, 
    128,128,128,128,128,128,254,0,252,146,146,146,146,146,146,0, 
    130,194,162,146,138,134,130,0,124,130,130,130,130,130,124,0, 
    252,130,130,252,128,128,128,0,124,130,130,130,138,134,126,0, 
    252,130,130,252,130,130,130,0,126,128,128,124,2,2,252,0, 
    254,16,16,16,16,16,16,0,130,130,130,130,130,130,124,0, 
    130,130,68,68,40,40,16,0,130,130,130,146,146,146,108,0, 
    130,68,40,16,40,68,130,0,130,130,130,126,2,2,252,0, 
    254,4,8,16,32,64,254,0,56,32,32,32,32,32,56,0, 
    128,64,32,16,8,4,2,0,56,8,8,8,8,8,56,0, 
    16,40,68,130,0,0,0,0,0,0,0,0,0,0,0,255, 
    32,32,16,0,0,0,0,0,0,0,56,68,124,68,68,0, 
    0,0,120,68,120,68,120,0,0,0,60,64,64,64,60,0, 
    0,0,120,68,68,68,120,0,0,0,124,64,112,64,124,0, 
    0,0,124,64,112,64,64,0,0,0,60,64,76,68,60,0, 
    0,0,68,68,124,68,68,0,0,0,124,16,16,16,124,0, 
    0,0,28,4,4,68,56,0,0,0,68,72,112,72,68,0, 
    0,0,64,64,64,64,124,0,0,0,120,84,84,84,84,0, 
    0,0,120,68,68,68,68,0,0,0,56,68,68,68,56,0, 
    0,0,120,68,120,64,64,0,0,0,56,68,68,76,54,0, 
    0,0,120,68,120,68,68,0,0,0,60,64,56,4,120,0, 
    0,0,124,16,16,16,16,0,0,0,68,68,68,68,56,0, 
    0,0,68,68,40,40,16,0,0,0,68,68,84,108,68,0, 
    0,0,68,40,16,40,68,0,0,0,68,68,60,4,120,0, 
    0,0,124,8,16,32,124,0,8,16,16,32,16,16,8,0, 
    16,16,16,0,16,16,16,0,32,16,16,8,16,16,32,0, 
    80,40,0,0,0,0,0,0,0,16,40,68,130,130,254,0, 
    254,254,254,254,254,254,254,0,0,0,0,0,0,254,254,0, 
    0,0,124,124,124,124,124,0,0,0,0,0,0,0,124,0, 
    128,128,128,128,128,128,128,0,0,64,64,64,64,64,64,0, 
    16,24,28,30,28,24,16,0,16,48,112,240,112,48,16,0, 
    62,30,30,62,114,224,64,0,4,14,156,248,240,240,248,0, 
    64,224,114,62,30,30,62,0,248,240,240,248,156,14,4,0, 
    56,68,130,130,130,68,56,0,56,124,254,254,254,124,56,0, 
    0,124,68,68,68,124,0,0,0,124,124,124,124,124,0,0, 
    0,60,110,126,112,126,60,0,0,60,118,126,14,126,60,0, 
    0,60,126,106,126,126,106,0,0,60,126,86,126,126,86,0, 
    0,0,0,24,24,0,0,0,0,0,24,60,60,24,0,0, 
    0,12,52,36,36,108,72,0,0,0,0,0,0,0,0,0, 
    60,126,198,231,255,224,126,60,60,126,227,231,255,7,126,60, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,52,118,118,94,126,60,0,0,60,110,126,112,126,60,0, 
    0,60,126,122,110,110,44,0,0,60,126,14,126,118,60,0, 
    0,0,0,0,0,0,0,0,126,126,126,126,60,0,0,0, 
    0,15,31,31,31,31,15,0,126,127,127,127,127,127,63,0, 
    0,0,0,60,126,126,126,126,126,126,126,126,126,126,126,126, 
    0,63,127,127,127,127,127,126,126,127,127,127,127,127,127,126, 
    0,240,248,248,248,248,240,0,126,254,254,254,254,254,252,0, 
    0,255,255,255,255,255,255,0,126,255,255,255,255,255,255,0, 
    0,252,254,254,254,254,254,126,126,254,254,254,254,254,254,126, 
    0,255,255,255,255,255,255,126,126,255,255,255,255,255,255,126, 
    0,0,63,63,48,55,52,52,0,0,255,255,0,255,0,0, 
    0,0,248,248,24,216,88,88,88,88,88,88,88,88,88,88, 
    88,216,24,248,248,0,0,0,0,255,0,255,255,0,0,0, 
    52,55,48,63,63,0,0,0,52,52,52,52,52,52,52,52, 
    0,0,0,31,24,24,24,24,0,0,0,255,0,0,0,0, 
    0,0,0,240,48,48,48,48,48,48,48,48,48,48,48,48, 
    48,48,48,240,0,0,0,0,0,0,0,255,0,0,0,0, 
    24,24,24,31,0,0,0,0,24,24,24,24,24,24,24,24, 
    136,34,136,34,136,34,136,34,85,170,85,170,85,170,85,170, 
    68,170,68,170,68,170,68,170,51,102,204,153,51,102,204,153, 
    204,102,51,153,204,102,51,153,199,143,31,62,124,248,241,227, 
    227,241,248,124,62,31,143,199,174,128,186,2,234,8,171,32, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 
 
/* Scrive una stringa di testo nella modalità video 
 * stampa carattere 8x8 ma in doppia altezza (8x16) 
 */ 
 
void outtextxy (char *c, int xt, int yt, int color) 
{ int count=0; 
  int riga, colonna, byte, peso;  
  char ct;  
 
   while ((c[count]!='\0') && (count < 256))  
   { ct=c[count]; 
     for (riga=0; riga<8; riga++) 
     { byte=font1[ct*8+riga]; peso=128;  
       for(colonna=0; colonna<8; colonna++) 
       { if ((byte/peso)==1)  
         { putpixel(xt+colonna,yt+riga*2,color);   // carattere doppia altezza 
           putpixel(xt+colonna,yt+1+riga*2,color);   
          } 
 
         byte = byte % peso; 
         peso = peso / 2; 
       } 
     } 
   xt=xt+8; 
   count ++ ; 
   } 
} 
 
void screenshot (void)  // cattura schermata e stampa su file (volutamente sottosopra = da flippare in verticale) 
{ int x,y,c; 
  int r,g,b; 
  FILE *fpo; 
  unsigned char a[64]={66,77,54,0,36,0,0,0,0,0,54,0,0,0,40,0, 
                       0,0,0,4,0,0,0,3,0,0,1,0,24,0,0,0, 
                       0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0, 
                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // primi 54 Bytes del file bmp 
   
  fpo=fopen("./screenshot.bmp","wb");  // FILE DESTINAZIONE BMP 1024x768 colori 24 bit  
  if (fpo==NULL) { printf("ERRORE OPEN FILE OUTPUT \n"); exit(0); } 
 
  for (x=0; x<54; x++)     // Intestazione, scrittura dei primi 54 byte del file  
  { putc(a[x],fpo); } 
 
  for (y=0; y<768; y++)    // Scrittura della matrice di pixel 1024x768x3 Bytes 
    for(x=0; x<1024; x++) 
    { c=getpixel(x,y); 
      putpixel(x,y,c+1); // progress scan 
      // conversione da 256 colori 24 bit (3 byte per colore = RGB) 
      // nel sistema a 256 colori, la palette dei primi 16 è la stessa dei 16 colori 
      r=0;g=0;b=0;                      // noir  
      if (c==1)  {r=0;g=0;b=128; };     // dark blu  
      if (c==2)  {r=0;g=128;b=0; };     // green  
      if (c==3)  {r=0;g=128;b=128; };   // azzurro  
      if (c==4)  {r=128;g=0;b=0; };     // dark red   
      if (c==5)  {r=128;g=0;b=128; };   // dark violet   
      if (c==6)  {r=128;g=128;b=0; };   // dark yellow  
      if (c==7)  {r=128;g=128;b=128; }; // light gris  
      if (c==8)  {r=64;g=64;b=64; };    // dark gris  
      if (c==9)  {r=0;g=0;b=255; };     // blu  
      if (c==10) {r=0;g=255;b=0; };     // light green  
      if (c==11) {r=0;g=255;b=255; };   // azzurro  
      if (c==12) {r=255;g=0;b=0; };     // rosso 
      if (c==13) {r=255;g=0;b=255; };   // viola  
      if (c==14) {r=255;g=255;b=0; };   // yellow  
      if (c==15) {r=255;g=255;b=255; }; // white  
     
      putc(b,fpo);  // blu 
      putc(g,fpo);  // green 
      putc(r,fpo);  // red 
    } 
  fclose(fpo); 
} 
 
void axes (void) 
{ int x,y; 
  for(x=0;x<1024;x++) putpixel(x,384,15);  
  for(y=0;y<768;y++)  putpixel(512,y,15); 
} 
 
void disegna (float z, float x, float y, int col) 
{ float xd,yd,yp,fi; 
 
  fi=0.5; 
  xd=-z*sin(Pi/4.0)+x*cos(Pi/4.0); 
  yp=-x*sin(fi)+y*cos(fi); 
  yd=-z*sin(fi)+yp*cos(fi); 
 
  putpixel(xo+(int)(xd), yo-(int)(yd),col); 
 
} 
 
void funzione (void) 
{ float x,y,z; 
 
/* disgna assi cartesiani */ 
  for (x=-400.0; x<400.0; x+=0.1) 
  { disegna(x,0.0,0.0,14); } 
  for (y=-400.0; y<400.0; y+=0.1) 
  { disegna(0.0,y,0.0,13); } 
  for (z=-400.0; z<400.0; z+=0.1) 
  { disegna(0.0,0.0,z,14); } 
 
 
/* disgna funzione */ 
  for (x=-2.0; x<2.0; x=x+0.2) 
   for (y=-2.0; y<2.0; y=y+0.01) 
   { z=cos(x*x+y*y); 
     disegna(100*x,100*y,100*z,9); 
   } 
  for (y=-2.0; y<2.0; y=y+0.2) 
   for (x=-2.0; x<2.0; x=x+0.01) 
   { z=cos(x*x+y*y); 
     disegna(100*x,100*y,100*z,9); 
   } 
} 
 
int main() 
 
{ vga_setmode(G1024x768x256);  // set VGA - some low resolution dont work  
  vga_setcolor(1);             // color of pixel  
 
  funzione(); 
   
  outtextxy("Press a key for ScreenShot",10,10,15);  // scrive su schermo grafico 
  getc(stdin);                                       // attende carattere da tastiera  
   
  screenshot(); 
 
  outtextxy("Press a key for EXIT",10,50,15);   // scrive su schermo grafico 
  getc(stdin);                                  // attende carattere da tastiera  
 
  vga_setmode(TEXT);           // restore textmode  
  
  return 0; 
}

- - - Updated - - -

il programma (in teoria) dovrebbe anche salvare uno screenshot su file bitmap del video.
tipo questo :

screenshot.jpg

(il file originale generato del programma appare capovolto, e sarebbe da invertire verticalmente con qualsiasi editor.. oppure si può modificare il programma per scansionare i pixel dal basso verso l'alto...)

- - - Updated - - -

per ora il pacchetto svgalib sembra funzionare bene su mint 17.1 - 17.3 32 bit ma non sulle versioni amd64 :cry:
probabilmente bisogna aggiustare qualche file di configurazione ...
comunque nelle prossime settimane spero di riuscire a compilare il make install
anche su altre distro e/o versioni a 64 bit.

:ciaociao:
 
Ultima modifica:

Zhong

Nuovo Utente
88
25
CPU
i8
Scheda Madre
supermicro
HDD
nas array
RAM
dual ecc
GPU
rage
Audio
beep
Monitor
lcd
PSU
rack supply
Case
hot rack
OS
red hatt
terzo capitolo ...

Sembrerebbe che esistono anche altri programmatori che utilizzano la grafica SVGA..
e uno di questi dovrebbe essere un Radioamatore che ha scritto il programma Linrad
Linrad home page. Download Linrad or update Linrad here.
In pratica dovrebbe essere un software di gestione degli RTX, che qui non ci interessano.
però possiamo sfruttare l'esperienza fatta sull' utilizzo delle librerie in ambiente linux.
Secondo quanto scritto in questa pagina :
Linrad support: Install svgalib
"The svgalib installation may fail on modern Linux distributions because they do not always include a working C complier"
e probabilmente la compilazione potrebbe risultare difficile con alcune nuove distribuzioni di linux.
Dunque non ci resta che provare... freeBSD... Knoppix... e tanti altri..
oppure possiamo anche abbandonare le SVGA e passare alle librerie X11
A Brief intro to X11 Programming

- - - Updated - - -

Per ora la grafica SVGA funziona abbastanza bene e sembra abbastanza efficente.
Ecco un altro programmino... in C che disegna la funzione sombrero :
Codice:
/* 
 * SVGALib C-Linux Disegna una funzione 3d  
 * 
 *  erikkssen X  
 *  
 */ 
 
# include <stdio.h> 
# include <stdlib.h>    // exit  
# include <math.h> 
# include <vga.h> 
 
# define Pi 3.1415926  // Pi-greco 
 
int xo=512, yo=384;    // centro schermo  
 
 
char getpixel (int x, int y) 
{ return vga_getpixel(x,y); } // read a pixel 
 
void putpixel (int x,int y, int c) 
{ vga_setcolor(c);    // set color   
  vga_drawpixel(x,y); // draw pixel  
} 
 
/*  Font di 256 caratteri SVGA 8x8. 
 *  Ogni carattere è rappresentato da 8 unsigned char 
 *  per un totale di 2048 numeri.  
 *  Ogni intero rappresenta una riga di 8 pixel del carattere visualizzato 
 */ 
 
unsigned char font1[2048] = 
{   124,130,186,162,186,130,124,0,126,129,165,129,165,153,129,126, 
    126,129,165,129,153,165,129,126,108,246,246,254,124,56,16,0, 
    16,56,124,254,124,56,16,0,16,56,84,254,84,16,56,0, 
    56,124,254,254,108,16,56,0,16,24,20,20,48,112,96,0, 
    254,254,254,238,254,254,254,0,236,138,138,170,170,170,236,0, 
    142,136,136,140,136,136,232,0,174,170,170,234,170,170,174,0, 
    238,136,136,204,136,136,136,0,238,138,138,142,140,138,234,0, 
    62,34,62,34,102,238,204,0,16,84,40,198,40,84,16,0, 
    240,248,252,254,252,248,240,0,30,62,126,254,126,62,30,0, 
    16,56,124,16,124,56,16,0,238,238,238,238,238,0,238,0, 
    254,68,68,68,68,68,68,0,126,128,188,198,122,2,252,0, 
    0,0,0,0,255,255,0,0,16,56,124,16,124,56,16,254, 
    16,56,124,254,56,56,56,0,56,56,56,254,124,56,16,0, 
    16,24,252,254,252,24,16,0,16,48,126,254,126,48,16,0, 
    144,72,36,18,36,72,144,0,18,36,72,144,72,36,18,0, 
    16,40,68,146,40,68,130,0,130,68,40,146,68,40,16,0, 
    0,0,0,0,0,0,0,0,16,16,16,16,16,0,16,0, 
    40,40,40,0,0,0,0,0,68,254,68,68,68,254,68,0, 
    16,126,144,124,18,252,16,0,66,164,72,16,36,74,132,0, 
    56,68,56,112,138,132,122,0,16,16,32,0,0,0,0,0, 
    8,16,16,16,16,16,8,0,32,16,16,16,16,16,32,0, 
    16,84,56,254,56,84,16,0,16,16,16,254,16,16,16,0, 
    0,0,0,0,0,16,16,32,0,0,0,254,0,0,0,0, 
    0,0,0,0,0,0,16,0,2,4,8,16,32,64,128,0, 
    124,130,130,130,130,130,124,0,240,16,16,16,16,16,254,0, 
    252,2,2,124,128,128,254,0,252,2,2,28,2,2,252,0, 
    130,130,130,126,2,2,2,0,254,128,252,2,2,2,252,0, 
    126,128,252,130,130,130,124,0,252,2,2,2,2,2,2,0, 
    124,130,130,124,130,130,124,0,126,130,130,126,2,2,252,0, 
    0,0,0,16,0,0,16,0,0,0,0,16,0,0,16,32, 
    8,16,32,64,32,16,8,0,0,0,0,254,0,254,0,0, 
    64,32,16,8,16,32,64,0,56,68,4,8,16,0,16,0, 
    60,66,154,170,156,64,62,0,124,130,130,254,130,130,130,0, 
    252,130,130,252,130,130,252,0,124,130,128,128,128,130,124,0, 
    252,130,130,130,130,130,252,0,254,128,128,240,128,128,254,0, 
    254,128,128,240,128,128,128,0,124,130,128,142,130,130,124,0, 
    130,130,130,254,130,130,130,0,254,16,16,16,16,16,254,0, 
    62,2,2,2,130,130,124,0,130,132,136,240,136,132,130,0, 
    128,128,128,128,128,128,254,0,252,146,146,146,146,146,146,0, 
    130,194,162,146,138,134,130,0,124,130,130,130,130,130,124,0, 
    252,130,130,252,128,128,128,0,124,130,130,130,138,134,126,0, 
    252,130,130,252,130,130,130,0,126,128,128,124,2,2,252,0, 
    254,16,16,16,16,16,16,0,130,130,130,130,130,130,124,0, 
    130,130,68,68,40,40,16,0,130,130,130,146,146,146,108,0, 
    130,68,40,16,40,68,130,0,130,130,130,126,2,2,252,0, 
    254,4,8,16,32,64,254,0,56,32,32,32,32,32,56,0, 
    128,64,32,16,8,4,2,0,56,8,8,8,8,8,56,0, 
    16,40,68,130,0,0,0,0,0,0,0,0,0,0,0,255, 
    32,32,16,0,0,0,0,0,0,0,56,68,124,68,68,0, 
    0,0,120,68,120,68,120,0,0,0,60,64,64,64,60,0, 
    0,0,120,68,68,68,120,0,0,0,124,64,112,64,124,0, 
    0,0,124,64,112,64,64,0,0,0,60,64,76,68,60,0, 
    0,0,68,68,124,68,68,0,0,0,124,16,16,16,124,0, 
    0,0,28,4,4,68,56,0,0,0,68,72,112,72,68,0, 
    0,0,64,64,64,64,124,0,0,0,120,84,84,84,84,0, 
    0,0,120,68,68,68,68,0,0,0,56,68,68,68,56,0, 
    0,0,120,68,120,64,64,0,0,0,56,68,68,76,54,0, 
    0,0,120,68,120,68,68,0,0,0,60,64,56,4,120,0, 
    0,0,124,16,16,16,16,0,0,0,68,68,68,68,56,0, 
    0,0,68,68,40,40,16,0,0,0,68,68,84,108,68,0, 
    0,0,68,40,16,40,68,0,0,0,68,68,60,4,120,0, 
    0,0,124,8,16,32,124,0,8,16,16,32,16,16,8,0, 
    16,16,16,0,16,16,16,0,32,16,16,8,16,16,32,0, 
    80,40,0,0,0,0,0,0,0,16,40,68,130,130,254,0, 
    254,254,254,254,254,254,254,0,0,0,0,0,0,254,254,0, 
    0,0,124,124,124,124,124,0,0,0,0,0,0,0,124,0, 
    128,128,128,128,128,128,128,0,0,64,64,64,64,64,64,0, 
    16,24,28,30,28,24,16,0,16,48,112,240,112,48,16,0, 
    62,30,30,62,114,224,64,0,4,14,156,248,240,240,248,0, 
    64,224,114,62,30,30,62,0,248,240,240,248,156,14,4,0, 
    56,68,130,130,130,68,56,0,56,124,254,254,254,124,56,0, 
    0,124,68,68,68,124,0,0,0,124,124,124,124,124,0,0, 
    0,60,110,126,112,126,60,0,0,60,118,126,14,126,60,0, 
    0,60,126,106,126,126,106,0,0,60,126,86,126,126,86,0, 
    0,0,0,24,24,0,0,0,0,0,24,60,60,24,0,0, 
    0,12,52,36,36,108,72,0,0,0,0,0,0,0,0,0, 
    60,126,198,231,255,224,126,60,60,126,227,231,255,7,126,60, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,52,118,118,94,126,60,0,0,60,110,126,112,126,60,0, 
    0,60,126,122,110,110,44,0,0,60,126,14,126,118,60,0, 
    0,0,0,0,0,0,0,0,126,126,126,126,60,0,0,0, 
    0,15,31,31,31,31,15,0,126,127,127,127,127,127,63,0, 
    0,0,0,60,126,126,126,126,126,126,126,126,126,126,126,126, 
    0,63,127,127,127,127,127,126,126,127,127,127,127,127,127,126, 
    0,240,248,248,248,248,240,0,126,254,254,254,254,254,252,0, 
    0,255,255,255,255,255,255,0,126,255,255,255,255,255,255,0, 
    0,252,254,254,254,254,254,126,126,254,254,254,254,254,254,126, 
    0,255,255,255,255,255,255,126,126,255,255,255,255,255,255,126, 
    0,0,63,63,48,55,52,52,0,0,255,255,0,255,0,0, 
    0,0,248,248,24,216,88,88,88,88,88,88,88,88,88,88, 
    88,216,24,248,248,0,0,0,0,255,0,255,255,0,0,0, 
    52,55,48,63,63,0,0,0,52,52,52,52,52,52,52,52, 
    0,0,0,31,24,24,24,24,0,0,0,255,0,0,0,0, 
    0,0,0,240,48,48,48,48,48,48,48,48,48,48,48,48, 
    48,48,48,240,0,0,0,0,0,0,0,255,0,0,0,0, 
    24,24,24,31,0,0,0,0,24,24,24,24,24,24,24,24, 
    136,34,136,34,136,34,136,34,85,170,85,170,85,170,85,170, 
    68,170,68,170,68,170,68,170,51,102,204,153,51,102,204,153, 
    204,102,51,153,204,102,51,153,199,143,31,62,124,248,241,227, 
    227,241,248,124,62,31,143,199,174,128,186,2,234,8,171,32, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 
 
/* Scrive una stringa di testo nella modalità video 
 * stampa carattere 8x8 ma in doppia altezza (8x16) 
 */ 
 
void outtextxy (char *c, int xt, int yt, int color) 
{ int count=0; 
  int riga, colonna, byte, peso;  
  char ct;  
 
   while ((c[count]!='\0') && (count < 256))  
   { ct=c[count]; 
     for (riga=0; riga<8; riga++) 
     { byte=font1[ct*8+riga]; peso=128;  
       for(colonna=0; colonna<8; colonna++) 
       { if ((byte/peso)==1)  
         { putpixel(xt+colonna,yt+riga*2,color);   // carattere doppia altezza 
           putpixel(xt+colonna,yt+1+riga*2,color);   
          } 
 
         byte = byte % peso; 
         peso = peso / 2; 
       } 
     } 
   xt=xt+8; 
   count ++ ; 
   } 
} 
 
void screenshot (void)  // cattura schermata e stampa su file (volutamente sottosopra = da flippare in verticale) 
{ int x,y,c; 
  int r,g,b; 
  FILE *fpo; 
  unsigned char a[64]={66,77,54,0,36,0,0,0,0,0,54,0,0,0,40,0, 
                       0,0,0,4,0,0,0,3,0,0,1,0,24,0,0,0, 
                       0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0, 
                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // primi 54 Bytes del file bmp 
   
  fpo=fopen("./screenshot.bmp","wb");  // FILE DESTINAZIONE BMP 1024x768 colori 24 bit  
  if (fpo==NULL) { printf("ERRORE OPEN FILE OUTPUT \n"); exit(0); } 
 
  for (x=0; x<54; x++)     // Intestazione, scrittura dei primi 54 byte del file  
  { putc(a[x],fpo); } 
 
  for (y=0; y<768; y++)    // Scrittura della matrice di pixel 1024x768x3 Bytes 
    for(x=0; x<1024; x++) 
    { c=getpixel(x,y); 
      putpixel(x,y,c+1); // progress scan 
      // conversione da 256 colori 24 bit (3 byte per colore = RGB) 
      // nel sistema a 256 colori, la palette dei primi 16 è la stessa dei 16 colori 
      r=0;g=0;b=0;                      // noir  
      if (c==1)  {r=0;g=0;b=128; };     // dark blu  
      if (c==2)  {r=0;g=128;b=0; };     // green  
      if (c==3)  {r=0;g=128;b=128; };   // azzurro  
      if (c==4)  {r=128;g=0;b=0; };     // dark red   
      if (c==5)  {r=128;g=0;b=128; };   // dark violet   
      if (c==6)  {r=128;g=128;b=0; };   // dark yellow  
      if (c==7)  {r=128;g=128;b=128; }; // light gris  
      if (c==8)  {r=64;g=64;b=64; };    // dark gris  
      if (c==9)  {r=0;g=0;b=255; };     // blu  
      if (c==10) {r=0;g=255;b=0; };     // light green  
      if (c==11) {r=0;g=255;b=255; };   // azzurro  
      if (c==12) {r=255;g=0;b=0; };     // rosso 
      if (c==13) {r=255;g=0;b=255; };   // viola  
      if (c==14) {r=255;g=255;b=0; };   // yellow  
      if (c==15) {r=255;g=255;b=255; }; // white  
     
      putc(b,fpo);  // blu 
      putc(g,fpo);  // green 
      putc(r,fpo);  // red 
    } 
  fclose(fpo); 
} 
 
void bkcolor (int color) 
{ int x,y; 
  for(y=0;y<768;y++) for(x=0;x<1024;x++) putpixel(x,y,color); 
} 
 
 
void axes (void) 
{ int x,y; 
  for(x=0;x<1024;x++) putpixel(x,384,15);  
  for(y=0;y<768;y++)  putpixel(512,y,15); 
} 
 
void disegna (float z, float x, float y, int col) 
{ float xd,yd,yp,fi; 
 
  fi=0.2; 
  xd=-z*sin(Pi/4.0)+x*cos(Pi/4.0); 
  yp=-x*sin(fi)+y*cos(fi); 
  yd=-z*sin(fi)+yp*cos(fi); 
 
  putpixel(xo+(int)(xd), yo-(int)(yd),col); 
 
} 
 
void funzione (void) 
{ float x,y,z; 
 
/* disgna assi cartesiani 3d */ 
  for (x=-400.0; x<400.0; x+=0.1) 
  { disegna(x,0.0,0.0,14); } 
  for (y=-400.0; y<400.0; y+=0.1) 
  { disegna(0.0,y,0.0,13); } 
  for (z=-400.0; z<400.0; z+=0.1) 
  { disegna(0.0,0.0,z,14); } 
 
/* disgna funzione 3d */ 
  for (x=-8.0; x<8.1; x=x+0.2) 
   for (y=-8.0; y<8.0; y=y+0.01) 
   {  
     if(fabs(sqrt(x*x+y*y))>0.01)  
     { z=sin(sqrt(x*x+y*y))/sqrt(x*x+y*y); 
       disegna(30*x,30*y,300*z,1); 
     } 
   } 
  for (y=-8.0; y<8.1; y=y+0.2) 
   for (x=-8.0; x<8.0; x=x+0.01) 
   {  
     if(fabs(sqrt(x*x+y*y))>0.01)  
     { z=sin(sqrt(x*x+y*y))/sqrt(x*x+y*y); 
       disegna(30*x,30*y,300*z,1); 
     }    
   } 
} 
 
int main() 
 
{ vga_setmode(G1024x768x256);  // set VGA - some low resolution dont work  
  vga_setcolor(1);             // color of pixel  
 
  bkcolor(15);                 // set colore sfondo 
 
  funzione(); 
   
  outtextxy("Press a key for ScreenShot",10,10,1);   // scrive su schermo grafico 
  getc(stdin);                                       // attende carattere da tastiera  
   
  screenshot(); 
 
  outtextxy("Press a key for EXIT",10,50,1);    // scrive su schermo grafico 
  getc(stdin);                                  // attende carattere da tastiera  
 
  vga_setmode(TEXT);           // restore textmode  
  
  return 0; 
}

il grafico dovebbe essere questo :
Visualizza allegato 201948
poi per paragone istalliamo il programma OCTAVE utilizzando il software manager, oppure scrivendo direttamente :
$ sudo apt-get install octave
e scriviamo anche la funzione sombrero per octave :
Codice:
% Progrmma sombrero per octave  
% salvare il file di testo come sombrero.m 
% avviare Octave e dal prompt lanciare con > run sombrero.m 
% octave supporta anche alcuni comandi come ls e cd 
 
ticks = [-10.0:0.3:10.0]; 
[x, y] = meshgrid(ticks, ticks); 
z = sin (sqrt (x.^2 + y.^2)) ./ (sqrt (x.^2 + y.^2)); 
surf(x,y,z); 
title('sombrero using meshgrid'); 
print('sombrero_meshgrid.jpg');

- - - Updated - - -

con il copia-incolla creiamo il file di testo sombrero.m per il programma matematico.
lanciamo Octave dal menu start o direttamente dal terminal e poi al prompt scriviamo :
> run sombrero.m
e se tutto funziona bene si dovrebbe visualizzare questo grafico :
Visualizza allegato 201950
beh insomma Octave è un programma scientifico, che somiglia molto al mitico Matlab.
dunque non pretendiamo la stessa qualità, ma siamo già abbastanza soddisfatti del risultato.

- - - Updated - - -

In teoria, anche se non fosse possibile utilizzare direttamente la grafica in real time,
si potrebbe sempre scrivere il programma che genera il file Bitmap da visualizzare a posteriori.
(utilizzando un array abbastanza grande si potrebbero ottenere risoluzioni "impossibili" per il nostro monitor)
Oppure utilizzando le versioni di linux 64 bit si potrebbe creare una matrice 3d di voxel da utilizzare per visualizzare
le slice di una TAC o una MRI come nel programma 3d slicer https://www.slicer.org/

Per ora è tutto...
alle prossime.. :ciaociao:
 
Ultima modifica:

Zhong

Nuovo Utente
88
25
CPU
i8
Scheda Madre
supermicro
HDD
nas array
RAM
dual ecc
GPU
rage
Audio
beep
Monitor
lcd
PSU
rack supply
Case
hot rack
OS
red hatt
capitolo IV

Proviamo anche le librerie di X11 Window... che magicamente sono già installate nel DVD di Mint 17.3 mate 64 bit.
quindi è possibile provare il programma senza installare nulla e senza la connessione di internett.

Siccome le X11 interagiscono con il sistema operativo allora diventa tutto molto più difficile.
Abbiamo bisogno di inizializzare le windows, le variabili di ambiente e come risultato otteniamo un programmone davvero complesso ed incomprensibile.
dall' altro lato però abbiamo disponibili molte funzioni che ci evitano di scrivere le routine grafiche di basso livello.

ecco il programma che disegna la funzione sombrero in X11
Codice:
/* 
 * Programma grafico per LINUX X11 Window.
 * Il pack X11 è gia compreso nell'istallazione del DVD di Mint 17.3 64bit
 * Compilare come superuser 
 *   
 * gcc sombrero.c -lX11 -lm
 * 
 * eseguire con 
 * 
 * ./a.out
 *
 */

# include <stdio.h> 
# include <stdlib.h>    // exit  
# include <math.h> 
// libreria X11 Window
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# include <X11/Xos.h>

# define Pi 3.1415926  // Pi-greco 
 
int xo=512, yo=384;    // centro schermo di 1024x768

// variabili globali per X11 Window

Display *dis;
int scr;
Window win;
GC gc;
XEvent e;   // keypressed


void disegna (float z, float x, float y) 
{ float xd,yd,yp,fi; 
 
  fi=0.2; 
  xd=-z*sin(Pi/4.0)+x*cos(Pi/4.0); 
  yp=-x*sin(fi)+y*cos(fi); 
  yd=-z*sin(fi)+yp*cos(fi); 
 
  XDrawPoint(dis, win, DefaultGC(dis, scr), xo+(int)(xd), yo-(int)(yd));   // disegna il pixel in X11 window
} 
 
void funzione (void) 
{ float x,y,z; 
 
/* disgna assi cartesiani 3d */ 
  for (x=-400.0; x<400.0; x+=0.1) 
  { disegna(x,0.0,0.0); } 
  for (y=-400.0; y<400.0; y+=0.1) 
  { disegna(0.0,y,0.0); } 
  for (z=-400.0; z<400.0; z+=0.1) 
  { disegna(0.0,0.0,z); } 
 
/* disgna funzione 3d */ 
  for (x=-8.0; x<8.1; x=x+0.2) 
   for (y=-8.0; y<8.0; y=y+0.01) 
   {  
     if(fabs(sqrt(x*x+y*y))>0.01)  
     { z=sin(sqrt(x*x+y*y))/sqrt(x*x+y*y); 
       disegna(30*x,30*y,300*z); 
     } 
   } 
  for (y=-8.0; y<8.1; y=y+0.2) 
   for (x=-8.0; x<8.0; x=x+0.01) 
   {  
     if(fabs(sqrt(x*x+y*y))>0.01)  
     { z=sin(sqrt(x*x+y*y))/sqrt(x*x+y*y); 
       disegna(30*x,30*y,300*z); 
     }    
   } 
} 

int main(int argc, char** argv) 
{  
  printf("Programma avviato. \n"); 

  dis = XOpenDisplay(NULL);  if (dis == NULL) { printf("Errore apertura display \n"); exit(1); }
  scr = DefaultScreen(dis);
  win = XCreateSimpleWindow(dis, RootWindow(dis, scr), 1, 1, 1000, 700, 5, BlackPixel(dis, scr), WhitePixel(dis, scr));
  XSelectInput(dis, win, ExposureMask | KeyPressMask);
  XMapWindow(dis, win);
  XStoreName(dis, win, "Disegno in X11 Windows");

  const char* s1 = "Funzione Sombrero : Press a Key for Exit";

  while (1) 
  { XNextEvent(dis, &e);
    if (e.type == KeyPress) break;          // press a key for exit
    XDrawString(dis,win,DefaultGC(dis, scr),20,20,s1,strlen(s1));  
    
    funzione();
   }
 
  XDestroyWindow(dis, win);
  XCloseDisplay(dis);

  printf("Programma Terminato. \n");

  return(0);
}

- - - Updated - - -

Se non ci sono errori l'output dovrebbe essere il grafico :

Sombrero.jpg

ciaoooooo :ciaociao:
 

Entra

oppure Accedi utilizzando

Hot: E3 2021, chi ti è piaciuto di più?

  • Ubisoft

    Voti: 4 16.7%
  • Gearbox

    Voti: 0 0.0%
  • Xbox & Bethesda

    Voti: 20 83.3%
  • Square Enix

    Voti: 0 0.0%
  • Capcom

    Voti: 0 0.0%
  • Nintendo

    Voti: 3 12.5%
  • Altro (Specificare)

    Voti: 0 0.0%

Discussioni Simili