#include <stdio.h>

/∗

∗ To programma auto dhmiourgei ena kamba 200x100 ∗ kai sthn synexeia orizei thn synarthsh setpixel

∗ h opoia mesa ston kamba anabei to pixel me

∗ syntetagmenes x,y sthn RGB timh pou dinetai me ∗ treis parametrous. ∗

∗ To apotelesma eksagete san arxeio eikonas

∗ ppm to opoio mporeite na to anoiksete me

∗ opoiodhpote paketo grafikwn (px gimp) ∗

∗ gia na to treksete dwste

∗ gcc SetPixel.c

∗ gia na to metaglwtisete kai sthn

∗ synexeia

∗ ./a.out > test.ppm

∗ opote 8a grapsei to arxeio eikonas

∗ sto file test.ppm ∗ ∗ ∗/

int xres=200,yres=100; int i; unsigned char ∗pa; /∗ Prosekste ton orismo tou pa san deikth

∗ apo arrays pou apoteleitai apo short

∗ integers. ∗/

main() {

int size;

xres=200; yres=100; size=xres∗yres∗3;

unsigned char a[size]; pa=&a[0]; size=xres∗yres∗3;

/∗ ∗ Gemizoume ton pinaka me stoixeia 0 dhladh

∗ ton maurizw. ∗/

for (i=0; i < size; i++)

a[i]=0;

setpixel(1,0,255,234,234); /∗ Anabw to pixel 1,0 sthn RGB timh 255,234,234 ∗/ setpixel(10,5,255,255,255); /∗ Anabw to pixel 10,5 sthn RGB timh 255,255,255 (leuko) ∗/

/∗ write file

∗ Gia na katalabete pws paw na grapsw to arxeio grafikwn ∗ ppm mporeite na diabasete ta specifications tou ppm ∗ sthn selida

∗ http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/ppm.txt ∗ h apla na dwsete

∗ man ppm

∗ se ena kala ry8mismeno

∗ unix mhxanhma ∗/

printf("%s\n","P3"); printf("%d\t%d\n",xres,yres); printf("%d\n",15);

for (i=0; i < size; i++) {

printf("%d%s",a[i]," "); }

}

/∗

∗ Routina Set Pixel

∗ Prosekste oti gia na perasw ton pinaka sthn

∗ yporoutina kanw xrhsh pointer, kytakste thn

∗ selida 141 tou Kernighan -Ritchie. ∗/ int setpixel(int x, int y, int R, int G, int B) {

i=3∗xres∗y+3∗x; ∗(pa+i)=R; ∗(pa+i+1)=G; ∗(pa+i+2)=B;

}