1. Dibuje una línea de caracol
//Draw snail line
void CCavsSampleView::OnMenuitemWoniuline()
{
float pi = 3.1415926f;
CRect rect;
GetClientRect(&rect);
UINT width = rect.Width();
UINT height = rect.Height();
CDC* pDC = GetDC();
for (float x = 0;x < 10*pi; x+= pi/width)
{
if (x == 0) pDC->SetPixel(width/2, 0, RGB(255,0,0));
else pDC->SetPixel((int)(width*sin(x)/x*cos(x)+width/2), (int)(width*sin(x)/x*sin(x)),RGB(255,0,0));
}
}
2. Dibuje la curva de Bézier
Cada curva Bézier consta de cuatro nodos, un punto inicial, dos puntos de control y un punto final. Cuando se ajusten los dos puntos de control, se cambiará la forma de la curva Bézier. .
BOOL PolyBezier(
const POINT* lpPoints,//La matriz de estructura de datos POINT del punto final y el punto de control de la curva
int nCount);//Especifique el número de puntos de la matriz lpPoints. Este valor debe ser 3 veces el número de curvas que se dibujará más 1.
// Draw Bezier curve
void CCavsSampleView::OnMenuitemDrawbezier()
{
CDC* pDC = GetDC();
CPoint pt[] = { CPoint(40, 72), CPoint(107, 302),
CPoint(329, 292),
CPoint(79, 148),
CPoint(498, 29),
CPoint(322, 201),
CPoint(176, 137) };
pDC->PolyBezier(pt, sizeof(pt)/sizeof(pt[0]));
}
Tres, dibuja una curva sinusoidal
y=Asin(x)
Utilice la función DrawLine() para dibujar una línea central azul en el centro de la pantalla. En el bucle for, utilice la coordenada x, es decir, la abscissa como variable de cálculo, de 0 a la anchura de la pantalla. Y después de calcular el valor y mostrado a través del valor positivo del deslumbramiento y la amplitud,
Utilice la función DrawLine para dibujar una curva deslumbrante roja.
//Draw a sine curve
void CCavsSampleView::OnMenuitemSinline()
{
float pi = 3.1415926f;
Status status = GenericError;
Graphics graphics(m_hWnd);
status = graphics.GetLastStatus();
if (status != Ok)
return;
CRect rect;
GetClientRect(&rect);
UINT width = rect.Width();
UINT height = rect.Height();
Pen bluePen(Color(255, 0, 0, 255), 1);//Draw the center line
graphics.DrawLine(&bluePen, 0, height/2, width, height/2);
Pen redPen(Color(255, 255, 0, 0), 2);//Draw a sine curve
float oldX = 0.0f;
float oldY=(float)(width/2);
for (float x = 0;x < width;x++)
{
float radian = x/width*10*pi;
float y = (float)sin(radian);
y = (1-y)*height/2;
graphics.DrawLine(&redPen, oldX, oldY, x, y);
oldX = x;
oldY = y;
}
}
.