Write balensley fern in C Language

Source: Internet
Author: User

Write balensley fern in C Language

First, I wrote the program in VS2015, as shown in figureIf you cannot load this file in VS2015, read my previous article and find a solution.

The core of the code is to use the SetPixel (hdc, x, y, color) function to generate the pixel image of bayensley fern.

Directly paste the Code:

#include<graphics.h>
void main() {
	HWND hwnd = NULL;
	HDC hdc = GetDC(hwnd);
	srand(0);
	double x = 0.0, y = 0.0;
	for (int i = 0; i < 200000; i++) {
		int r = rand() % 100;
		if (r == 0) { x = 0; y = 0.16*y; }
		else if (r > 0 && r <= 85) { x = 0.85*x + 0.04*y; y = (-0.04)*x + 0.85*y + 1.6; }
		else if (r>85&&r<=92) { x = 0.2*x + (-0.26)*y; y = 0.23*x + 0.22*y + 1.6; }
		else { x = (-0.15)*x + 0.28*y; y = 0.26*x + 0.24*y + 0.44; }
		SetPixel(hdc, (int)((x * 25) + 200), (int)((y * 25) + 100), 0x00FF00);
	}	
}

Running result:


PS: I am also a beginner and have limited capabilities. Therefore, after generating the bayensley fern, try not to shake the mouse as much as possible. Otherwise, the generated image will soon disappear, even if you do not stop for a few seconds, it will disappear.


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.