You are on page 1of 5

Grafica

vectoriala
Proiectul nr.1
Student: Bradisteanu Elisaveta

Anul de studii

2016 2017
// pro1View.cpp : implementation of the Cpro1View class

//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "pro1.h"
#endif
#include "pro1Doc.h"
#include "pro1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include<math.h>
// Cpro1View
IMPLEMENT_DYNCREATE(Cpro1View, CView)
BEGIN_MESSAGE_MAP(Cpro1View, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &Cpro1View::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
END_MESSAGE_MAP()
// Cpro1View construction/destruction
Cpro1View::Cpro1View()
{
// TODO: add construction code here
}
Cpro1View::~Cpro1View()
{
}
BOOL Cpro1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// Cpro1View drawing
double fun(double x, double e) {
int k;
double t, s;
k = 0;
t=s=1;
for(k = 1; k<=100; k++){
t *= x/k;
s += t;
}
return s;
}
void Cpro1View::OnDraw(CDC* pDC)
{
Cpro1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;

// TODO: add draw code for native data here


///////////////////desenam axa Ox/////////////////////////
CRect rcClient; //am creat un dreptunghi cu numele Client
GetClientRect(&rcClient);
CPen penAxe(PS_SOLID, 3, RGB(0, 0, 0)); // am creat o penita
CPen penGrf(PS_SOLID, 2, RGB(0, 0, 200));
pDC -> SelectObject(&penAxe); // am selectat penita creata
pDC -> MoveTo(0, rcClient.CenterPoint().y); // am mutat cursorul pe coordonatele date
pDC -> LineTo(rcClient.Width(), rcClient.CenterPoint().y);
///////////////////desenam axa Oy/////////////////////////
pDC -> MoveTo(rcClient.CenterPoint().x, 0);
pDC -> LineTo(rcClient.CenterPoint().x, rcClient.Height());
rcClient.CenterPoint();
double x, y, a = -2, b = 2, st = 0.0025, scx = 80.0, scy = 80.0, e = 0.0001;
//sageata y
pDC->MoveTo(rcClient.CenterPoint().x, 0);
pDC->LineTo(rcClient.CenterPoint().x-7, 7);
pDC->MoveTo(rcClient.CenterPoint().x, 0);
pDC->LineTo(rcClient.CenterPoint().x+7, 7);
//sageata x
pDC->MoveTo(rcClient.Width(), rcClient.CenterPoint().y);
pDC->LineTo(rcClient.Width()-7, rcClient.CenterPoint().y-7);
pDC->MoveTo(rcClient.Width(), rcClient.CenterPoint().y);
pDC->LineTo(rcClient.Width()-7, rcClient.CenterPoint().y+7);
//axa de coordonate x
double depl=scx;
while(depl<=rcClient.Width()){
pDC->MoveTo(rcClient.CenterPoint().x+depl, rcClient.CenterPoint().y-4);
pDC->LineTo(rcClient.CenterPoint().x+depl, rcClient.CenterPoint().y+4);
pDC->MoveTo(rcClient.CenterPoint().x-depl, rcClient.CenterPoint().y-4);
pDC->LineTo(rcClient.CenterPoint().x-depl, rcClient.CenterPoint().y+4);
depl+=scx;
}
//axa de coordonate y
depl=scy;
while(depl<=rcClient.Height()-5){
pDC->MoveTo(rcClient.CenterPoint().x-4, rcClient.CenterPoint().y-depl);
pDC->LineTo(rcClient.CenterPoint().x+4, rcClient.CenterPoint().y-depl);
pDC->MoveTo(rcClient.CenterPoint().x-4, rcClient.CenterPoint().y+depl);
pDC->LineTo(rcClient.CenterPoint().x+4, rcClient.CenterPoint().y+depl);
depl+=scy;
}
x = a;
FILE *g; g=fopen("file1.txt","w+");
while(x <= b) {
y = exp(x)*1.1;
pDC -> SetPixel(rcClient.CenterPoint().x + (int)(x * scx), rcClient.CenterPoint().y - (int)(y * scy),
RGB(200, 0, 0));
fprintf(g,"%f - > %f\n",x,y);
x += st;
}
fclose(g);
pDC -> SelectObject(&penGrf);
x=a;
FILE *f; f=fopen("file2.txt","w+");

scy));

y = fun(x, e) ;
pDC -> MoveTo(rcClient.CenterPoint().x + (int)(x * scx), rcClient.CenterPoint().y - (int)(y *
x=a;
while(x <=b){
y = fun(x, e) ;

pDC -> LineTo(rcClient.CenterPoint().x + (int)(x * scx), rcClient.CenterPoint().y - (int)(y * scy));


fprintf(f,"%f - > %f\n",x,y);
x += st;
}
fclose(f);
}
// Cpro1View printing
void Cpro1View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL Cpro1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void Cpro1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void Cpro1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void Cpro1View::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void Cpro1View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// Cpro1View diagnostics
#ifdef _DEBUG
void Cpro1View::AssertValid() const
{
CView::AssertValid();
}
void Cpro1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
Cpro1Doc* Cpro1View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cpro1Doc)));
return (Cpro1Doc*)m_pDocument;
}
#endif //_DEBUG

// Cpro1View message handlers

You might also like