C # small exercise notes: generate a Rose Line Pattern

Source: Internet
Author: User

This article is from the csdn blog,Reposted source (column of the tree man in Summer) 

Discuss this pattern with Vincent. He uses js to implement this Rose Line Pattern and uses the new HTML5 features. It is found that this pattern can be implemented in other languages. The results are quite good.

Mathematical formula: P = A * sin (Num * angle );

I would like to try an experiment to see if other languages can be generated in the same way. The tested principles are the same. This time I used the C # drawing API. The premise is that I am not familiar with C # And it takes a lot of time to read this document. And I am not familiar with it. C # is operating. I wrote a script. Fortunately, the pattern is generated.

Step 1: Create a C # windows application. Name: Rose Wire

 

Add this event to the paint event on the property panel.

 

 

 

C # source code:

The difference is that different degrees will produce different results. But the formula is the same.

// Double [] point1 = getpoint (200, (I-1) * Math. PI/180, 2 );

// Double [] point2 = getpoint (200, I * Math. PI/180,2 );

Double [] point1 = getpoint (200, (I-1), 5 );

Double [] point2 = getpoint (200, I, 5 );

Here, I use the trigonometric function transformation to find the coordinate values of X and Y, and then link them one by one from the start point.

P0 -- P1 --> P2 --> p3... keep connected like this. In this way, we can see the pattern we want to see.

 

View plaincopy to clipboardprint?


Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;


Namespace rose Wire
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}


Private void form1_paint (Object sender, painteventargs E)
{

Graphics G = E. graphics;
Pen P = new pen (color. Black, 1 );

For (INT I = 1; I <= 360; I ++)
{

// Double [] point1 = getpoint (200, (I-1) * Math. PI/180, 2 );

// Double [] point2 = getpoint (200, I * Math. PI/180,2 );

Double [] point1 = getpoint (200, (I-1), 5 );

Double [] point2 = getpoint (200, I, 5 );

G. drawline (p, 250 + convert. toint32 (point1 [0]), 200 + convert. toint32 (point1 [1]), 250 + convert. toint32 (point2 [0]), 200 + convert. toint32 (point2 [1]);

}

}

Private double [] getpoint (int r, double I, int num)
{

Double Len = r * Math. Sin (Num * I );
Double [] Point = change (Len, I );
Return Point;

}


Private double [] Change (double Len, double angle)
{

Double [] array = new double [2];
Array [0] = Len * Math. Cos (angle );
Array [1] = Len * Math. Sin (angle );
Return array;
}



}
}

 

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.