Write C++/Java program to draw any object such as flower, waves using any curve generation techniques

Second Year Computer Engineering Computer Graphics Programs:

Computer Graphics Lab:

Practical:B14
Write C++/Java program to draw any object such as flower, waves using any curve generation techniques.
----------------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
int maxx,maxy;
float xxx [4][2];
void line1(float x2,float y2)
{
line(xxx[0][0],xxx[0][1],x2,y2);
xxx[0][0]=x2;
xxx[0][1]=y2;
}
void bezier(float xb,float yb,float xc,float yc,float xd,float yd,int n)
{
float xab,yab,xbc,ybc,xcd,ycd;
float xabc,yabc,xbcd,ybcd;
float xabcd,yabcd;
if(n==0)
{
line1(xb,yb);
line1(xc,yc);
line1(xd,yd);
}
else
{
xab = (xxx[0][0]+xb)/2;
yab = (xxx[0][1]+yb)/2;
xbc = (xb+xc)/2;
ybc = (yb+yc)/2;
xcd = (xc+xd)/2;
ycd = (yc+yd)/2;
xabc = (xab+xbc)/2;
yabc = (yab+ybc)/2;
xbcd = (xbc+xcd)/2;
ybcd = (ybc+ycd)/2;
xabcd = (xabc+xbcd)/2;
yabcd = (yabc+ybcd)/2;
n=n-1;
bezier(xab,yab,xabc,yabc,xabcd,yabcd,n);
bezier(xbcd,ybcd,xcd,ycd,xd,yd,n);
}
}
int main()
{
int i;
float temp1,temp2;
int gm,gd=DETECT;
initgraph(&gd,&gm,NULL);
xxx[0][0] = 100;
xxx[0][1] = 200;
bezier(150,50,200,50,250,200,8);
xxx[0][0] = 250;
xxx[0][1] = 200;
bezier(300,350,350,350,400,200,8);
getch();
closegraph();
return 0;
}
----------------------------------------------------------------------------------------------------------------------------------

Comments

Post a Comment

Popular posts from this blog

Implement C++ program for expression conversion as infix to postfix and its evaluation using stack.

Write C++ program to maintain club member‘s information using singly linked list. Store student PRN and Name.

Write C++/Java program for line drawing using DDA or Bresenhams algorithm with patterns such as solid, dotted, dashed, dash dot and thick.