منحنی های بزیه - 1403/05/08 - الف - جدول کدها
به نام خدا
سلام به شما دوستداران علم و هنر
ادامه ی مطالب یادداشت "منحنی های بزیه":
جدول سه: جدول کدها:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Try_Bezier_01 { internal class class_Level { internal List<class_Line> Lines; } } |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace Try_Bezier_01 { internal class class_Line { internal Point start_point; internal Point end_point; } } |
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Try_Bezier_01 { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Try_Bezier_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Pen pen; Point pt1, pt2, pt3, pt4; Point pt11, pt12, pt13, pt14; class_Level[] Levels; int red, green, blue; int x, y; Graphics graphics_1; class_Line line; Point start_point, end_point; double percentage; int counter1; private void button1_Click(object sender, EventArgs e) { EvHa_button1_Click(); } private void EvHa_button1_Click() { pen = new Pen(Color.DarkMagenta, 3); draw_level_0(); } private void draw_level_0() { if (Levels[0] != null) { for (int i = 0; i < counter1; i++) { pen = new Pen(get_random_color()); graphics_1.DrawLine( pen, Levels[0].Lines[i].start_point, Levels[0].Lines[i].end_point ); } } } private Color get_random_color() { //throw new NotImplementedException(); int red, green, blue; red = new Random().Next(0, 255 + 1); sleep(new Random().Next(2, 12 + 1)); green = new Random().Next(0, 255 + 1); sleep(new Random().Next(2, 12 + 1)); blue = new Random().Next(0, 255 + 1); return (Color.FromArgb( red, green, blue )); } private void sleep(int p) { //throw new NotImplementedException(); System.Threading.Thread.Sleep(p); } private void init_02() { graphics_1.Clear(Color.Black); red = 255; green = 100; blue = 100; pen = new Pen(Color.FromArgb(red, green, blue)); //for (int i = 0; i < 6; i++) //{ // Levels[0].Lines.Add(line); //} //for (int i = 0; i < Levels[0].Lines.Count; i++) //{ // Levels[0].Lines[i] = new class_Line(); //} } private void init_01() { //throw new NotImplementedException(); counter1 = 0; graphics_1 = Graphics.FromHwnd(pictureBox1.Handle); Levels = new class_Level[3]; //for (int i = 0; i < Levels.Length; i++) //{ // Levels[i] = new class_Level(); // Levels[i].Lines = new List<class_Line>(); //} //Levels[0] = new class_Level(); //Levels[0].Lines = new List<class_Line>(); //line = new class_Line(); } private void button2_Click(object sender, EventArgs e) { EvHa_button2_Click(); } private void EvHa_button2_Click() { draw_level_1(); } private void draw_level_1() { //int pen_width; //pen_width = (int)(numericUpDown_pen_width.Value); set_random_pen(true, 1); //set_pen(200,150,160,pen_width); ////////// //Levels[1] = new class_Level(); //Levels[1].Lines = new List<class_Line>(); //line = new class_Line(); Levels[1] = new class_Level(); Levels[1].Lines = new List<class_Line>(); if (Levels[0] != null) { for (int i = 0; i < Levels[0].Lines.Count - 1; i++) { Levels[1].Lines.Add(line); Levels[1].Lines[i] = new class_Line(); } percentage = (double)numericUpDown_percentage.Value; for (int i = 0; i < Levels[0].Lines.Count - 2; i++) { //percentage = 30; start_point = Levels[0].Lines[i].start_point; end_point = Levels[0].Lines[i].end_point; Levels[1].Lines[i].start_point = percenty_point(start_point, end_point, percentage); start_point = Levels[0].Lines[i + 1].start_point; end_point = Levels[0].Lines[i + 1].end_point; Levels[1].Lines[i].end_point = percenty_point(start_point, end_point, percentage); graphics_1.DrawLine( pen, Levels[1].Lines[i].start_point, Levels[1].Lines[i].end_point ); } } } private void set_pen(int red, int green, int blue, int pen_width) { pen = new Pen(Color.FromArgb(red, green, blue), pen_width); } private Point percenty_point(Point start_point, Point end_point, double percentage) { //throw new NotImplementedException(); Point r_percenty_point; r_percenty_point = new Point( (int)((percentage / 100d) * start_point.X + (100d - percentage) / 100d * end_point.X), (int)((percentage / 100d) * start_point.Y + (100d - percentage) / 100d * end_point.Y) ); return r_percenty_point; } private void Form1_Load(object sender, EventArgs e) { init_01(); } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { EvHa_button1_Click(); EvHa_button2_Click(); EvHa_button3_Click(); } private void EvHa_button3_Click() { //throw new NotImplementedException(); //set_random_pen(false,12); set_random_pen(true, 1); // set_pen(30,170,200,2); ////////// Levels[2] = new class_Level(); Levels[2].Lines = new List<class_Line>(); for (int i = 0; i < Levels[1].Lines.Count - 1; i++) { Levels[2].Lines.Add(line); Levels[2].Lines[i] = new class_Line(); } percentage = (double)numericUpDown_percentage.Value; for (int i = 0; i < Levels[1].Lines.Count - 2; i++) { //percentage = 30; start_point = Levels[1].Lines[i].start_point; end_point = Levels[1].Lines[i].end_point; Levels[2].Lines[i].start_point = percenty_point(start_point, end_point, percentage); start_point = Levels[1].Lines[i + 1].start_point; end_point = Levels[1].Lines[i + 1].end_point; Levels[2].Lines[i].end_point = percenty_point(start_point, end_point, percentage); graphics_1.DrawLine( pen, Levels[2].Lines[i].start_point, Levels[2].Lines[i].end_point ); } } private void set_random_pen(bool has_random_width , int width) { //throw new NotImplementedException(); if (has_random_width) { int min_width , max_width; min_width = (int)(numericUpDown_pen_width_min.Value); max_width = (int)(numericUpDown_pen_width_max.Value); pen = new Pen(get_random_color(), get_random_width(min_width, max_width)); } else { pen = new Pen(get_random_color(), width); } } private float get_random_width(int min , int max) { //throw new NotImplementedException(); int random_width; sleep(new Random().Next(2, 12 + 1)); random_width = new Random().Next(min, max + 1); return random_width; } private void pictureBox1_Click(object sender, EventArgs e) { } private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { if (counter1 == 0) { draw_level_0(); init_02(); Levels[0] = new class_Level(); Levels[0].Lines = new List<class_Line>(); Levels[0].Lines.Add(new class_Line()); Levels[0].Lines[0].start_point = new Point(e.X, e.Y); Levels[0].Lines[0].end_point = new Point(e.X + 1, e.Y + 1); draw_level_0(); counter1++; } else { Levels[0].Lines[counter1 - 1].end_point = new Point(e.X, e.Y); Levels[0].Lines.Add(new class_Line()); Levels[0].Lines[counter1].start_point = new Point(e.X, e.Y); Levels[0].Lines[counter1].end_point = new Point(e.X + 1, e.Y + 1); counter1++; draw_level_0(); } //sleep(10); draw_level_0(); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (counter1 == 0) { pen = new Pen(Color.Blue); graphics_1.DrawLine(pen, e.X, e.Y, e.X + 2, e.Y + 2 ); } else if (Levels[0].Lines.Count > 1) { for (int i = 0; i < counter1; i++) { //Levels[0].Lines[i].end_point = new Point(e.X, e.Y); graphics_1.DrawLine( pen, Levels[0].Lines[i].start_point, Levels[0].Lines[i].end_point ); } } } private void button_clear_Click(object sender, EventArgs e) { clear(); } private void clear() { //throw new NotImplementedException(); graphics_1.Clear(Color.Black); init_01(); } private void button_draw_level_0_Click(object sender, EventArgs e) { EvHa_button1_Click(); } private void button_draw_level_1_Click(object sender, EventArgs e) { EvHa_button2_Click(); } private void numericUpDown_pen_width_min_ValueChanged(object sender, EventArgs e) { if (numericUpDown_pen_width_min.Value > numericUpDown_pen_width_max.Value) { numericUpDown_pen_width_min.Value--; } } private void numericUpDown_pen_width_max_ValueChanged(object sender, EventArgs e) { if (numericUpDown_pen_width_max.Value < numericUpDown_pen_width_min.Value) { numericUpDown_pen_width_max.Value++; } } } } |
namespace Try_Bezier_01 { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button_draw_level_0 = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button_draw_level_1 = new System.Windows.Forms.Button(); this.numericUpDown_percentage = new System.Windows.Forms.NumericUpDown(); this.button_clear = new System.Windows.Forms.Button(); this.numericUpDown_pen_width_min = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.numericUpDown_pen_width_max = new System.Windows.Forms.NumericUpDown(); this.label3 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.panel1 = new System.Windows.Forms.Panel(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.panel2 = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_percentage)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_pen_width_min)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_pen_width_max)).BeginInit(); this.groupBox1.SuspendLayout(); this.panel1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.panel2.SuspendLayout(); this.SuspendLayout(); // // button_draw_level_0 // this.button_draw_level_0.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128))))); this.button_draw_level_0.Location = new System.Drawing.Point(20, 17); this.button_draw_level_0.Name = "button_draw_level_0"; this.button_draw_level_0.Size = new System.Drawing.Size(123, 50); this.button_draw_level_0.TabIndex = 0; this.button_draw_level_0.Text = "Draw Level 0"; this.button_draw_level_0.UseVisualStyleBackColor = false; this.button_draw_level_0.Click += new System.EventHandler(this.button_draw_level_0_Click); // // pictureBox1 // this.pictureBox1.BackColor = System.Drawing.Color.Black; this.pictureBox1.Location = new System.Drawing.Point(17, 17); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(641, 521); this.pictureBox1.TabIndex = 1; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick); this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); // // button_draw_level_1 // this.button_draw_level_1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); this.button_draw_level_1.Location = new System.Drawing.Point(20, 73); this.button_draw_level_1.Name = "button_draw_level_1"; this.button_draw_level_1.Size = new System.Drawing.Size(123, 50); this.button_draw_level_1.TabIndex = 2; this.button_draw_level_1.Text = "Draw Level 1"; this.button_draw_level_1.UseVisualStyleBackColor = false; this.button_draw_level_1.Click += new System.EventHandler(this.button_draw_level_1_Click); // // numericUpDown_percentage // this.numericUpDown_percentage.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.numericUpDown_percentage.Increment = new decimal(new int[] { 5, 0, 0, 0}); this.numericUpDown_percentage.Location = new System.Drawing.Point(20, 266); this.numericUpDown_percentage.Name = "numericUpDown_percentage"; this.numericUpDown_percentage.Size = new System.Drawing.Size(95, 29); this.numericUpDown_percentage.TabIndex = 3; this.numericUpDown_percentage.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // button_clear // this.button_clear.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.button_clear.Location = new System.Drawing.Point(20, 150); this.button_clear.Name = "button_clear"; this.button_clear.Size = new System.Drawing.Size(117, 65); this.button_clear.TabIndex = 2; this.button_clear.Text = "Clear"; this.button_clear.UseVisualStyleBackColor = false; this.button_clear.Click += new System.EventHandler(this.button_clear_Click); // // numericUpDown_pen_width_min // this.numericUpDown_pen_width_min.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.numericUpDown_pen_width_min.Location = new System.Drawing.Point(20, 340); this.numericUpDown_pen_width_min.Maximum = new decimal(new int[] { 12, 0, 0, 0}); this.numericUpDown_pen_width_min.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown_pen_width_min.Name = "numericUpDown_pen_width_min"; this.numericUpDown_pen_width_min.Size = new System.Drawing.Size(95, 29); this.numericUpDown_pen_width_min.TabIndex = 3; this.numericUpDown_pen_width_min.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown_pen_width_min.ValueChanged += new System.EventHandler(this.numericUpDown_pen_width_min_ValueChanged); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.ForeColor = System.Drawing.Color.Coral; this.label1.Location = new System.Drawing.Point(16, 239); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(127, 24); this.label1.TabIndex = 4; this.label1.Text = "percentage = "; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.ForeColor = System.Drawing.Color.Coral; this.label2.Location = new System.Drawing.Point(16, 313); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(154, 24); this.label2.TabIndex = 4; this.label2.Text = "pen_width.min = "; // // numericUpDown_pen_width_max // this.numericUpDown_pen_width_max.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.numericUpDown_pen_width_max.Location = new System.Drawing.Point(20, 410); this.numericUpDown_pen_width_max.Maximum = new decimal(new int[] { 12, 0, 0, 0}); this.numericUpDown_pen_width_max.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown_pen_width_max.Name = "numericUpDown_pen_width_max"; this.numericUpDown_pen_width_max.Size = new System.Drawing.Size(95, 29); this.numericUpDown_pen_width_max.TabIndex = 3; this.numericUpDown_pen_width_max.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown_pen_width_max.ValueChanged += new System.EventHandler(this.numericUpDown_pen_width_max_ValueChanged); // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.ForeColor = System.Drawing.Color.Coral; this.label3.Location = new System.Drawing.Point(16, 383); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(159, 24); this.label3.TabIndex = 4; this.label3.Text = "pen_width.max = "; // // groupBox1 // this.groupBox1.Controls.Add(this.panel1); this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.groupBox1.ForeColor = System.Drawing.Color.CornflowerBlue; this.groupBox1.Location = new System.Drawing.Point(27, 23); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(259, 547); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; this.groupBox1.Text = "Options : "; // // panel1 // this.panel1.AutoScroll = true; this.panel1.Controls.Add(this.button_draw_level_0); this.panel1.Controls.Add(this.numericUpDown_pen_width_min); this.panel1.Controls.Add(this.label3); this.panel1.Controls.Add(this.label1); this.panel1.Controls.Add(this.button_draw_level_1); this.panel1.Controls.Add(this.numericUpDown_percentage); this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.numericUpDown_pen_width_max); this.panel1.Controls.Add(this.button_clear); this.panel1.Location = new System.Drawing.Point(21, 26); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(213, 487); this.panel1.TabIndex = 5; // // groupBox2 // this.groupBox2.Controls.Add(this.panel2); this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.groupBox2.ForeColor = System.Drawing.Color.Cornsilk; this.groupBox2.Location = new System.Drawing.Point(292, 23); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(731, 547); this.groupBox2.TabIndex = 6; this.groupBox2.TabStop = false; this.groupBox2.Text = "Drawing : "; // // panel2 // this.panel2.AutoScroll = true; this.panel2.Controls.Add(this.pictureBox1); this.panel2.Location = new System.Drawing.Point(16, 26); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(633, 521); this.panel2.TabIndex = 2; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScroll = true; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); this.ClientSize = new System.Drawing.Size(903, 545); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_percentage)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_pen_width_min)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_pen_width_max)).EndInit(); this.groupBox1.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.panel2.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button_draw_level_0; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button button_draw_level_1; private System.Windows.Forms.NumericUpDown numericUpDown_percentage; private System.Windows.Forms.Button button_clear; private System.Windows.Forms.NumericUpDown numericUpDown_pen_width_min; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.NumericUpDown numericUpDown_pen_width_max; private System.Windows.Forms.Label label3; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.Panel panel2; } } |
امیدوار و شاد باشید!
خودتان را درگیر اخبار بد فضای مجازی و ... نکنید.
خدا نگهدار