Polygon clipping is one of the classic problem in computer graphics lab. Generally, polygons or whatever objects, are clipped by a rectangular clipping windows. But, this one is a little more challenging graphics lab experiment in which we have to clip polygon with another polygon. That is the clipping windows is actually another polygon. The following c program implements polygon clipping with another polygon. The program clips any polygon with the clipping polygon, given both should be convex polygons.
Search This Blog
Showing posts with label experiment. Show all posts
Showing posts with label experiment. Show all posts
Rotation of Wheel - C Program for Computer Graphics Lab
In computer graphics experiments, we need to rotate objects like wheels while doing animation. This is a simple c program that shows rotation of a wheel. A circle is drawn and four radial lines are drawn at 90 degree separation. These lines are drawn from center to a point on circle which depends on the value of theta, a variable. As the value of theta changes, the end points of the radial lines changes. Therefore, increasing the value of theta in a loop give counter clockwise rotaion and decreasing gives clockwise rotation.
The program is as follows:
The program is as follows:
C Program to Draw Fern Leaf using Fractals - Computer Graphics Experiment
Fern is a plant with leaves that follow a pattern. A whole fern plant can be drawn using simply lines. Drawing fern is a simple example for fractals in computer graphics. The following program draws a fern plant using the idea of fractals. This is a computer graphics lab experiment.
Rotation and Revolution of Two Wheels following a 'D' Shaped Path - Computer Graphics Experiment
This is a computer graphics lab experiment. The question was to animate both rotation and revolution of two wheels in opposite direction. Both the wheels move in a path in a of shape 'D'. If one moves in clockwise direction, the other moves in counter clockwise direction. The output of the program is as follows:
The program is as follows:
The program is as follows:
Blooming Flower and Bee Animation C Program - Computer Graphics Lab Experiment
One of my graphics lab questions was to write a c program to animate a blooming flower and a bee (or a beetle) that comes to the flower, sit on it and fly away. The program uses graphics.h header file.
Output:
Program
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int i,xmax,ymax;
int startx,starty;
int stopped=0;
void drawFlower(int i)
{
setcolor(GREEN);
line(xmax/2,ymax/2,xmax/2,ymax/2+100);
setcolor(BROWN);
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(xmax/2,ymax/2,10+1.8*i,5+.6*i);
fillellipse(xmax/2,ymax/2,5+.6*i,10+1.8*i);
setcolor(BROWN);
setfillstyle(SOLID_FILL,RED);
fillellipse(xmax/2,ymax/2,5+.6*i,5+.6*i);
}
void drawBee(int i)
{
startx+=2;
starty+=7*sin(i);
setcolor(BROWN);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(startx,starty,12,5);
setcolor(BLUE);
fillellipse(startx,starty,5,10*(i%2));
fillellipse(startx+8,starty-3,1,1);
fillellipse(startx+8,starty+3,1,1);
line(startx+9,starty-2,startx+11,starty-5);
line(startx+9,starty+2,startx+11,starty+5);
}
void main()
{
int max,may,i,t;
int gm=DETECT,gd;
initgraph(&gm,&gd," ");
xmax=getmaxx();
ymax=getmaxy();
startx=xmax/2-100;
starty=ymax/2;
setbkcolor(WHITE);
getch();
for(i=0;i<20;i++)
{
delay(120);
cleardevice();
drawFlower(i);
}
t=i;
for(i=0;startx+i<xmax-60;i++)
{
delay(90);
cleardevice();
drawFlower(t);
drawBee(i);
if(stopped==0&&abs(startx-xmax/2)<10&&abs(starty-ymax/2)<15)
{
delay(2500);
stopped=1;
}
}
getch();
}
Subscribe to:
Posts (Atom)