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