SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | * Created by SharpDevelop. | |
3 | * User: fhrl0 | |
4 | * Date: 14/09/2019 | |
5 | * Time: 02:04 p. m. | |
6 | - | * Vertion: 0.2.1 |
6 | + | * Vertion: 0.3.0 |
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers. | |
8 | */ | |
9 | using System; | |
10 | using System.Collections.Generic; | |
11 | using System.Drawing; | |
12 | using System.Windows.Forms; | |
13 | ||
14 | namespace Actividad_2{ | |
15 | /// <summary> | |
16 | /// Description of MainForm. | |
17 | /// </summary> | |
18 | public partial class MainForm : Form{ | |
19 | Bitmap Original,Drawing; | |
20 | public MainForm(){ | |
21 | // | |
22 | // The InitializeComponent() call is required for Windows Forms designer support. | |
23 | // | |
24 | InitializeComponent(); | |
25 | ||
26 | // | |
27 | // TODO: Add constructor code after the InitializeComponent() call. | |
28 | // | |
29 | } | |
30 | int codificador(bool[]arregloBits){//fixed | |
31 | int abstracto=0; | |
32 | for(int i=0;i<arregloBits.Length;i++){ | |
33 | abstracto=abstracto*2; | |
34 | if(arregloBits[i]) | |
35 | abstracto++; | |
36 | }//else es inesesario incrmentar. | |
37 | return abstracto; | |
38 | } | |
39 | bool esNegro(int x,int y){ | |
40 | return(int)Original.GetPixel(x,y).R | |
41 | +(int)Original.GetPixel(x,y).G | |
42 | +(int)Original.GetPixel(x,y).B<(int)383; | |
43 | } | |
44 | void centra(int xInicio,int yInicio,int xFin,int yFin){//163 >> 1 | |
45 | buttonMostrar.Text=yFin.ToString(); | |
46 | Drawing.SetPixel(xInicio,yInicio,Color.Yellow); | |
47 | for(bool[]sentencias={esNegro(xInicio,yInicio),esNegro(xFin,yFin)};true;){ | |
48 | switch(codificador(sentencias)){ | |
49 | case 0:{//00? | |
50 | }return; | |
51 | case 1:{//10? | |
52 | //yFin=yFin+i; | |
53 | }return; | |
54 | case 2:{//01? | |
55 | //yFin=yFin-i; | |
56 | }return; | |
57 | case 3:{//11? | |
58 | //yFin=yFin-i; | |
59 | }return; | |
60 | default:return; | |
61 | }; | |
62 | } | |
63 | } | |
64 | void detecta(int xInicio,int yInicio,int xFin,int yFin){//Drawing.SetPixel(xInicio,yInicio,Color.BlueViolet);//para analisis.//int xCentro=(xInicio+xFin)/2,yCentro=(yInicio+yFin)/2; | |
65 | int xCentro=(xInicio+xFin)/2, | |
66 | yCentro=(yInicio+yFin)/2; | |
67 | - | esNegro((xInicio+xFin)/2,(yInicio+yFin)/2);) |
67 | + | |
68 | esNegro(xInicio,yFin),esNegro(xFin,yFin)}; | |
69 | esNegro(xCentro,yCentro);) | |
70 | switch(codificador(tipoVorde)){ | |
71 | - | int xCentro=(xInicio+xFin)/2; |
71 | + | |
72 | - | //Drawing.SetPixel(xCentro,(yInicio+yFin)/2,Color.OrangeRed); |
72 | + | |
73 | xCentro=(xInicio+xFin)/2; | |
74 | yCentro=(yInicio+yFin)/2; | |
75 | Drawing.SetPixel(xCentro,yCentro,Color.OrangeRed); | |
76 | if(esNegro(xCentro,yInicio-1)){yInicio--; | |
77 | if(esNegro(xCentro,yFin+1)){yFin++; | |
78 | if(esNegro(xInicio-1,yCentro)){xInicio--; | |
79 | if(esNegro(xFin+1,yCentro)){xFin++;}else{} | |
80 | - | Drawing.SetPixel(xCentro,(yInicio+yFin)/2,Color.OrangeRed); |
80 | + | }else{ |
81 | - | //Drawing.SetPixel((xInicio+xFin)/2,yInicio,Color.OrangeRed); |
81 | + | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
82 | - | //Drawing.SetPixel((xInicio+xFin)/2,yFin,Color.OrangeRed); |
82 | + | } |
83 | - | return; |
83 | + | |
84 | if(esNegro(xInicio-1,yCentro)){xInicio--; | |
85 | if(esNegro(xFin+1,yCentro)){xFin++;}else{} | |
86 | - | //buttonMostrar.Text=xInicio.ToString(); |
86 | + | }else{ |
87 | - | //buttonMostrar.BackColor=Color.WhiteSmoke; |
87 | + | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
88 | - | //buttonMostrar.Refresh();System.Threading.Thread.Sleep(200);//xCentro=(xInicio+xFin)/2; |
88 | + | } |
89 | - | //xInicio=(xInicio+xFin)/2; |
89 | + | |
90 | - | //buttonMostrar.Text=xInicio.ToString(); |
90 | + | |
91 | - | //buttonMostrar.BackColor=Color.White; |
91 | + | |
92 | - | //buttonMostrar.Refresh();System.Threading.Thread.Sleep(200); |
92 | + | |
93 | - | /*Drawing.SetPixel(xInicio,yInicio,Color.OrangeRed); |
93 | + | if(esNegro(xInicio-1,yCentro)){xInicio--; |
94 | - | Drawing.SetPixel(xInicio,yFin,Color.OrangeRed); |
94 | + | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
95 | - | Drawing.SetPixel(xFin,yInicio,Color.OrangeRed); |
95 | + | }else{ |
96 | - | Drawing.SetPixel(xFin,yFin,Color.OrangeRed);*/ |
96 | + | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
97 | - | //pictureBoxMuestra.Refresh(); |
97 | + | } |
98 | - | /*if(esNegro(xInicio,yInicio-1)){yInicio--; |
98 | + | |
99 | - | if(esNegro(xInicio,yFin+1))yFin++; |
99 | + | if(esNegro(xInicio-1,yCentro)){xInicio--; |
100 | if(esNegro(xFin+1,yCentro)){xFin++;}else{} | |
101 | - | if(esNegro(xInicio,yFin+1))yFin++; |
101 | + | }else{ |
102 | - | else{ |
102 | + | if(esNegro(xFin+1,yCentro)){xFin++;}else{Drawing.SetPixel(xCentro,yCentro,Color.OrangeRed);return;} |
103 | - | yInicio=(yInicio+yFin)/2; |
103 | + | } |
104 | - | //yCentro=(yInicio+yFin)/2; |
104 | + | |
105 | - | //yInicio=(yInicio+yFin)/2;//no detecto el conflicto de usar yInicio en ves de yCentro,pero funciona con yCentro |
105 | + | |
106 | - | Drawing.SetPixel(xInicio,yInicio,Color.Yellow); |
106 | + | |
107 | - | //Drawing.SetPixel(xInicio,yFin,Color.OrangeRed); |
107 | + | }break;//return; |
108 | - | pictureBoxMuestra.Refresh(); |
108 | + | /*case 2:case 11:{/// L |
109 | - | for(xInicio=(xInicio-xFin)+((yInicio+yFin)/2),yInicio=(yInicio+yFin)/2;0<xInicio&&esNegro(xInicio,yInicio);xInicio--){ |
109 | + | |
110 | - | Drawing.SetPixel(xInicio,yInicio,Color.OrangeRed); |
110 | + | |
111 | - | } |
111 | + | |
112 | - | return; |
112 | + | |
113 | Drawing.SetPixel(x-n,y+n,Color.Blue); | |
114 | return; | |
115 | - | //pictureBoxMuestra.Refresh(); |
115 | + | |
116 | - | /*for(Centro_x=1;!esNegro(xInicio+Centro_x,yInicio)&&(xInicio+Centro_x<Original.Width-1);Centro_x++){ |
116 | + | |
117 | - | Drawing.SetPixel(x+Centro_x,y,Color.DarkMagenta); |
117 | + | |
118 | - | }//int Vertical=0; |
118 | + | |
119 | - | Centro_x/=2;//Drawing.SetPixel(x+Centro_x,y,Color.DarkViolet); |
119 | + | |
120 | - | for(j=0;esNegro(xInicio+Centro_x,yInicio-j);j++)Drawing.SetPixel(x+Centro_x,y+j,Color.DarkRed); |
120 | + | |
121 | - | for(i=0;esNegro(xInicio+Centro_x,yInicio+i);i++)Drawing.SetPixel(x+Centro_x,y-i,Color.DarkRed); |
121 | + | |
122 | - | i=(i+j)/2; |
122 | + | |
123 | - | j=i-j; |
123 | + | |
124 | - | Drawing.SetPixel(xInicio+Centro_x,yInicio+j,Color.White); |
124 | + | |
125 | - | pictureBoxMuestra.Refresh();*/ |
125 | + | |
126 | - | }break;// |
126 | + | |
127 | - | //return; |
127 | + | |
128 | - | /* |
128 | + | |
129 | - | case 2:case 11:{/// L |
129 | + | |
130 | } | |
131 | case 5:{// > | |
132 | Drawing.SetPixel(x,y,Color.Red); | |
133 | /*for(;(esNegro(x+n,y)) | |
134 | &&(x+n<Original.Height);n++) | |
135 | Drawing.SetPixel(x+n,y,Color.Blue); | |
136 | return; | |
137 | } | |
138 | case 4:case 13:{// ¬ | |
139 | Drawing.SetPixel(x,y,Color.Red); | |
140 | for(;esNegro(x+n,y-n) | |
141 | &&((x+n<Original.Height) | |
142 | &&(y-n>=0));n++) | |
143 | Drawing.SetPixel(x+n,y-n,Color.Blue); | |
144 | return; | |
145 | } | |
146 | case 12:{// ^ | |
147 | Drawing.SetPixel(x,y,Color.Red); | |
148 | for(;esNegro(x,y-n) | |
149 | &&(y-n>=0);n++) | |
150 | Drawing.SetPixel(x,y-n,Color.Blue); | |
151 | return; | |
152 | } | |
153 | case 8:case 14:{// F | |
154 | Drawing.SetPixel(x,y,Color.Red); | |
155 | for(n=0;n>9;n++) | |
156 | Drawing.SetPixel(x-n,y-n,Color.Red); | |
157 | for(;esNegro(x-n,y-n) | |
158 | &&((x-n>=0) | |
159 | &&(y-n>=0));n++) | |
160 | Drawing.SetPixel(x-n,y-n,Color.Blue); | |
161 | return; | |
162 | }*/ | |
163 | default:return; | |
164 | //Drawing.SetPixel(x,y,Color.Red); | |
165 | //break;ruido | |
166 | } | |
167 | } | |
168 | void analizar(int xInicio,int yInicio,int xFin,int yFin){//dispose objetos//principio de animacion | |
169 | int xCentro=(xInicio+xFin)/2, | |
170 | yCentro=(yInicio+yFin)/2; | |
171 | detecta(xInicio,yInicio,xFin,yFin); | |
172 | //System.Threading.Thread.Sleep(10); | |
173 | bool[]sentencias={xInicio+2<xFin-2,yInicio+2<yFin-2}; | |
174 | switch(codificador(sentencias)){//enum{}? | |
175 | case 1://01 | |
176 | analizar(xInicio,yInicio,xFin,yCentro-1); | |
177 | analizar(xInicio,yCentro,xFin,yFin); | |
178 | return; | |
179 | case 2://10 | |
180 | analizar(xInicio,yInicio,xCentro-1,yFin);analizar(xCentro,yInicio,xFin,yFin); | |
181 | return; | |
182 | case 3://11 | |
183 | //a por definir descarte | |
184 | analizar(xInicio,yInicio,xCentro-1,yCentro-1);analizar(xCentro,yInicio,xFin,yCentro-1); | |
185 | analizar(xInicio,yCentro,xCentro-1,yFin); analizar(xCentro,yCentro,xFin,yFin); | |
186 | return; | |
187 | default:return;//00 | |
188 | } | |
189 | } | |
190 | void ButtonMostrarClick(object sender, EventArgs e){ | |
191 | if(pictureBoxMuestra.Image==null){ | |
192 | }else{ | |
193 | Original=(Bitmap)pictureBoxMuestra.Image; | |
194 | Drawing=(Bitmap)Original; | |
195 | analizar(0,0,Original.Width-1,Original.Height-1); | |
196 | pictureBoxMuestra.Refresh(); | |
197 | //pictureBoxMuestra.Image=Drawing; | |
198 | } | |
199 | } | |
200 | void ButtonAbrirMouseClick(object sender, MouseEventArgs e){ | |
201 | openFileDialogImagen.ShowDialog(); | |
202 | pictureBoxMuestra.Image=Image.FromFile(openFileDialogImagen.FileName); | |
203 | } | |
204 | } | |
205 | } |