CG Record
CG Record
no :1
IMPLEMENTATION OF LINE, CIRCLE AND ELLIPSE DRAWING
Date:30-07-2019
AIM:
To write a program to implement Midpoint algorithms for line, circle and ellipse drawing.
ALGORITHM:
1
PROGRAM:
Index.c
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#include "eli.h"
#include "cir.h"
#include "lin.h"
void main()
{
int choice=0;
char z;
clrscr();
z='Y';
while (z!='N'){
system("cls");
printf("\n1.ellipse\n2.circle\n3.Line\n4.exit\n\nEnter your Choice [1-4]? : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
eli();
break;
case 2:
cir();
break;
case 3: lin();
break;
case 4:
exit(0);
default:
printf("Enter valid option\n");
}
printf("\nDo you want to continue? (Y/N):");
2
while(getchar() != '\n') continue;
scanf("%c",&z);
if(isalpha(z))
z=toupper(z);
// else
// printf("\nYou should enter a character to continue\n");
}
system("pause");
getch();
Eli()
void eli()
{
float x,y,a,b,h,k,p1,p2,dx,dy;
int gd= DETECT,gm;
clrscr();
initgraph (&gd, &gm,"C:\\TURBOC3\\BGI");
printf("\n ENTER CENTER COORDINATES (h,k) OF ELLIPSE:\n");
scanf("%f%f",&h,&k) ;
printf("\n ENTER LENGTH OF MAJOR AXIS\n:");
scanf("%f",&a);
printf("\n ENTER LENGTH OF MINOR AXIS:\n");
scanf("%f",&b);
x=0;
y=b;
p1 =(b * b)+((a*a)/4)-(b*a*a);
dx=2*(b*b)*x;
dy=2*(a*a)*y;
while(dx<dy)
{
putpixel (x+h, y+k, RED);
3
putpixel (-x+h, -y+k, RED);
putpixel (x+h, -y+k, RED);
putpixel (-x+h, y+k, RED);
if (p1 < 0)
{
x=x+1;
dx=2*b*b*x;
p1=p1+dx+(b*b);
}
else
{
x=x+1;
y=y-1;
dx=2*b*b*x;
dy=2*a*a*y;
p1=p1+(dx-dy)+(b*b);
}
p2 =((b * b)* (x + 0.5)*(x + 0.5))+((a * a)*(y-1) * (y-1))-(a * a *b * b);
while (y>=0)
{
putpixel (x+h, y+k, RED);
putpixel (-x+h, -y+k, RED);
putpixel (x+h, -y+k, RED);
putpixel (-x+h, y+k, RED);
if (p2>0)
{
y=y-1;
dy=2*(a*a)*y;
p2=p2-dy+(a *a); }
else
{
x=x+1;
y=y-1;
dx=dx+2*(b*b);
dy=dy-2*(a*a);
p2=p2+(dx-dy)+(a*a)
}
} }
4
Cir()
void cir()
{
int r,x,y,gd=DETECT,gm,h,k;
float p;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
scanf("%d%d",&h,&k) ;
printf("Enter radius:\n ");
scanf("%d",&r);
x=0;
y=r;
p=1.25-r;
while(x<y)
{
putpixel(h+x,k+y,RED);
putpixel(h+x,k-y,WHITE);
putpixel(h-x,k+y,BLUE);
putpixel(h-x,k-y,GREEN);
putpixel(h+y,k+x,YELLOW);
putpixel(h+y,k-x,RED);
putpixel(h-y,k+x,WHITE);
putpixel(h-y,k-x,BLUE);
if (p<0)
{
x=x+1;
y=y;
p=p+2*x+3;
}
else
{
x=x+1;
y=y-1;
p=p+2*(x-y)+5;}}}
5
lin()
void lin(){
int gd=DETECT, gm,x1,x2,y1,y2,dx,dy,d,cre,crne,x,y;
clrscr();
initgraph(&gd, &gm,"C:\\TURBOC3\\BGI");
printf("Enter (x1,y1):\n");
scanf("%d%d",&x1,&y1);
printf("Enter (x2,y2):\n");
scanf("%d%d",&x2,&y2);
dx = x2 - x1;
dy = y2 - y1;
d = 2 * dy - dx;
cre = 2 * dy;
crne = 2 * (dy - dx);
x = x1;
y = y1;
putpixel(x, y, WHITE);
while(x < x2){
if(d<=0){
d += cre;
x++;
}
else{
d += crne;
x++;
y++;
}
putpixel(x,y,WHITE);
}
}
6
OUTPUT:-
7
Enter the Choice:3
RESULT:
Thus the program implementation of Midpoint algorithm for line, circle and ellipse drawing is done
successfully
8
Ex.no :2
IMPLEMENTATION OF POLYGON CLIPPING AND POLYGON
Date:13-08-2019 FILLING
AIM:
To create a program to implement polygon clipping and polygon filling Using flood fill algorithm.
ALGORITHM:
Step 3: Create a function to get the line co-ordinates and window co-ordinate values.
Step 4: Fill the polygon using flood fill algorithm,flood fill(x,y,new color,old color)
Step5: Check all the co-ordinates of the lines are within the window co-ordinate or not.
Step6: Clip the lines which are all outside of the window co-ordinates using Sutherland- Holygon polygon
clipping algortthm.
Step7: After the clipping draw all the lines along with the window.
9
PROGRAM:
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.*;
graphics2D.setBackground(Color.black);
graphics2D.clearRect(0,0,WIDTH,HEIGHT);
repaint();
revalidate();
10
}
Application(){
mFloodPoint = 0;
addMouseListener(this);
}@Override
super.paintComponent(g);
graphics2D.setBackground(Color.black);
g.drawImage(mImage,0,0,this);
}@Override
return true;
return false;
int i,j;
11
for (i = 0, j = mVertices.size()- 1; i < mVertices.size(); j = i++) {
(mVertices.get(j).Y-mVertices.get(i).Y) + mVertices.get(i).X))
result = !result;
return result;
graphics2D.setColor(BLUE);
graphics2D.drawLine(current.X,current.Y,next.X, next.Y);
graphics2D.drawLine(first.X,first.Y,last.X,last.Y);
12
repaint();
revalidate();
} @Override
if(e.getButton() == MouseEvent.BUTTON1) {
mVertices.add(new Point(e.getX(),e.getY()));
if(mFloodPoint==0) {
System.out.println("Drawing polygon");
drawPolygon();
mFloodPoint = 1;
else if(mFloodPoint==1){
System.out.println("Filling polygon");
floodFill(e.getX(),e.getY(),Color.green);
mFloodPoint = 2;
else if(mFloodPoint==2){
13
int h = in.nextInt();
int w = in.nextInt();
in.close();
System.out.println("Clipping polygon");
clip(w, h);
mFloodPoint = 2;
clearImage();
callStack.add(new Point(x,y));
while(!callStack.isEmpty()) {
if(isInside(point.X, point.Y)) {
14
repaint();
revalidate();
repaint();
mImage.setRGB(i, j, Color.black.getRGB());
repaint();
}@Override
@Override
15
@Override
class Point{
int X, Y;
this.X = X;
this.Y = Y;
jFrame.setSize(720, 480);
jFrame.setBackground(Color.BLUE);
jFrame.add(app);
jFrame.setVisible(true);
16
OUTPUT:-
17
RESULT:
Thus the program implementation of Sutherland Hodgeman algorithm for polygon fill and clip the polygon is
done successfully.
18
Ex.no:3
IMPLEMENTATION OF 2D AND 3D TRANSFORMATION
Date:03-09-2-19
AIM:
ALGORITHM:
Step3: Draw a model for 2d transformation and Rectangle,Cone and cubic surface for 3d and Develop a
Step4: Open video stream and apply scale,rotation and drag transformations with the specified time locations
Step5: Set fixed value for scaling,rotation,drag and X,Y co-ordinates and set Z=0 for 2d transformation.
Step6: Set fixed value for scaling,rotation,drag and X,Y,Z co-ordinates for 3d transformation.
19
OUTPUT:-
2D
3D
RESULT:
Thus the program implementation of 2D and 3D graphic transformation is done successfully.
20
Ex.no :4 ANIMATION CREATION – 1
Date:17-09-2019
AIM:
Step 7: For making a man to walk and vehicle to move use delay function.
21
PROGRAM:
#include<stdio.h>
#include<graphics.h>
#define ScreenWidth getmaxx()
#define ScreenHeight getmaxy()
#define midy getmaxy()/2
#define GroundY ScreenHeight*0.75
int ldisp=0;
rectangle(50+k,275,150+k,400);
rectangle(150+k,350,200+k,400);
circle(75+k,410,10);
circle(175+k,410,10);
setcolor(j);
setcolor(WHITE);
line(0, midy + 37, ScreenWidth, midy + 37);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, RED);
22
line(62 + i, midy - 15, 77 + i, midy - 15);
line(77 + i, midy - 15, 92 + i, midy);
line(92 + i, midy, 62 + i, midy);
line(62 + i, midy, 62 + i, midy - 15);
floodfill(5 + i, midy + 22, YELLOW);
setcolor(BLUE);
setfillstyle(SOLID_FILL, DARKGRAY);
circle(30 + i, midy + 25, 9);
circle(90 + i, midy + 25, 9);
floodfill(30 + i, midy + 25, BLUE);
floodfill(90 + i, midy + 25, BLUE);
setcolor(WHITE);
circle(x,GroundY-90,10);
line(x,GroundY-80,x,GroundY-30);
line(x,GroundY-70,x+15+ldisp,GroundY-60);
line(x,GroundY-65,x+ldisp,GroundY-55);
line(x,GroundY-30,x+ldisp,GroundY);
line(x,GroundY-30,x-ldisp,GroundY);
}
void main()
{
int gd=DETECT,gm,x=0,i=0,j=0,k=0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
while(!kbhit())
{
ldisp=(ldisp+2)%20;
GraphicProcess(x,ldisp,i,j,k);
delay(50);
cleardevice();
x=(x+2)%ScreenWidth;
j++;
k=k+10;
i=i+5;
}
getch();
}
23
OUTPUT:
RESULT:
Thus the program implementation of person walking in the city road is done successfully.
24
Ex.no :5
ANIMATION CREATION - 2
Date:15-10-2019
AIM:
ALGORITHM:
Step 1: Include the necessary library functions for graphics java program.
Step 4: Resize the background image and gif as per the screen size.
PROGRAM:
import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;
public class Park extends JFrame {
private int frameWidth = 700, frameHeight = 500;
private Image image = new ImageIcon("F:/abc.jpg").getImage();
public Park() {
setBounds(100, 100, frameWidth, frameHeight);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
g.drawImage(image, 0,0,getWidth(),getHeight(),this);
for(int i=0;i<=getWidth();i++)
25
{
g.drawImage(image, 0,0,getWidth(),getHeight(),this);
g.drawImage(image1, i,getHeight()-100,100,100,this);
try
{
Thread.sleep(10);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
}
public static void main(String args[]) {
new Park();
}
}
26
OUTPUT:
RESULT:
Thus the program implementation of a man cycling in the park is done successfully.
27
Ex.no :6
ANIMATION CREATION - 3
Date:30-10-2019
AIM
PROCEDURE:
Building a Warrior
Step1: For creating a Warrior animation using blender.
Step2: Open the blender software for deleting the default cube by Alt + X.
Step3: for adding press shift + A to add UV sphere.
Step4: for recompress the UV sphere.
Step5: Add duplicate of the UV sphere to place the body for the Warrior.
Step6: Repeat the step for creating face.
Step7: To move the mirror to place an eye.
Step8: Repeat to create another eye.
Step9: Press Shift + A to add cone to create a nose like structure.
Step10: Press S to resize the cone.
Step11: Add cylinder to create leg structure
Step12: Repeat the step to create a warrior and make duplicate by press Shift + D.
28
OUTPUT:
RESULT:
Thus the program to animate and simulate a cartoon character is done successfully
29