Showing posts with label COMPUTER GRAPHICS. Show all posts
Showing posts with label COMPUTER GRAPHICS. Show all posts

Rolling ball Computer Animation Program using C++ VB 6.0

The Animation program is Rolling Ball over a horizontal line . The ball start rolling at the start of the line and moves till the end of line length.The program is implemented using C++ MS Visual studio , MFC application.

PROGRAM:
                                             
void CAnimation1View::OnDraw(CDC* pDC)
{
	CAnimation1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
    POINT ball[2]={25,150,75,100};
	pDC->Ellipse(ball[0].x,ball[0].y,ball[1].x,ball[1].y);
	
	for(int i=0;i<600;i++)
	{
		pDC->FloodFill(50,50,RGB(100,100,100));
		pDC->Ellipse(ball[0].x++,ball[0].y,ball[1].x++,ball[1].y);
		pDC->MoveTo(10,150);
	pDC->LineTo(600,150);
		Sleep(1);
	}

}

OUTPUT:


Read more »

Computer Animation Bouncing Ball Program using MFC C++ code

Basic Computer Animation Program using MS Visual Studio 6.0 with MFC application.Here in this program we make use of flood fill concept . The function is very simple indicating just coordinates which has to be displayed on the screen.

 PROGRAM:
void CBouncingballView::OnDraw(CDC* pDC)
{
	CBouncingballDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
POINT ball[2]={25,150,75,100};
	pDC->Ellipse(ball[0].x,ball[0].y,ball[1].x,ball[1].y);
	for(int k=0;k<600;k++)
	{
		pDC->FloodFill(50,50,RGB(100,100,100));
        pDC->MoveTo(10,150);
	    pDC->LineTo(600,150);
		for(int i=0;i<250;i++)
		{
		for(int i=0;i<250;i++)
	{
		pDC->FloodFill(50,50,RGB(100,100,100));
		pDC->Ellipse(ball[0].x,ball[0].y++,ball[1].x,ball[1].y++);
	    pDC->MoveTo(10,400);
	    pDC->LineTo(600,400);
	}
	for(int j=250;j>=1;j--)
    {	
		pDC->FloodFill(50,50,RGB(100,100,100));
		pDC->Ellipse(ball[0].x++,ball[0].y--,ball[1].x++,ball[1].y--);
        pDC->MoveTo(10,400);
	    pDC->LineTo(600,400);
	    Sleep(1);
	}
		}
	}
}


OUTPUT:



Read more »

Implementing ellipse Program using computer Graphics C++ Code

This Program illustrates how to draw a circle without using the direct function. The Program is written in C++ language using  Microsoft Developer Studio , Format Version 6.00.This part of programming belongs to basic Computer graphics.Use MS visual studio 6.0 with MFC application.

PROGRAM:
#include "stdafx.h"
#include "ellipse.h"

#include "ellipseDoc.h"
#include "ellipseView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
#define ROUND(a)((int)(a+0.5))
static char THIS_FILE[] = __FILE__;
#endif

void ellipseMidPoint(int Xcenter,int Ycenter,int Rx,int Ry,CDC* pDC,COLORREF color)
{
	int Rx2=Rx*Rx;
	int Ry2=Ry*Ry;
	int twoRx2=2*Rx2;
	int twoRy2=2*Ry2;
	int p;
	int x=0;
	int y=Ry;
	int px=0;
	int py=twoRx2*y;
    void ellipsePlotPoints(int,int,int,int,CDC* pDC,COLORREF color);
	
	ellipsePlotPoints(Xcenter,Ycenter,x,y,pDC,color);
    
	p=ROUND(Ry2-(Rx2*Ry)*(0.25*Rx2));
	
	while(px<py)
	{
		x++;
		px+=twoRy2;
		if(p<0)
			p+=Ry2*px;
		else
		{
			y--;
			py-=twoRx2;
			p+=Ry2+px-py;
		}
		ellipsePlotPoints(Xcenter,Ycenter,x,y,pDC,color);
	}
	p=ROUND(Ry2*(x+0.5)*(x+0.5)+Rx2*(y-1)*(y-1)-Rx2*Ry2);
	while(y>0)
	{
		y--;
	py-=twoRx2;
	if(p>0)
		p+=Rx2-py;
	else
	{
		x++;
		px+=twoRy2;
		p+=Rx2-py+px;
	}
	ellipsePlotPoints(Xcenter,Ycenter,x,y,pDC,color);
}
}
void ellipsePlotPoints(int Xcenter,int Ycenter,int x,int y,CDC* pDC,COLORREF color)
{
	pDC->SetPixel(Xcenter+x, Ycenter+y,color);
	pDC->SetPixel(Xcenter-x, Ycenter+y,color);
	pDC->SetPixel(Xcenter+x, Ycenter-y,color);
	pDC->SetPixel(Xcenter-x, Ycenter-y,color);
}
void CEllipseView::OnDraw(CDC* pDC)
{
	CEllipseDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
		COLORREF color=RGB(0,0,0);
	ellipseMidPoint(150,70,13,50,pDC,color);

	// TODO: add draw code for native data here
}


OUTPUT:



Read more »