

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
More use full aaps thanks very mush
Typology: Cheat Sheet
1 / 2
This page cannot be seen from the preview
Don't miss anything!


8.scaling of triangle #include #include #define W 300 #define H 300 static int img[H][W][3] = {0}; void plot(int x, int y, int r, int g, int b){ if(x>=0 && x=0 && y abs(dy)? abs(dx) : abs(dy); float xinc = dx / (float)steps; float yinc = dy / (float)steps; float x = x1, y = y1; for(int i=0; i<=steps; i++){ plot((int)(x+0.5), (int)(y+0.5), 255,255,255); x += xinc; y += yinc; } } void saveImage(char fname){ FILE f = fopen(fname,"w"); fprintf(f,"P3\n%d %d\n255\n",W,H); for(int y=0;y int x1=50,y1=50, x2=150,y2=50, x3=100,y3=150; float sx, sy; / Original triangle / drawLine(x1,y1, x2,y2); drawLine(x2,y2, x3,y3); drawLine(x3,y3, x1,y1); printf("Enter scaling factors sx sy : "); scanf("%f %f",&sx,&sy); / Scaled triangle (about origin) / drawLine(x1sx, y1sy, x2sx, y2sy); drawLine(x2sx, y2sy, x3sx, y3sy); drawLine(x3sx, y3sy, x1sx, y1sy); saveImage("scale.ppm"); return 0; }