C + + drawing sine Line Instance code _c language

Source: Internet
Author: User
Tags sin

This article describes the C + + drawing sine line of the implementation code, shared for everyone to reference.

The main functional code is as follows:

Copy Code code as follows:
Case WM_PAINT:
HDC = BeginPaint (hWnd, &ps);
TODO: Add any drawing code here ...
Draw the positive and the black line
#define PI 3.1415926
#define SEGMENT 500
int cxclient,cyclient;
RECT RECT;

:: GetClientRect (HWnd, &rect);
Cxclient = Rect.right-rect.left;
Cyclient = Rect.bottom-rect.top;

Point Pt[segment];
for (int i=0;i<segment;i++)
{
pt[i].x = i * cxclient/segment; The length of the cxclient is divided into segment.
PT[I].Y = (int) (CYCLIENT/2) * (1-sin (2 * PI * i/segment)); Because the sin (2pi) is reversed, because the mathematical coordinate y-axis is up and the coordinate y-axis in the system is downward, the +CYCLIENT/2 is to move the coordinate origin to the upper-left corner
}
::P olyline (HDC, PT, SEGMENT); Drawing functions

EndPaint (HWnd, &ps);
Break

I hope this article will help you with the C + + program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.