Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Graphics Expert

Draw the letters S, P, R or U of English alphabet using multiple Bézier curves. 

A complete code for plotting Bezier curves is given previously. There in the code, control points for the Bézier curves are taken using mouse input.  Plot Bézier curves by first identifying the control points of the curve and then storing them in an array.  Always employ curves of same degree for plotting different parts of the alphabet letter.  In the following code, character  P  is generated using only quadratic Bézier curves. Straight line segments are also generated using a quadratic Bézier curve by choosing the control points on a straight line. 

/* Create the character P using multiple Bezier curves*/

#include

#include

#include  

#define n 2 //Uniform degree of all Bezier curves 

int ww=640,wh = 480; //Window Size

int OUT_CURVES = 18; //Counter for curves in outer boundary

int IN_CURVES=12; // Counter for curves in inner boundary

//Coordinates of control points for outer curves

int Px_Out[21]={90, 120, 160, 180, 180, 180, 180, 180, 160,

140, 120, 120,120, 120, 140, 140,140, 120, 90, 90, 90};

int Py_Out[21]={100, 100, 100, 100, 120, 140, 160, 180, 180,

180, 180, 230,230,240,240, 250, 260, 260, 260, 200,100};

//Coordinates of control points for inner curves

int Px_In[15]={120, 130, 140, 160, 160, 160, 160,

160,160,160,130,120,120,120,120};

int Py_In[15]={120, 120, 120, 120, 130, 140,

140,145,150,160,160,160,160,130,120};  

void myInit(){

    glClearColor(0.0,0.0,0.0,0.0);

    glColor3f(0.0,1.0,0.0);

    glPointSize(4.0); //Select point size 

    gluOrtho2D(0.0,640.0,0.0,480.0); 

    //For setting the clipping areas  

} //Initialize    

//Point plotting    

//Computing factorial of a number k

int factorial(int k) {

 int fact=1,i;

 for(i=1;i<=k;i++)

 fact=fact*i;

 return fact; }  

/* Draw a bezier curve with control points (x[i],y[i]),

i=0,..., n */

void drawBezier(int x[n+1], int y[n+1]) {

 double P_x,P_y;

 glColor3f(1.0,1.0,1.0); //Set drawing colour for curve

 for( double t=0.0;t<=1.0;t+=0.01){

  P_x=0.0; 

  P_y=0.0;

 glBegin(GL_POINTS); //Draw point (P_x,P_y) on the curve 

for( int i=0;i<=n;i++) {

 int cni=factorial(n)/(factorial(n-i)*factorial(i));

 P_x = P_x+(double)(x[i]*cni)*pow(1 - t,n-i)*pow(t,i); 

 P_y = P_y+(double)(y[i]*cni)*pow(1 - t,n-i)*pow(t,i); 

   }

 

   glVertex2f(P_x,wh -P_y); 

   }

 glEnd();

glFlush(); }

 

//Draw character P using Bezier curves

void Bezier()

{

 int Control_x[3], Control_y[3];

 //Outer Boundary curves 

 for (int j=0;j<=OUT_CURVES; j+=2){

  Control_x[0]=Px_Out[j];

  Control_y[0]=Py_Out[j];

  Control_x[1]=Px_Out[j+1];

  Control_y[1]=Py_Out[j+1];

  Control_x[2]=Px_Out[j+2];

  Control_y[2]=Py_Out[j+2];

 drawBezier(Control_x, Control_y);

 }

 //Inner Boundary curves

 for (int j=0;j<=IN_CURVES; j+=2){

  Control_x[0]=Px_In[j];

  Control_y[0]=Py_In[j];

  Control_x[1]=Px_In[j+1];

  Control_y[1]=Py_In[j+1];

  Control_x[2]=Px_In[j+2];

  Control_y[2]=Py_In[j+2];

 drawBezier(Control_x, Control_y);

 }

 glFlush();

}

//Draw character P on a mouse click

void myMouse(int button, int state, int x, int y) { 

 if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {      

  Bezier();

  glFlush();} 

}

void myDisplay() {

    glClear(GL_COLOR_BUFFER_BIT);

 //Bezier();

    glFlush();

}

int main() {

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

    glutInitWindowSize(ww,wh);

    glutInitWindowPosition(200,200);

    glutCreateWindow("Bezier curves");

    glutMouseFunc(myMouse);

    glutDisplayFunc(myDisplay);

    myInit();

    glutMainLoop();

 return 0;

}

 Other characters R,S,U can be similarly plotted using appropriate coordinates of the control points.

Computer Graphics, Computer Science

  • Category:- Computer Graphics
  • Reference No.:- M9623102

Have any Question?


Related Questions in Computer Graphics

The problemyou are to search a bitmap in rgb format and

The problem: You are to search a bitmap in RGB format and count the number of pixels which match a set of colors. The bitmap will be 1024 by 1024 pixels for the purposes of explaining this problem. The set of colors will ...

Please read my question if you post copy and pasted code

Please read my question if you post copy and pasted code you will get a negative review. This is java In this graphical program, you are going to simulate arcade car racing game. You need a single player that is movable ...

You have a program draw a rectangle on the screen and allow

You have a program draw a rectangle on the screen and allow the user to change the color/size of the rectangle. The program will store in the browser the settings of the color/size so that upon revisiting the page, the v ...

The problemsit is strongly recommended that you tackle the

The problems: It is strongly recommended that you tackle the following tasks in a modular way -- a separate standalone function for each task. Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polyg ...

The saffir-simpson hurricane scale classifies hurricanes

The Saffir-Simpson Hurricane Scale classifies hurricanes into five categories numbered 1 through 5. Write an application named Hurricane that outputs a hurricane's category based on the user's input of the wind speed. CA ...

Question a describe the architecture of simple raster

Question : a) Describe the architecture of simple raster graphics system? b) Explain raster scan display processor?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As