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 | - | * |
6 | + | * Version: 0.2.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 | int i=1; | |
46 | buttonMostrar.Text=yFin.ToString(); | |
47 | Drawing.SetPixel(xInicio,yInicio,Color.Yellow); | |
48 | for(bool[]sentencias={esNegro(xInicio,yInicio),esNegro(xFin,yFin)};true;){ | |
49 | switch(codificador(sentencias)){ | |
50 | case 0:{//00? | |
51 | }return; | |
52 | case 1:{//10? | |
53 | //yFin=yFin+i; | |
54 | }return; | |
55 | case 2:{//01? | |
56 | //yFin=yFin-i; | |
57 | }return; | |
58 | case 3:{//11? | |
59 | //yFin=yFin-i; | |
60 | }return; | |
61 | default:return; | |
62 | }; | |
63 | } | |
64 | } | |
65 | 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; | |
66 | for(bool[]tipoVorde={esNegro(xInicio,yInicio),esNegro(xFin,yInicio), | |
67 | - | esNegro(xInicio,yFin),esNegro(xFin,yFin)};true//esNegro((xInicio+xFin)/2,(yInicio+yFin)/2) |
67 | + | esNegro(xInicio,yFin),esNegro(xFin,yFin)}; |
68 | - | ;) |
68 | + | esNegro((xInicio+xFin)/2,(yInicio+yFin)/2);) |
69 | switch(codificador(tipoVorde)){ | |
70 | case 0:case 15:return;// x <-nombrar_como. | |
71 | - | case 10:{// < // |
71 | + | case 10:{// < |
72 | int xCentro=(xInicio+xFin)/2; | |
73 | //Drawing.SetPixel(xCentro,(yInicio+yFin)/2,Color.OrangeRed); | |
74 | if(esNegro(xCentro,yInicio-1)){yInicio--; | |
75 | - | xInicio=(xInicio+xFin)/2; |
75 | + | if(esNegro(xCentro,yFin+1)){yFin++; |
76 | }else{ | |
77 | } | |
78 | }else{ | |
79 | - | //Drawing.SetPixel(xInicio,yInicio,Color.OrangeRed); |
79 | + | if(esNegro(xCentro,yFin+1)){yFin++; |
80 | - | //Drawing.SetPixel(xInicio,yFin,Color.OrangeRed); |
80 | + | }else{ |
81 | Drawing.SetPixel(xCentro,(yInicio+yFin)/2,Color.OrangeRed); | |
82 | - | if(esNegro(xInicio,yInicio-1)){yInicio--; |
82 | + | //Drawing.SetPixel((xInicio+xFin)/2,yInicio,Color.OrangeRed); |
83 | //Drawing.SetPixel((xInicio+xFin)/2,yFin,Color.OrangeRed); | |
84 | return; | |
85 | } | |
86 | } | |
87 | //buttonMostrar.Text=xInicio.ToString(); | |
88 | //buttonMostrar.BackColor=Color.WhiteSmoke; | |
89 | //buttonMostrar.Refresh();System.Threading.Thread.Sleep(200);//xCentro=(xInicio+xFin)/2; | |
90 | //xInicio=(xInicio+xFin)/2; | |
91 | //buttonMostrar.Text=xInicio.ToString(); | |
92 | //buttonMostrar.BackColor=Color.White; | |
93 | //buttonMostrar.Refresh();System.Threading.Thread.Sleep(200); | |
94 | /*Drawing.SetPixel(xInicio,yInicio,Color.OrangeRed); | |
95 | Drawing.SetPixel(xInicio,yFin,Color.OrangeRed); | |
96 | Drawing.SetPixel(xFin,yInicio,Color.OrangeRed); | |
97 | Drawing.SetPixel(xFin,yFin,Color.OrangeRed);*/ | |
98 | //pictureBoxMuestra.Refresh(); | |
99 | /*if(esNegro(xInicio,yInicio-1)){yInicio--; | |
100 | if(esNegro(xInicio,yFin+1))yFin++; | |
101 | }else{ | |
102 | if(esNegro(xInicio,yFin+1))yFin++; | |
103 | else{ | |
104 | yInicio=(yInicio+yFin)/2; | |
105 | //yCentro=(yInicio+yFin)/2; | |
106 | //yInicio=(yInicio+yFin)/2;//no detecto el conflicto de usar yInicio en ves de yCentro,pero funciona con yCentro | |
107 | Drawing.SetPixel(xInicio,yInicio,Color.Yellow); | |
108 | //Drawing.SetPixel(xInicio,yFin,Color.OrangeRed); | |
109 | pictureBoxMuestra.Refresh(); | |
110 | - | }break;//return; |
110 | + | |
111 | Drawing.SetPixel(xInicio,yInicio,Color.OrangeRed); | |
112 | } | |
113 | return; | |
114 | } | |
115 | }*/ | |
116 | //pictureBoxMuestra.Refresh(); | |
117 | /*for(Centro_x=1;!esNegro(xInicio+Centro_x,yInicio)&&(xInicio+Centro_x<Original.Width-1);Centro_x++){ | |
118 | Drawing.SetPixel(x+Centro_x,y,Color.DarkMagenta); | |
119 | }//int Vertical=0; | |
120 | Centro_x/=2;//Drawing.SetPixel(x+Centro_x,y,Color.DarkViolet); | |
121 | for(j=0;esNegro(xInicio+Centro_x,yInicio-j);j++)Drawing.SetPixel(x+Centro_x,y+j,Color.DarkRed); | |
122 | for(i=0;esNegro(xInicio+Centro_x,yInicio+i);i++)Drawing.SetPixel(x+Centro_x,y-i,Color.DarkRed); | |
123 | i=(i+j)/2; | |
124 | j=i-j; | |
125 | Drawing.SetPixel(xInicio+Centro_x,yInicio+j,Color.White); | |
126 | pictureBoxMuestra.Refresh();*/ | |
127 | }break;// | |
128 | //return; | |
129 | /* | |
130 | case 2:case 11:{/// L | |
131 | Drawing.SetPixel(x,y,Color.Red); | |
132 | for(;esNegro(x-n,y+n) | |
133 | &&(x-n>=0) | |
134 | &&(y+n<Original.Width);n++) | |
135 | Drawing.SetPixel(x-n,y+n,Color.Blue); | |
136 | return; | |
137 | } | |
138 | case 3:{/// v | |
139 | Drawing.SetPixel(x,y,Color.Red); | |
140 | for(;esNegro(x,y+n) | |
141 | &&(y+n<Original.Width);n++) | |
142 | Drawing.SetPixel(x,y+n,Color.Blue); | |
143 | return; | |
144 | } | |
145 | case 1:case 7:{// _| | |
146 | Drawing.SetPixel(x,y,Color.Red); | |
147 | /*for(;esNegro(x+n,y+n) | |
148 | &&(y+n<Original.Width) | |
149 | &&(x+n<Original.Height);n++) | |
150 | Drawing.SetPixel(x+n,y+n,Color.Blue); | |
151 | return; | |
152 | } | |
153 | case 5:{// > | |
154 | Drawing.SetPixel(x,y,Color.Red); | |
155 | /*for(;(esNegro(x+n,y)) | |
156 | &&(x+n<Original.Height);n++) | |
157 | Drawing.SetPixel(x+n,y,Color.Blue); | |
158 | return; | |
159 | } | |
160 | case 4:case 13:{// ¬ | |
161 | Drawing.SetPixel(x,y,Color.Red); | |
162 | for(;esNegro(x+n,y-n) | |
163 | &&((x+n<Original.Height) | |
164 | &&(y-n>=0));n++) | |
165 | Drawing.SetPixel(x+n,y-n,Color.Blue); | |
166 | return; | |
167 | } | |
168 | case 12:{// ^ | |
169 | Drawing.SetPixel(x,y,Color.Red); | |
170 | for(;esNegro(x,y-n) | |
171 | &&(y-n>=0);n++) | |
172 | Drawing.SetPixel(x,y-n,Color.Blue); | |
173 | return; | |
174 | } | |
175 | case 8:case 14:{// F | |
176 | Drawing.SetPixel(x,y,Color.Red); | |
177 | for(n=0;n>9;n++) | |
178 | Drawing.SetPixel(x-n,y-n,Color.Red); | |
179 | for(;esNegro(x-n,y-n) | |
180 | &&((x-n>=0) | |
181 | &&(y-n>=0));n++) | |
182 | Drawing.SetPixel(x-n,y-n,Color.Blue); | |
183 | return; | |
184 | }*/ | |
185 | default:return; | |
186 | //Drawing.SetPixel(x,y,Color.Red); | |
187 | //break;ruido | |
188 | } | |
189 | } | |
190 | void analizar(int xInicio,int yInicio,int xFin,int yFin){//dispose objetos//principio de animacion | |
191 | int xCentro=(xInicio+xFin)/2, | |
192 | yCentro=(yInicio+yFin)/2; | |
193 | detecta(xInicio,yInicio,xFin,yFin); | |
194 | //System.Threading.Thread.Sleep(10); | |
195 | bool[]sentencias={xInicio+2<xFin-2,yInicio+2<yFin-2}; | |
196 | switch(codificador(sentencias)){//enum{}? | |
197 | case 1://01 | |
198 | analizar(xInicio,yInicio,xFin,yCentro-1); | |
199 | analizar(xInicio,yCentro,xFin,yFin); | |
200 | return; | |
201 | case 2://10 | |
202 | analizar(xInicio,yInicio,xCentro-1,yFin);analizar(xCentro,yInicio,xFin,yFin); | |
203 | return; | |
204 | case 3://11 | |
205 | //a por definir descarte | |
206 | analizar(xInicio,yInicio,xCentro-1,yCentro-1);analizar(xCentro,yInicio,xFin,yCentro-1); | |
207 | analizar(xInicio,yCentro,xCentro-1,yFin); analizar(xCentro,yCentro,xFin,yFin); | |
208 | return; | |
209 | default:return;//00 | |
210 | } | |
211 | } | |
212 | void ButtonMostrarClick(object sender, EventArgs e){ | |
213 | if(pictureBoxMuestra.Image==null){ | |
214 | }else{ | |
215 | Original=(Bitmap)pictureBoxMuestra.Image; | |
216 | Drawing=(Bitmap)Original; | |
217 | analizar(0,0,Original.Width-1,Original.Height-1); | |
218 | pictureBoxMuestra.Refresh(); | |
219 | //pictureBoxMuestra.Image=Drawing; | |
220 | } | |
221 | } | |
222 | void ButtonAbrirMouseClick(object sender, MouseEventArgs e){ | |
223 | openFileDialogImagen.ShowDialog(); | |
224 | pictureBoxMuestra.Image=Image.FromFile(openFileDialogImagen.FileName); | |
225 | } | |
226 | } | |
227 | } |