Sunteți pe pagina 1din 173

1.

Ingresar a Microsoft Visual estudio 2012 y realizar un programa en Visual


Basic en modo Consola y realice ejercicios como
1
clic en Microsoft Visual Studio 2008. Ver una pantalla de bienvenida para Visual
Studio 2008,
1. seguido por la pgina de inicio (consulte la figura 2-3).

Combinaciones y permutaciones en c++


Clases y objetos

RELLENO CON AUTOMATAS CELULARES

Module Module1
Dim px As Integer = 2
Dim py As Integer = 2
Dim Cont As Integer
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim resultado As Integer = 0
Sub Main()

IniciarMatriz(Matriz, nf, nc)


linea(px, py, 18, 18)
Matriz(px, py) = relleno
REM RecuperarMatriz(Matriz, nf, nc)
Verpantalla(Matriz, nf, nc)
Console.ReadLine()
Dim cont As Integer = 0
While resultado = 0
REM resultado = crecer(Matriz, nf, nc)
crecer(Matriz, nf, nc)
REM
Sleep(50)
cont = cont + 1
If cont > 20 Then resultado = 1
End While
Verpantalla(Matriz, nf, nc)
REM GrabarMatriz(Matriz, nf, nc)
Console.ReadLine()
End Sub
End Module
CODIGO DEL MODULO 2
Imports System.IO
Module Module2
Public Const maxfilas As Integer = 20
Public camino As Integer = 0
Public relleno As Integer = 1
Public Const maxcol As Integer = 20
Public nf As Integer = maxfilas, nc As Integer = maxcol
Public Matriz(maxfilas, maxfilas) As Integer
Public np As Integer = 4
Public X(maxfilas) As Integer
Public Y(maxfilas) As Integer
Public Sub RecuperarMatriz(ByRef A(,) As Integer, ByVal nf As Integer, ByVal nc
As Integer)
REM Dim srLector = New StreamReader("E:\datos\matriz5x5.txt")
Dim srLector = New StreamReader("E:\datos\matriz20x20a.txt")
Dim cadena As String, subcadena As String
Dim pos As Integer = 0, fila1 As Integer, longitud As String
Dim inicio As Integer = 1, cont As Integer = 0
For fila1 = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1 : cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then

subcadena = Mid(cadena, inicio, pos - inicio)


A(fila1, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila1, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
REM Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 2
Next
Next
End Sub
Sub Verpantalla(ByVal a(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.CursorLeft = col + 1
Console.CursorTop = fila + 1
Console.ForegroundColor = a(fila, col)
Console.Write(a(fila, col))
Next
Next
End Sub
Public Sub linea(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
Dim i As Single, vel As Integer = 10
Dim mayor As Single, ancho As Single, alto As Single, partex As Single,
partey As Single
Dim px As Single, py As Single
Dim dx As Single, dy As Single
ancho = Math.Abs(x2 - x1)
alto = Math.Abs(y2 - y1)
If x1 <= x2 Then
dx = 1
Else

dx = -1
End If
If y1 <= y2 Then
dy = 1
Else
dy = -1
End If
If ancho >= alto Then
mayor = ancho
Else
mayor = alto
End If
partex = ancho / (mayor)
partey = alto / (mayor)
For i = 0 To mayor Step 1
px = i * partex * dx * 1
py = i * partey * dy * 1
Console.CursorLeft = x1 + px
Console.CursorTop = y1 + py
Console.Write(camino)
Matriz(y1 + py, x1 + px) = camino
REM Sleep(vel)
Next
End Sub
Function crecer(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
As Integer
Dim resultado As Integer = 0
Dim fila As Integer, col As Integer, vecinos As Integer
Dim x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer
Dim fila1 As Integer, col1 As Integer
For fila = 1 To nf - 1
For col = 1 To nf - 1
If A(fila, col) <> camino Then Continue For
If (fila > 1) Then
y1 = fila - 1
Else
y1 = fila
End If
If (fila < nf - 1) Then
y2 = fila + 1
Else
y2 = fila
End If
If (col > 1) Then
x1 = col - 1
Else

x1 = col
End If
If (col < nc) Then
x2 = col + 1
Else
x2 = col
End If
vecinos = 0
For fila1 = y1 To y2
For col1 = x1 To x2
If (fila1 = fila And col1 = col) Then Continue For
If A(fila1, col1) = relleno Then vecinos = vecinos + 1
Next
Next
If vecinos > camino And A(fila, col) = camino Then
A(fila, col) = relleno
resultado = 1
End If
Next
Next
End Function
Sub GrabarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim swEscritor = New StreamWriter("e:\DATOS\matriz20X20A.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Sub TransferirMatriz(ByVal Matriz(,) As Integer, ByVal m1(,) As Integer, ByVal nf
As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 1 To nf
For col = 1 To nc
m1(fila, col) = Matriz(fila, col)
Next
Next
End Sub
End Module
46 Programa de automatas celulares para obtener figuras

Imports System.IO
Module Module1
Dim swEscritor As StreamWriter
Sub main()
cont = 0
RecuperarMatriz("e:\datos\matriz10x10.txt", A, nfilas, ncol)
MostrarMatriz(1, 1, A, nfilas, ncol)
proceso()
Console.ReadLine()
End Sub
Sub EncontrarPuntoOrigen(ByRef pxo As Integer, ByRef pyo As Integer, ByVal
camino As Integer)
Dim encontrado As Integer = 0
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
If A(fila, col) = camino Then
pxo = col
pyo = fila
encontrado = 1
Exit For
End If
If encontrado = 1 Then Exit For
Next
Next
End Sub
Sub proceso()
pmx = 1
pmy = 1
'EncontrarPuntoOrigen(pxo, pyo, camino)
pxo = 6

pyo = 4
InicializarObjeto(pxo, pyo, Objeto1)
final = 0
MostrarMatriz(pmx, pmy, A, nf, nc)
MostrarObjeto(pmx, pmy, Objeto1)
NroObjeto = 0
Objetos(NroObjeto) = Objeto1
Objetos2(cont) = Objeto1
A(Objeto1.Cy, Objeto1.Cx) = huella
Do
Do
MostrarMatriz(pmx, pmy, A, nf, nc)
MostrarObjeto(pmx, pmy, Objeto1)
resultado = evaluar(Objeto1, A, camino, meta)
If resultado = 1 Then
GoTo fin
procesar = 0
End If
dir = Objeto1.Direc
Select Case dir
Case 1 : Objeto1.Cx = Objeto1.Cx + 1
Case 2 : Objeto1.Cy = Objeto1.Cy - 1
Case 3 : Objeto1.Cx = Objeto1.Cx - 1
Case 4 : Objeto1.Cy = Objeto1.Cy + 1
Case Else : terminado = 1
End Select
A(Objeto1.Cy, Objeto1.Cx) = huella
NroObjeto = NroObjeto + 1
cont = cont + 1
Objeto1.nro = NroObjeto
Objetos(NroObjeto) = Objeto1
Objetos2(cont) = Objeto1
Loop While terminado = 0
terminado = 0
Do
Objeto1 = Objetos(NroObjeto)
MostrarMatriz(pmx, pmy, A, nf, nc)
MostrarObjeto(pmx, pmy, Objeto1)
resultado = evaluar(Objeto1, A, camino, meta)
dir = Objeto1.Direc
If (NroObjeto < 0) Then GoTo fin
If dir > 0 Then
terminado = 1
Else
A(Objeto1.Cy, Objeto1.Cx) = retorno
NroObjeto = NroObjeto - 1

If (NroObjeto < 0) Then GoTo fin


cont = cont + 1
'Sleep(10)
End If
Loop While terminado = 0
If NroObjeto < 0 Then final = 1
Loop While final = 0
MostrarObjeto(pmx, pmy, Objeto1)
fin:
Console.SetCursorPosition(2, 22)
If NroObjeto > 0 Then
Console.WriteLine("ENCONTRADO X={0} Y = {1} Mov ={2} ",
Objetos(NroObjeto).Cx, Objetos(NroObjeto).Cy, cont)
Else
Console.WriteLine(" no se encontro la meta y se hizo {0} Movimientos ",
cont)
End If
' grabar la matriz de movimientos
swEscritor = New StreamWriter("E:\DATOS\puntosbuscados.txt")
For i = 0 To cont - 1
With Objetos2(i)
swEscritor.WriteLine("{0}{1}{2}{3}{4}{5}{6} {7}{8} {9}{10} {11}{12}{13}{14}
{15}{16} {17} {18}", _
.nro, Chr(9), .dir1, Chr(9), .dir2, Chr(9), .dir3, Chr(9), .dir4,
Chr(9), .Cx, _
Chr(9), .Cy, Chr(9), .np, Chr(9), .Valor, Chr(9), .Direc)
End With
Next
swEscritor.Close()
' Obtener la matriz final
cont2 = 1
Vx(0) = Objetos2(0).Cx
Vy(0) = Objetos2(0).Cy
Vdir(0) = Objetos2(0).Direc
For i = 1 To cont - 1
If Objetos2(i).dir1 = 0 And Objetos2(i).dir2 = 0 And Objetos2(i).dir3 = 0 And
Objetos2(i).dir4 = 0 Then
Continue For
Else
Vx(cont2) = Objetos2(i).Cx
Vy(cont2) = Objetos2(i).Cy
Vdir(cont2) = Objetos2(i).Direc
cont2 = cont2 + 1
End If
Next
Console.WriteLine(" Archivo puntos buscados grabados cont2 {0} ", cont2)
swEscritor = New StreamWriter("E:\DATOS\puntosfinales.txt")

For i = 0 To cont2 - 1
swEscritor.WriteLine("{0}{1}{2}{3}{4}", Vx(i), Chr(9), Vy(i), Chr(9), Vdir(i))
Next
swEscritor.Close()
Console.WriteLine(" Archivo puntos finales grabados ")
reconstruir(Vx, Vy, Vdir, cont2, B)
MostrarMatriz(40, 1, B, nf, nc)
procesar = 0
End Sub
Sub reconstruir(ByVal vx() As Integer, ByVal vy As Integer(), ByVal vdir() As
Integer, ByVal ne As Integer, ByRef B(,) As Integer)
For i = 0 To ne - 1
B(vy(i), vx(i)) = camino
Next
End Sub
End Module
Imports System.IO
Module Module2
Public cont2 As Integer = 0 ' para contar los puntos finales
Public pxo As Integer ' posicion x del objeto
Public pyo As Integer ' posicion y del objeto
Public pmx As Integer ' posicion x de la matriz
Public pmy As Integer ' posicion y de la matriz
Public A(nfilas, ncol) As Integer
Public B(nfilas, ncol) As Integer
Public px1 As Integer
Public py1 As Integer
Public camino As Integer = 9, terminado As Integer = 0, retorno As Integer = 5,
huella = 4
Public meta As Integer = 7, resultado As Integer = 0, dir As Integer = 0
Public mxo As Integer = 9, myo As Integer = 9, mzo As Integer = 0
Public valor As Integer = 0, final As Integer = 0, cont As Integer = 0, NroObjeto
As Integer = 0
Public procesar As Integer = 0 ' al principio no procesa
Public Const nfilas As Integer = 10, ncol As Integer = 10
Public srLector As StreamReader
Public nf As Integer = 10 ' 20
Public nc As Integer = 10 '20
Public Objetos(200) As Buscador
Public Objetos2(200) As Buscador
Public Vx(100) As Integer
Public Vy(100) As Integer
Public Vdir(100) As Integer

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


REM ***
Public Structure Buscador
Public nro As Integer
Public dir1 As Integer, dir2 As Integer, dir3 As Integer, dir4 As Integer '
declarar matrices de 4
Public Cx As Integer
Public Cy As Integer
Public np As Integer
Public Valor As Integer ' Es el valor del objeto
Public Color As Integer ' Es el color del objeto
Public Direc As Integer
End Structure
Public Objeto1 As Buscador
Function obtenerDir(ByVal d1 As Integer, ByVal d2 As Integer, ByVal d3 As
Integer, ByVal d4 As Integer) As Integer
If d1 = 1 Then Return 1
If d2 = 1 Then Return 2
If d3 = 1 Then Return 3
If d4 = 1 Then Return 4
obtenerDir = 0
End Function
Function evaluar(ByRef objeto1 As Buscador, ByVal Matriz(,) As Integer, ByVal
camino As Integer, ByVal meta As Integer) As Integer
Dim cont As Integer = 0, Cx As Integer, Cy As Integer, Direc As Integer = 0
Dim resultado As Integer = 0
objeto1.dir1 = 0
objeto1.dir2 = 0
objeto1.dir3 = 0
objeto1.dir4 = 0
Cx = objeto1.Cx
Cy = objeto1.Cy
' primero evalua si ya encontro la metas
If Matriz(Cy, Cx + 1) = meta Then
objeto1.dir1 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
If Matriz(Cy - 1, Cx) = meta Then
objeto1.dir2 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
If Matriz(Cy, Cx - 1) = meta Then
objeto1.dir3 = 1

cont = cont + 1
evaluar = 1
Exit Function
End If
If Matriz(Cy + 1, Cx) = meta Then
objeto1.dir4 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
'// si no encuentra meta evalua si hay camino
If Matriz(Cy, Cx + 1) = camino Then
objeto1.dir1 = 1
cont = cont + 1
End If
If Matriz(Cy - 1, Cx) = camino Then
objeto1.dir2 = 1
cont = cont + 1
End If
If Matriz(Cy, Cx - 1) = camino Then
objeto1.dir3 = 1
cont = cont + 1
End If
If Matriz(Cy + 1, Cx) = camino Then
objeto1.dir4 = 1
cont = cont + 1
End If
objeto1.np = cont
Direc = obtenerDir(objeto1.dir1, objeto1.dir2, objeto1.dir3, objeto1.dir4)
objeto1.Direc = Direc
evaluar = 0
End Function
Sub InicializarObjeto(ByVal Cx As Integer, ByVal cy As Integer, ByRef Objeto1
As Buscador)
Objeto1.Cx = pxo
Objeto1.Cy = pyo
Objeto1.Valor = 9
Objeto1.Color = 9
Objeto1.dir1 = 0
Objeto1.dir2 = 0
Objeto1.dir3 = 0
Objeto1.dir4 = 0
Objeto1.np = 0
Objeto1.nro = 0
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByVal A(,) As Integer,
ByVal nf As Integer, ByVal nc As Integer)

srLector = New StreamReader(nombrearchivo)


Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
Next
srLector.Close()
End Sub
Sub MostrarObjeto(ByVal pmx As Integer, ByVal pmy As Integer, ByVal objeto1
As Buscador)
Console.ForegroundColor = objeto1.Color
Console.CursorLeft = pmx + objeto1.Cx
Console.CursorTop = pmy + objeto1.Cy
Console.Write("{0}", objeto1.Valor)
End Sub
Sub MostrarMatriz(ByVal cx As Integer, ByVal cy As Integer, ByVal B(,) As
Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
Console.CursorLeft = cx + col
Console.CursorTop = cy + fila
Console.ForegroundColor = B(fila, col)
Console.Write("{0} ", Hex(B(fila, col)))
Next
Next
End Sub
End Module

NOTA. En el mismo proceso usar recursividad y solo las direcciones


Sub reconstruir(ByVal vx() As Integer, ByVal vy As Integer(), ByVal vdir() As
Integer, ByVal ne As Integer, ByRef B(,) As Integer)
px1 = vx(0)

py1 = vy(0)
B(py1, px1) = camino
For i = 1 To ne - 1
Select Case vdir(i)
Case 1 : px1 = px1 + 1
Case 2 : py1 = py1 - 1
Case 3 : px1 = px1 - 1
Case 4 : py1 = py1 + 1
End Select
B(py1, px1) = camino
Next
End Sub
Sabiendo que el primer punto encontrado es la coorddenda 0 0 convertirlo las
coordenadas en relativas a ese punto
Para ello lo nico es restarlo a cada coordendas la primera coordenda
encontradas
Pregunta 3
Reconstruir la figura pero en otra coordenada que se desea
Ejemplo
Elorigen esta en 4 ,2 ahora quiero que el origen este en 3,3 y quiero que este en
5,2 entonces a cada elemento debo sumarlo
Pxnuevo=px1+dif(px2-px1)
Pynuevo=py1+dif(py2-py1)
O sino se aplica trsalacion a la nueva matriz
Se puede aplicar tambin rotacin y escalado
Pregunta 4
Obtener la fgura y mover en la misma matriz de izqueirda a derecha
Se copia los valores de la obtenidos de nuevo en la matriz
Osea
reconstruir(Vx, Vy, Vdir, cont2, A)
MostrarMatriz(40, 1, A, nf, nc)
Pregunta 4
Mover en la pantalla el vector obtenido

' para mover lo capturado usando una matrizadicional


While (1)
For i = 1 To 40
MostrarMatriz(i, 1, B, nf, nc)
System.Threading.Thread.Sleep(10) ' 1 segundo
Next
End While
' para mover lo capturado usando la misma matriz
' para mover lo capturado
While (1)
For i = 1 To 3
reconstruir(Vx, Vy, Vdir, cont2, B, i, 1)
MostrarMatriz(i, 1, A, nf, nc)
System.Threading.Thread.Sleep(10) ' 1 segundo
Next
End While
End Sub
Sub reconstruir(ByVal vx() As Integer, ByVal vy As Integer(), ByVal vdir() As
Integer, ByVal ne As Integer, ByRef B(,) As Integer, _
ByVal dx As Integer, ByVal dy As Integer)

For i = 0 To ne - 1
B(vy(i) + dy, vx(i) + dx) = camino
Next
End Sub
Escogemos varias figuras
Se puede de acuerdo a su color
DETERMINAR COcrucN automatas celulares si hay cruce o no

Imports System.IO
Module Module2
Public px1 As Integer = 0
Public py1 As Integer = 0
Public px2 As Integer = 0
Public py2 As Integer = 0
Public px3 As Integer = 0
Public py3 As Integer = 0
Public px4 As Integer = 0
Public py4 As Integer = 0
Public px5 As Integer = 0
Public py5 As Integer = 0
Public Const maxcol As Integer = 30
Public Const maxfilas As Integer = 30
Public color1 As Integer = 10
Public color2 As Integer = 12
Public color3 As Integer = 14

Public np As Integer = 3
Dim srLector As StreamReader
Public Matriz(maxfilas, maxcol) As Integer
Public vector(8) As Integer
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine("{0} {1} ", fila, X(fila))
Next
End Sub
Sub MostrarMatriz(ByVal Cx As Integer, ByVal Cy As Integer, ByVal A(,) As
Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
Console.ForegroundColor = A(fila, col)
Console.SetCursorPosition(Cx + col, Cy + fila)
Console.Write("{0}", Hex(A(fila, col)))
Next col
Next fila
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nfilas As Integer, ByVal ncol As
Integer, ByVal nro As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
A(fila, col) = nro
Next
Next
End Sub
Sub linea(ByRef matriz(,) As Integer, ByVal x1 As Single, ByVal y1 As Single,
ByVal x2 As Single, ByVal y2 As Single, ByVal nro As Integer)
Dim i As Single, vel As Integer = 10
Dim mayor As Single, ancho As Single, alto As Single, partex As Single,
partey As Single
Dim px As Single, py As Single
Dim dx As Single, dy As Single
ancho = Math.Abs(x2 - x1)
alto = Math.Abs(y2 - y1)
If x1 <= x2 Then
dx = 1
Else
dx = -1

End If
If y1 <= y2 Then
dy = 1
Else
dy = -1
End If
If ancho >= alto Then
mayor = ancho
Else
mayor = alto
End If
partex = ancho / (mayor)
partey = alto / (mayor)
For i = 0 To mayor Step 1
px = i * partex * dx * 1
py = i * partey * dy * 1
matriz(y1 + py, x1 + px) = nro
REM Sleep(vel)
Next
End Sub
Function haycruce(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As
Integer, ByVal y2 As Integer, _
ByVal x3 As Integer, ByVal y3 As Integer, ByVal x4 As Integer, ByVal
y4 As Integer, _
ByVal color1 As Integer, ByVal color2 As Integer) As Integer
Dim cont As Integer = 0
Dim resultado As Integer = 0
Dim vacio As Integer = 0
Dim fila1 As Integer
Dim col1 As Integer
Dim encontrado1 As Integer = 0
Dim encontrado2 As Integer = 0
IniciarMatriz(Matriz, maxfilas, maxcol, 1)
linea(Matriz, px1, py1, px2, py2, color1)
linea(Matriz, px3, py3, px4, py4, color2)
linea(Matriz, px3 + 1, py3, px4 + 1, py4, color2)
linea(Matriz, px3, py3 + 1, px4, py4 + 1, color2)
MostrarMatriz(1, 1, Matriz, maxfilas, maxcol)
' encontrar donde hay color1 el primero
encontrado1 = 0
For fila = 0 To maxfilas - 1
For col = 0 To maxcol - 1
If Matriz(fila, col) = color1 Then

px5 = col
py5 = fila
encontrado1 = 1
End If
Next
Next
If encontrado1 = 0 Then Return 0 ' noy hay cruce
' usando automata celulares sigue la linea
vacio = 0
While vacio = 0
Matriz(py5, px5) = color3
MostrarMatriz(40, 1, Matriz, maxfilas, maxcol)
encontrado2 = 0
For fila1 = py5 - 1 To py5 + 1
For col1 = px5 - 1 To px5 + 1
If Matriz(fila1, col1) = color1 Then
px5 = col1
py5 = fila1
encontrado2 = 1
Exit For
End If
If encontrado2 = 1 Then Exit For
Next
Next
If encontrado2 = 0 Then vacio = 1
'
MostrarMatriz(30, 1, Matriz, maxfilas, maxcol)
End While
MostrarMatriz(40, 1, Matriz, maxfilas, maxcol)
' evalua si quedan valores
cont = 0
For fila = 0 To maxfilas - 1
For col = 0 To maxcol - 1
If Matriz(fila, col) = color1 Then
cont += 1
End If
Next
Next
If cont > 0 Then
Return 1
Else
Return 0
End If
End Function

End Module
Module Module1
Sub Main()
Dim resultado As Integer = 0
px1 = 6
py1 = 2
px2 = 6
py2 = 8
px3 = 2
py3 = 5
px4 = 10
py4 = 5

resultado = haycruce(px1, py1, px2, py2, px3, py3, px4, py4, color1, color2)
Console.SetCursorPosition(1, 23)
If resultado = 1 Then
Console.WriteLine(" HAY CRUCE")
Else
Console.WriteLine(" no hay cruce")
End If
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module2
Public trifinal(maxcol, 2) As Integer
Public copiapx5 As Integer = 0
Public copiapy5 As Integer = 0
Public px1 As Integer = 0
Public py1 As Integer = 0
Public px2 As Integer = 0
Public py2 As Integer = 0
Public px3 As Integer = 0
Public py3 As Integer = 0
Public px4 As Integer = 0
Public py4 As Integer = 0
Public px5 As Integer = 0
Public py5 As Integer = 0
Public Const maxcol As Integer = 50
Public Const maxfilas As Integer = 40
Public color1 As Integer = 10
Public color2 As Integer = 12
Public color3 As Integer = 14
'*****
Public Origen(maximo) As Integer
Public destino(maximo) As Integer
Public OrigenFinal(maximo) As Integer
Public Destinofinal(maximo) As Integer

Public Matriz(maxfilas, maxcol) As Integer


Public cx As Integer = 1
Public cy As Integer = 1
Public vdistancias(maximo) As Single
Public Const maximo As Integer = 100
Public ndist As Integer = 0
Public ntri As Integer = 0
Public cont As Integer = 0
Public nvecinos As Integer = 0
Public nvecinos1 As Integer = 0
Public TRI(maximo, 2) As Integer
Public vectorvecinos(maximo) As Integer
Public VectorRelaciones(maximo) As Integer
Public Ncol As Integer = maxcol
Public Nfilas As Integer = maxfilas
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim srLector As StreamReader
Dim swEscritor As StreamWriter
Public maxpuntos = 50
Public relleno(maxpuntos) As Integer
Public nf As Integer = maxfilas, nc As Integer = maxcol
Public VX(maxpuntos) As Single
Public VY(maxpuntos) As Single
Public VZ(maxpuntos) As Single
Public MatrizPuntos(maxfilas, 3) As Single
Public np As Integer = 6, k As Integer
'***********
Sub MatrizXYZ(ByVal A(,) As Single, ByVal nf As Integer, ByRef X() As Single,
ByRef Y() As Single, ByRef Z() As Single)
For fila = 0 To nf - 1
X(fila) = A(fila, 0)
Y(fila) = A(fila, 1)
Z(fila) = A(fila, 2)
Next
End Sub
Sub RecuperarArchivo(ByVal nombrearchivo As String, ByVal A(,) As Single,
ByVal nf As Integer, ByVal nc As Integer)
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)

inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub imprimirVectores(ByVal X() As Single, ByVal Y() As Single, ByVal ne As
Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine("{0} {1} ", X(fila), Y(fila))
Next
End Sub
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.Write("{0} ", X(fila))
Next
End Sub
Sub MostrarMatriz(ByVal Cx As Integer, ByVal Cy As Integer, ByVal A(,) As
Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
Console.ForegroundColor = A(fila, col)
Console.SetCursorPosition(Cx + col, Cy + fila)
Console.Write("{0}", Hex(A(fila, col)))
' Console.Write("{0}", A(fila, col))
Next col
Next fila
End Sub
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single) As Single
Return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
End Function

Sub OrdenarDistancias(ByRef Origen() As Integer, ByRef Destino() As Integer,


ByRef distancia() As Single, ByVal np As Integer)
Dim fila As Integer
Dim col As Integer
Dim tempOrigen As Single
Dim tempDestino As Single
Dim tempDist As Single
For fila = 0 To np - 2
For col = fila + 1 To np - 1
If (distancia(col) < distancia(fila)) Then
tempOrigen = Origen(fila)
tempDestino = Destino(fila)
tempDist = distancia(fila)
Origen(fila) = Origen(col)
Destino(fila) = Destino(col)
distancia(fila) = distancia(col)
Origen(col) = tempOrigen
Destino(col) = tempDestino
distancia(col) = tempDist
End If
Next col
Next fila
End Sub
Sub linea(ByRef matriz(,) As Integer, ByVal x1 As Single, ByVal y1 As Single,
ByVal x2 As Single, ByVal y2 As Single, ByVal nro As Integer)
Dim i As Single, vel As Integer = 10
Dim mayor As Single, ancho As Single, alto As Single, partex As Single,
partey As Single
Dim px As Single, py As Single
Dim dx As Single, dy As Single
ancho = Math.Abs(x2 - x1)
alto = Math.Abs(y2 - y1)
If x1 <= x2 Then
dx = 1
Else
dx = -1
End If
If y1 <= y2 Then
dy = 1
Else
dy = -1
End If

If ancho >= alto Then


mayor = ancho
Else
mayor = alto
End If
partex = ancho / (mayor)
partey = alto / (mayor)
For i = 0 To mayor Step 1
px = i * partex * dx * 1
py = i * partey * dy * 1
matriz(Int(y1 + py), Int(x1 + px)) = nro
REM Sleep(vel)
Next
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nfilas As Integer, ByVal ncol As
Integer, ByVal nro As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
A(fila, col) = nro
Next
Next
End Sub
Function haycruce(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As
Integer, ByVal y2 As Integer, _
ByVal x3 As Integer, ByVal y3 As Integer, ByVal x4 As Integer, ByVal
y4 As Integer, _
ByVal color1 As Integer, ByVal color2 As Integer) As Integer
Dim cont As Integer = 0
Dim resultado As Integer = 0
Dim vacio As Integer = 0
Dim fila1 As Integer
Dim col1 As Integer
Dim encontrado1 As Integer = 0
Dim encontrado2 As Integer = 0
Dim lix As Integer
Dim lsx As Integer
Dim liy As Integer
Dim lsy As Integer
IniciarMatriz(Matriz, maxfilas, maxcol, 1)

linea(Matriz, px1, py1, px2, py2, color1)


linea(Matriz, px3, py3, px4, py4, color2)
linea(Matriz, px3 + 1, py3, px4 + 1, py4, color2)
linea(Matriz, px3, py3 + 1, px4, py4 + 1, color2)
' MostrarMatriz(1, 1, Matriz, maxfilas, maxcol)
' encontrar donde hay color1 el primero
encontrado1 = 0
For fila = 0 To maxfilas - 1
For col = 0 To maxcol - 1
If Matriz(fila, col) = color1 Then
px5 = col
py5 = fila
encontrado1 = 1
Exit For
End If
If encontrado1 = 1 Then Exit For
Next
Next
If encontrado1 = 0 Then Return 0 ' noy hay cruce
' usando automata celulares sigue la linea
' case primera vez
vacio = 0
copiapx5 = px5
copiapy5 = py5
cont = 0
While vacio = 0
' caso primera vez
cont += 1
Matriz(py5, px5) = color3
' MostrarMatriz(1, 1, Matriz, maxfilas, maxcol)
encontrado2 = 0
lix = px5 - 1
lsx = px5 + 1
liy = py5 - 1
lsy = py5 + 1
For fila1 = liy To lsy
For col1 = lix To lsx
If (fila1 = py5 And col1 = px5) Then Continue For
If Matriz(fila1, col1) = color1 Then
px5 = col1
py5 = fila1
encontrado2 = 1
Exit For
End If
If encontrado2 = 1 Then Exit For
Next

Next
If encontrado2 = 0 Then vacio = 1
End While
' Matriz(py5, px5) = color1
'caso seconda vezz
vacio = 0
px5 = copiapx5
py5 = copiapy5
While vacio = 0
' caso segunda vez
Matriz(py5, px5) = color3
' MostrarMatriz(1, 1, Matriz, maxfilas, maxcol)
encontrado2 = 0
lix = px5 - 1
lsx = px5 + 1
liy = py5 - 1
lsy = py5 + 1
For fila1 = liy To lsy
For col1 = lix To lsx
If (fila1 = py5 And col1 = px5) Then Continue For
If Matriz(fila1, col1) = color1 Then
px5 = col1
py5 = fila1
encontrado2 = 1
Exit For
End If
If encontrado2 = 1 Then Exit For
Next
Next
If encontrado2 = 0 Then vacio = 1
End While
' MostrarMatriz(40, 1, Matriz, maxfilas, maxcol)
' evalua si quedan valores
cont = 0
For fila = 0 To maxfilas - 1
For col = 0 To maxcol - 1
If Matriz(fila, col) = color1 Then
cont += 1
End If
Next
Next
If cont > 0 Then
Return 1

Else
Return 0
End If
End Function
Sub procesoTriangulacion()
Dim t1 As Integer
Dim t2 As Integer
Dim t3 As Integer
Dim t4 As Integer
Dim resultado1 As Integer
Dim factible As Integer = 1
Dim cont1 As Integer = 0
Dim cont2 As Integer = 0
Dim vectortri(10) As Integer
Dim dist As Integer
RecuperarArchivo("e:\datos\puntos3x6.txt", MatrizPuntos, np, 3)
MatrizXYZ(MatrizPuntos, np, VX, VY, VZ)
imprimirVectores(VX, VY, np)
IniciarMatriz(Matriz, nf, nc, 1)
cont = 0
ntri = 0
' obtenemos todas las aritas
For fila = 0 To np - 1
For col = fila + 1 To np - 1
px1 = VX(fila)
py1 = VY(fila)
px2 = VX(col)
py2 = VY(col)
Origen(cont) = fila
destino(cont) = col
dist = distancia(px1, py1, px2, py2)
vdistancias(cont) = dist
Console.WriteLine(" {0} {1} {2} {3}", cont, fila, col, dist)
cont += 1
Next
Next
ntri = cont
' ** ordenamos de acuerdo a distancia
OrdenarDistancias(Origen, destino, vdistancias, ntri)
Console.WriteLine(" ordenado de acuerdo a distancia")
For fila = 0 To ntri - 1
Console.WriteLine(" {0} {1} {2} {3}", fila, Origen(fila), destino(fila),
vdistancias(fila))
Next

' Adjuntar ver los aristas que no se cruzan


Console.WriteLine("**** RESULTADOS FINALES **")
cont = 0
For fila = 0 To ntri - 1
t1 = Origen(fila)
t2 = destino(fila)
factible = 1
For col = 0 To cont - 1
t3 = OrigenFinal(col)
t4 = Destinofinal(col)
px1 = VX(t1)
py1 = VY(t1)
px2 = VX(t2)
py2 = VY(t2)
px3 = VX(t3)
py3 = VY(t3)
px4 = VX(t4)
py4 = VY(t4)
'Console.WriteLine("{0} {1} {2} {3} {4}", fila, col, t1, t2, t3, t4)
resultado1 = haycruce(px1, py1, px2, py2, px3, py3, px4, py4, color1,
color2)
If resultado1 = 1 Then
factible = 0
Exit For
End If
Next
' si es factible adjuntar
If factible = 1 Then
OrigenFinal(cont) = t1
Destinofinal(cont) = t2
cont += 1
End If
Next
Dim resultado As Integer = 0
Console.WriteLine("** resultados finales ********2 ")
'' ver todas las combinaciones
ntri = cont
For fila = 0 To ntri - 1
Console.WriteLine(" {0} {1} {2} ", cont, OrigenFinal(fila), Destinofinal(fila))
Next
cont = 0
cont1 = 0
For t1 = 0 To np - 2
For t2 = t1 + 1 To np - 1
For t3 = t2 + 1 To np - 1
Console.WriteLine(" {0} {1} {2} {3} ", cont, t1, t2, t3)

resultado = EvaluarTriangulo(OrigenFinal, Destinofinal, t1, t2, t3, ntri)


If resultado = 1 Then
trifinal(cont, 0) = t1
trifinal(cont, 1) = t2
trifinal(cont, 2) = t3
cont += 1
End If
cont1 += 1
Next
Next
Next
ntri = cont
Console.WriteLine("TRIANGULOS FINALES***3 ")
For fila = 0 To ntri - 1
Console.WriteLine("{0} {1} {2} {3} ", fila, trifinal(fila, 0), trifinal(fila, 1),
trifinal(fila, 2))
Next
Console.ReadLine()
ntri = cont
'' *** imprimir las lineas finales
Console.ForegroundColor = 13
IniciarMatriz(Matriz, maxfilas, maxcol, 1)
For fila = 0 To ntri - 1
t1 = trifinal(fila, 0)
t2 = trifinal(fila, 1)
t3 = trifinal(fila, 2)
px1 = VX(t1)
py1 = VY(t1)
px2 = VX(t2)
py2 = VY(t2)
px3 = VX(t3)
py3 = VY(t3)
linea(Matriz, px1, py1, px2, py2, 10)
linea(Matriz, px2, py2, px3, py3, 10)
linea(Matriz, px3, py3, px1, py1, 10)
Next
MostrarMatriz(1, 1, Matriz, maxfilas, maxcol)
Console.ForegroundColor = 15 ' '''''''''''
For fila = 0 To np - 1
Console.SetCursorPosition(VX(fila), VY(fila))
Console.Write("{0}", fila)
Next
Console.ReadLine()

End Sub
End Module
Imports System.IO
Module Module1
Sub Main()
procesoTriangulacion()
Console.ReadLine()
End Sub
Function EvaluarTriangulo(ByVal torig() As Integer, ByVal tdes() As Integer,
ByVal t1 As Integer, ByVal t2 As Integer, ByVal t3 As Integer, ByVal ntri As Integer)
As Integer
Dim r1 As Integer = 0
Dim r2 As Integer = 0
Dim r3 As Integer = 0
Dim resultado As Integer = 0
For fila = 0 To ntri - 1
If t1 = torig(fila) And t2 = tdes(fila) Then
r1 = 1
Exit For
End If
Next
If r1 = 1 Then
For fila = 0 To ntri - 1
If t2 = torig(fila) And t3 = tdes(fila) Then
r2 = 1
Exit For
End If
Next
End If
If r2 = 1 Then
For fila = 0 To ntri - 1
If t3 = torig(fila) And t1 = tdes(fila) Or t1 = torig(fila) And t3 = tdes(fila)
Then
r3 = 1
Exit For
End If
Next
End If
If r1 = 1 And r2 = 1 And r3 = 1 Then

Module Module1
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim MTrazos(Np, Np) As Integer
Sub Main()
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim p1 As Integer
Dim p2 As Integer
Dim B(50) As Integer
Dim nsr As Integer = 0
Dim fila As Integer
For fila = 0 To Np - 1
relleno(fila) = fila + 1
Next
recuperarPuntos(X, Y, Np)
imprimir(X, Y, Np)
IniciarMatriz(MRel, Np, Np)
EscribirEnMatriz(X, Y, Np, Matriz)
VerMatriz(Matriz, nf, nc, 1, 1)
REM al crecer obtien cuales son sus vecinos
For r = 1 To 20
crecerCirculo(Matriz, X, Y, nf, nc, relleno, r, Np)
VerMatriz(Matriz, nf, nc, 1, 1)
Next

Console.ForegroundColor = 15
For k = 0 To Np - 1
Console.CursorLeft = X(k)
Console.CursorTop = Y(k)
Console.Write("{0}", k)
Next
For fila = 0 To Np - 1
trazo(0) = fila + 1
cont = 1
crecer(Y(fila), X(fila), 0, relleno(fila))
REM VerMatriz(Matriz, nf, nc, 1, 1)
npuntos = cont
quitarRepetidos(trazo, B, npuntos, nsr)
Restar(B, nsr)
AsignarMatriz(MRel, B, nsr, fila)
Next
Console.ForegroundColor = 15
Console.CursorLeft = 1
Console.CursorTop = 24
ImprimirMatriz(MRel, Np, Np)
Console.ReadLine()
' graficar
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)
y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else
linea(x1, y1, x2, y2)
End If
End If
Next
Next
Console.ForegroundColor = 14
For k = 0 To Np - 1
Console.CursorLeft = X(k)
Console.CursorTop = Y(k)
Console.Write("{0}", k)
Next
Console.ReadLine()
End Sub

End Module
Imports System.IO
Module module2
Public cx As Integer = 1, cy As Integer = 1
Public cont As Integer
Public npuntos As Integer
Public Matriz(NFilas, NCol) As Integer
Const NFilas As Integer = 24, NCol As Integer = 70
Public Np As Integer = 5
Public relleno(Np) As Integer
Public camino As Integer = 0
Public X(Np) As Integer
Public Y(Np) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public trazo(500) As Integer
Public MRel(Np, Np) As Integer
REM Public nt As Integer
Public espacio As Integer = 0
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = -1
Next
Next
End Sub
Sub ImprimirMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
Console.WriteLine()
For col = 0 To nc - 1
If A(fila, col) >= 0 Then
Console.Write("{0} ", A(fila, col))
End If
Next
Next
End Sub
Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
ByVal cx As Integer, ByVal cy As Integer)
Dim fila As Integer, col As Integer
Dim valor As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1

Console.CursorLeft = cx + col
Console.CursorTop = cy + fila
valor = A(fila, col)
Console.ForegroundColor = A(fila, col)
Console.Write("{0}", Hex(A(fila, col)))
Next
Next
End Sub
Sub crecerCirculo(ByVal A(,) As Integer, ByVal X() As Integer, ByVal Y() As
Integer, ByVal nf As Integer, _
ByVal nc As Integer, ByVal relleno() As Integer, ByVal r As Single,
ByVal np As Integer)
Dim x1 As Integer, y1 As Integer, k As Integer
For k = 0 To np - 1
For y1 = Y(k) - r To Y(k) + r
For x1 = X(k) - r To X(k) + r
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r) And (x1 >
0) And (x1 < NCol) And (y1 > 0) And (y1 < NFilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If
End If
Next
Next
Next
End Sub
Sub crecer(ByVal cy As Integer, ByVal cx As Integer, ByVal ser As Integer, ByVal
espacio As Integer)
Matriz(cy, cx) = ser
If Matriz(cy, cx + 1) = espacio Then
crecer(cy, cx + 1, ser, espacio)
Else
If Matriz(cy, cx + 1) <> ser Then
trazo(cont) = Matriz(cy, cx + 1)
cont = cont + 1
End If
End If
If Matriz(cy - 1, cx) = espacio Then
crecer(cy - 1, cx, ser, espacio)
Else
If Matriz(cy - 1, cx) <> ser Then
trazo(cont) = Matriz(cy - 1, cx)
cont = cont + 1
End If
End If
If Matriz(cy, cx - 1) = espacio Then
crecer(cy, cx - 1, ser, espacio)

Else
If Matriz(cy, cx - 1) <> ser Then
trazo(cont) = Matriz(cy, cx - 1)
cont = cont + 1
End If
End If
If Matriz(cy + 1, cx) = espacio Then
crecer(cy + 1, cx, ser, espacio)
Else
If Matriz(cy + 1, cx) <> ser Then
trazo(cont) = Matriz(cy + 1, cx)
cont = cont + 1
End If
End If
End Sub
Public Sub linea(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
Dim i As Single, vel As Integer = 10
Dim mayor As Single, ancho As Single, alto As Single, partex As Single,
partey As Single
Dim px As Single, py As Single
Dim dx As Single, dy As Single
ancho = Math.Abs(x2 - x1)
alto = Math.Abs(y2 - y1)
If x1 <= x2 Then
dx = 1
Else
dx = -1
End If
If y1 <= y2 Then
dy = 1
Else
dy = -1
End If
If ancho >= alto Then
mayor = ancho
Else
mayor = alto
End If
partex = ancho / (mayor)
partey = alto / (mayor)
For i = 0 To mayor Step 1
px = i * partex * dx * 1
py = i * partey * dy * 1
Console.CursorLeft = x1 + px
Console.CursorTop = y1 + py

Console.Write("*")
REM
A(y1 + py, x1 + px) = 0
REM Sleep(vel)
Next
End Sub
Sub GrabarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim swEscritor = New StreamWriter("e:\DATOS\pantalla70x24.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Sub EscribirEnMatriz(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer, ByRef A(,) As Integer)
Dim fila As Integer, filaMat As Integer, colMat As Integer
For fila = 0 To ne - 1
filaMat = Y(fila)
colMat = X(fila)
A(filaMat, colMat) = fila + 1
Next
End Sub
Sub recuperarPuntos(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos2x5.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub

Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)


Dim fila As Integer
For fila = 0 To ne - 1
Console.Write(" {0} ", Hex(X(fila)))
Next
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine(" {0} {1} {2}", fila, X(fila), Y(fila))
Next
End Sub
Sub quitarRepetidos(ByVal A() As Integer, ByRef B() As Integer, ByVal ne As
Integer, ByRef nsr As Integer)
Dim fila As Integer, col As Integer
Dim cont As Integer = 0
Dim valor As Integer = 0
For fila = 0 To ne
REM buscar
valor = 0
For col = 0 To cont
If A(fila) = B(col) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
B(cont) = A(fila)
cont = cont + 1
End If
Next
nsr = cont
End Sub
Sub Restar(ByRef B() As Integer, ByVal nsr As Integer)
Dim fila As Integer
For fila = 0 To nsr - 1
B(fila) = B(fila) - 1
Next
End Sub
Sub AsignarMatriz(ByRef M(,) As Integer, ByVal V() As Integer, ByVal ne As
Integer, ByVal nfila As Integer)
Dim col As Integer
For col = 0 To ne - 1
M(nfila, col) = V(col)
Next
End Sub
End Module

CONTAR cuantos vecinos tienes cada area

Module Module1
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Main()
Dim fila As Integer
For fila = 0 To nseres - 1
relleno(fila) = fila
Next
REM contavecinos
RecuperarMatriz(Matriz, nf, nc)
VerMatriz(Matriz, nf, nc, 1, 1)
Console.ForegroundColor = 15
For fila = 0 To nseres - 1
contavecinos(relleno(fila), vecinos, nvecinos)
Console.WriteLine()
Console.Write(" ser {0} ", relleno(fila))
imprimirVector(vecinos, nvecinos)
Next
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module module2
Public srLector As StreamReader
Public relleno(np) As Integer
Public cx As Integer = 1, cy As Integer = 1
Public Matriz(NFilas, NCol) As Integer
Public Const NFilas As Integer = 10, NCol As Integer = 10, np = 100
Public nf As Integer = NFilas, nc As Integer = NCol
Public vecinos(np) As Integer
Public nvecinos As Integer
Public Const nseres As Integer = 8
Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
ByVal cx As Integer, ByVal cy As Integer)
Dim fila As Integer, col As Integer
Dim valor As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.CursorLeft = cx + col
Console.CursorTop = cy + fila
valor = A(fila, col)
Console.ForegroundColor = A(fila, col)
Console.Write("{0}", Hex(A(fila, col)))
Next
Next
End Sub
Sub GrabarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim swEscritor = New StreamWriter("e:\DATOS\pantalla70x24.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Public Sub RecuperarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc
As Integer)
srLector = New StreamReader("e:\DATOS\Matriz10x10.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String

Dim inicio As Integer = 1


Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub contavecinos(ByRef ser As Integer, ByRef Vecinos() As Integer, ByRef
nvecinos As Integer)
Dim fila As Integer, col As Integer
Dim cont = 0
Dim valor As Integer = 0
Vecinos(0) = ser
cont = 1
For fila = 1 To nf - 2
For col = 1 To nc - 2
If (Matriz(fila, col) = ser) Then
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col + 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col + 1)
cont = cont + 1
End If
REM //2

valor = 0
For k = 0 To cont - 1
If Matriz(fila - 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila - 1, col)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col - 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col - 1)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila + 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila + 1, col)
cont = cont + 1
End If
End If
Next
Next
nvecinos = cont
End Sub
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.Write(" {0} ", X(fila))
Next
End Sub

End Module
Programa triangulacin
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim pen As Pen
Dim Color As Color
Dim Grafico As Graphics
Dim BrochaSolida As SolidBrush
Dim nombreColores As String
Dim MColores(10, 3) As Integer
Dim Ex As Single = tam
Dim ey As Single = -tam
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
ListBox1.Items.Add(" X " & X(fila))
Next
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
ListBox1.Items.Clear()
Dim fila As Integer
For fila = 0 To ne - 1
ListBox1.Items.Add(" X " & X(fila) & " Y " & Y(fila))
Next
End Sub
Sub MostrarMatriz(ByVal Cx As Integer, ByVal Cy As Integer, ByVal A(,) As
Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
Dim indice As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
indice = A(fila, col)
BrochaSolida.Color = Color.FromArgb(MColores(indice, 0),
MColores(indice, 1), MColores(indice, 2))
Grafico.FillRectangle(BrochaSolida, col * tam + Cx, fila * tam + Cy, tam,
tam)
Next col
Next fila
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
pen = New Pen(Color.Yellow, 4)
Grafico = PictureBox1.CreateGraphics

BrochaSolida = New SolidBrush(Color.Red)


End Sub
Private Sub BtnPrincipal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrincipal.Click
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim p1 As Integer
Dim p2 As Integer
Dim nsr As Integer = 0
Dim fila As Integer
For fila = 0 To np - 1
relleno(fila) = fila + 1
Next
recuperarPuntos(X, Y, Np)
nombreColores = "e:\DATOS\colores3x50.txt"
RecuperarArchivo(MColores, 10, 3, nombreColores)
IniciarMatriz(MRel, Np, Np, -1)
IniciarMatriz(Matriz, nf, nc, 0)
MostrarMatriz(cx, cy, matriz, nf, nc)
imprimir(X, Y, Np)
REM al crecer obtien cuales son sus vecinos
For r = 0 To 40
crecerCirculo(Matriz, X, Y, nf, nc, relleno, r, Np)
Next
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
Dim MiFuente As New Font("Verdana", 16, FontStyle.Bold)
For fila = 0 To nseres - 1
contavecinos(relleno(fila), vecinos, nvecinos)
restar(vecinos, nvecinos)
AsignarMatriz(MRel, vecinos, nvecinos, fila)
ListBox1.Items.Add("ser " & relleno(fila))
imprimirVector(vecinos, nvecinos)
Next
' graficar
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)
y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else

Grafico.DrawLine(pen, x1 * tam, y1 * tam, x2 * tam, y2 * tam)


End If
End If
Next
Next
BrochaSolida.Color = Color.White
For k = 0 To Np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
End Sub
Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub btnMostrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMostrar.Click
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
End Sub
End Class
Imports System.IO
Module module1
Public tam As Integer = 5
Public Cx As Integer = 10, Cy As Integer = 10
Public npuntos As Integer
Public Matriz(NFilas, NCol) As Integer
Public Const NFilas As Integer = 240, NCol As Integer = 700, maximo = 100
Public Np As Integer = 5
Public relleno(NCol) As Integer
REM Public camino As Integer = 0
Public X(Np) As Integer
Public Y(Np) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public MRel(Np, Np) As Integer
Public srLector As StreamReader
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public nseres As Integer = 5
Public vecinos(maximo) As Integer
Public nvecinos As Integer
Sub contavecinos(ByRef ser As Integer, ByRef Vecinos() As Integer, ByRef
nvecinos As Integer)
Dim fila As Integer, col As Integer

Dim cont = 0
Dim valor As Integer = 0
Vecinos(0) = ser
cont = 1
For fila = 1 To nf - 2
For col = 1 To nc - 2
If (Matriz(fila, col) = ser) Then
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col + 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col + 1)
cont = cont + 1
End If
REM //2
valor = 0
For k = 0 To cont - 1
If Matriz(fila - 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila - 1, col)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col - 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col - 1)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila + 1, col) = Vecinos(k) Then
valor = 1
Exit For

End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila + 1, col)
cont = cont + 1
End If
End If
Next
Next
nvecinos = cont
End Sub
Public Sub RecuperarArchivo(ByVal A(,) As Integer, ByVal nf As Integer, ByVal
nc As Integer, ByVal nombre As String)
srLector = New StreamReader(nombre)
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub crecerCirculo(ByVal A(,) As Integer, ByVal X() As Integer, ByVal Y() As
Integer, ByVal nf As Integer, _

ByVal nc As Integer, ByVal relleno() As Integer, ByVal r As Single, ByVal


np As Integer)
Dim x1 As Integer, y1 As Integer, k As Integer
For k = 0 To np - 1
For y1 = Y(k) - r To Y(k) + r
For x1 = X(k) - r To X(k) + r
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r) And (x1 >
0) And (x1 < NCol) And (y1 > 0) And (y1 < NFilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If
End If
Next
Next
Next
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
ByVal nro As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = nro
Next
Next
End Sub
Sub recuperarPuntos(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos2x5.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub AsignarMatriz(ByRef M(,) As Integer, ByVal V() As Integer, ByVal ne As
Integer, ByVal nfila As Integer)

Dim col As Integer


For col = 0 To ne - 1
M(nfila, col) = V(col)
Next
End Sub
Sub Iniciarvector(ByVal A() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
A(fila) = -1
Next
End Sub
Sub restar(ByRef a() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
a(fila) = a(fila) - 1
Next
End Sub
End Module
EL siguiente ejercicio almacena la informacion como Secuencia ADN

Imports System.IO
Module Module1
Dim swEscritor As StreamWriter
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub main()
cont = 0
'RecuperarMatriz("e:\datos\matriz10x10.txt", A, nfilas, ncol)
RecuperarMatriz("e:\datos\casita21x23.txt", A, nfilas, ncol)
MostrarMatriz(1, 1, A, nfilas, ncol)
proceso()
Console.ReadLine()
End Sub
Sub EncontrarPuntoOrigen(ByRef pxo As Integer, ByRef pyo As Integer, ByVal
camino As Integer)
Dim encontrado As Integer = 0
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
If A(fila, col) = camino Then
pxo = col
pyo = fila
encontrado = 1
Exit For
End If
If encontrado = 1 Then Exit For
Next
Next
End Sub
Sub proceso()
pmx = 1

pmy = 1
EncontrarPuntoOrigen(pxo, pyo, camino)
InicializarObjeto(pxo, pyo, Objeto1)
final = 0
MostrarMatriz(pmx, pmy, A, nf, nc)
MostrarObjeto(pmx, pmy, Objeto1)
NroObjeto = 0
Objetos(NroObjeto) = Objeto1
Objetos2(cont) = Objeto1
A(Objeto1.Cy, Objeto1.Cx) = huella
Console.ReadLine()
Do
Do
'MostrarMatriz(pmx, pmy, A, nf, nc)
MostrarObjeto(pmx, pmy, Objeto1)
resultado = evaluar(Objeto1, A, camino, meta)
If resultado = 1 Then
GoTo fin
procesar = 0
End If
dir = Objeto1.Direc
Select Case dir
Case 1 : Objeto1.Cx = Objeto1.Cx + 1
Case 2 : Objeto1.Cy = Objeto1.Cy - 1
Case 3 : Objeto1.Cx = Objeto1.Cx - 1
Case 4 : Objeto1.Cy = Objeto1.Cy + 1
Case Else : terminado = 1
End Select
Objeto1.Valor = A(Objeto1.Cy, Objeto1.Cx)
A(Objeto1.Cy, Objeto1.Cx) = huella
NroObjeto = NroObjeto + 1
cont = cont + 1
Objeto1.nro = NroObjeto
Objetos(NroObjeto) = Objeto1
Objetos2(cont) = Objeto1
Loop While terminado = 0
terminado = 0
Do
Objeto1 = Objetos(NroObjeto)
'MostrarMatriz(pmx, pmy, A, nf, nc)
MostrarObjeto(pmx, pmy, Objeto1)
resultado = evaluar(Objeto1, A, camino, meta)
dir = Objeto1.Direc
If (NroObjeto < 0) Then GoTo fin
If dir > 0 Then
terminado = 1

Else
A(Objeto1.Cy, Objeto1.Cx) = retorno
NroObjeto = NroObjeto - 1
If (NroObjeto < 0) Then GoTo fin
cont = cont + 1
'Sleep(10)
End If
Loop While terminado = 0
If NroObjeto < 0 Then final = 1
Loop While final = 0
MostrarObjeto(pmx, pmy, Objeto1)
fin:
Console.SetCursorPosition(2, 22)
If NroObjeto > 0 Then
Console.WriteLine("ENCONTRADO X={0} Y = {1} Mov ={2} ",
Objetos(NroObjeto).Cx, Objetos(NroObjeto).Cy, cont)
Else
Console.WriteLine(" no se encontro la meta y se hizo {0} Movimientos ",
cont)
End If
' grabar la matriz de movimientos
swEscritor = New StreamWriter("E:\DATOS\puntosbuscados.txt")
For i = 0 To cont - 1
With Objetos2(i)
swEscritor.WriteLine("{0}{1}{2}{3}{4}{5}{6} {7}{8} {9}{10} {11}{12}{13}{14}
{15}{16} {17} {18}", _
.nro, Chr(9), .dir1, Chr(9), .dir2, Chr(9), .dir3, Chr(9), .dir4,
Chr(9), .Cx, _
Chr(9), .Cy, Chr(9), .np, Chr(9), .Valor, Chr(9), .Direc)
End With
Next
swEscritor.Close()
' Obtener la matriz final
cont2 = 1
Vx(0) = Objetos2(0).Cx
Vy(0) = Objetos2(0).Cy
Vdir(0) = Objetos2(0).Direc
Vvalor(0) = Objetos2(0).Valor
For i = 1 To cont - 1
If Objetos2(i).dir1 = 0 And Objetos2(i).dir2 = 0 And Objetos2(i).dir3 = 0 And
Objetos2(i).dir4 = 0 Then
Continue For
Else
Vx(cont2) = Objetos2(i).Cx
Vy(cont2) = Objetos2(i).Cy
Vdir(cont2) = Objetos2(i).Direc

Vvalor(cont2) = Objetos2(i).Valor
cont2 = cont2 + 1
End If
Next
Console.WriteLine(" Archivo puntos buscados grabados cont2 {0} ", cont2)
swEscritor = New StreamWriter("E:\DATOS\puntosfinales.txt")
For i = 0 To cont2 - 1
swEscritor.WriteLine("{0}{1}{2}{3}{4}", Vx(i), Chr(9), Vy(i), Chr(9), Vvalor(i),
Chr(9), Vdir(i))
Next
swEscritor.Close()
Console.WriteLine(" Archivo puntos finales grabados ")
reconstruir(Vx, Vy, Vdir, Vvalor, cont2, B, 0, 0)
MostrarMatriz(40, 1, B, nf, nc)
procesar = 0
End Sub
Sub reconstruir(ByVal vx() As Integer, ByVal vy As Integer(), ByVal vdir() As
Integer, ByVal vvalor() As Integer, _
ByVal ne As Integer, ByRef B(,) As Integer, _
ByVal dx As Integer, ByVal dy As Integer)
For i = 0 To ne - 1
B(vy(i) + dy, vx(i) + dx) = vvalor(i)
Next
End Sub
End Module

Imports System.IO
Module Module2
Public cont2 As Integer = 0 ' para contar los puntos finales
Public pxo As Integer ' posicion x del objeto
Public pyo As Integer ' posicion y del objeto
Public pmx As Integer ' posicion x de la matriz
Public pmy As Integer ' posicion y de la matriz
Public A(nfilas, ncol) As Integer

Public B(nfilas, ncol) As Integer


Public px1 As Integer
Public py1 As Integer
Public camino As Integer = 9, terminado As Integer = 0, retorno As Integer = 5,
huella = 4
Public meta As Integer = 7, resultado As Integer = 0, dir As Integer = 0
Public mxo As Integer = 9, myo As Integer = 9, mzo As Integer = 0
Public valor As Integer = 0, final As Integer = 0, cont As Integer = 0, NroObjeto
As Integer = 0
Public procesar As Integer = 0 ' al principio no procesa
Public Const nfilas As Integer = 23, ncol As Integer = 21
Public srLector As StreamReader
Public nf As Integer = 23 ' 20
Public nc As Integer = 21 '20
Public Objetos(2000) As Buscador
Public Objetos2(2000) As Buscador
Public Vx(1000) As Integer
Public Vy(1000) As Integer
Public Vdir(1000) As Integer
Public Vvalor(1000) As Integer
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
REM ***
Public Structure Buscador
Public nro As Integer
Public dir1 As Integer, dir2 As Integer, dir3 As Integer, dir4 As Integer '
declarar matrices de 4
Public Cx As Integer
Public Cy As Integer
Public np As Integer
Public Valor As Integer ' Es el valor del objeto encontrado
Public Color As Integer ' Es el color del objeto
Public Direc As Integer
End Structure
Public Objeto1 As Buscador
Function obtenerDir(ByVal d1 As Integer, ByVal d2 As Integer, ByVal d3 As
Integer, ByVal d4 As Integer) As Integer
If d1 = 1 Then Return 1
If d2 = 1 Then Return 2
If d3 = 1 Then Return 3
If d4 = 1 Then Return 4
obtenerDir = 0
End Function
Function evaluar(ByRef objeto1 As Buscador, ByVal Matriz(,) As Integer, ByVal
camino As Integer, ByVal meta As Integer) As Integer
Dim cont As Integer = 0, Cx As Integer, Cy As Integer, Direc As Integer = 0
Dim resultado As Integer = 0
objeto1.dir1 = 0

objeto1.dir2 = 0
objeto1.dir3 = 0
objeto1.dir4 = 0
Cx = objeto1.Cx
Cy = objeto1.Cy
' primero evalua si ya encontro la metas
If Matriz(Cy, Cx + 1) = meta Then
objeto1.dir1 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
If Matriz(Cy - 1, Cx) = meta Then
objeto1.dir2 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
If Matriz(Cy, Cx - 1) = meta Then
objeto1.dir3 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
If Matriz(Cy + 1, Cx) = meta Then
objeto1.dir4 = 1
cont = cont + 1
evaluar = 1
Exit Function
End If
'// si no encuentra meta evalua para figuras complejas
If Matriz(Cy, Cx + 1) >= 9 And Matriz(Cy, Cx + 1) <= 15 Then
'If Matriz(Cy, Cx + 1) = camino Then
objeto1.dir1 = 1
cont = cont + 1
End If
If Matriz(Cy - 1, Cx) >= 9 And Matriz(Cy, Cx + 1) <= 15 Then
'If Matriz(Cy - 1, Cx) = camino Then
objeto1.dir2 = 1
cont = cont + 1
End If
If Matriz(Cy, Cx - 1) >= 9 And Matriz(Cy, Cx + 1) <= 15 Then
'If Matriz(Cy, Cx - 1) = camino Then
objeto1.dir3 = 1
cont = cont + 1
End If

If Matriz(Cy + 1, Cx) >= 9 And Matriz(Cy, Cx + 1) <= 15 Then


'If Matriz(Cy + 1, Cx) = camino Then
objeto1.dir4 = 1
cont = cont + 1
End If
objeto1.np = cont
Direc = obtenerDir(objeto1.dir1, objeto1.dir2, objeto1.dir3, objeto1.dir4)
objeto1.Direc = Direc
evaluar = 0
End Function
Sub InicializarObjeto(ByVal Cx As Integer, ByVal cy As Integer, ByRef Objeto1
As Buscador)
Objeto1.Cx = pxo
Objeto1.Cy = pyo
Objeto1.Valor = 9
Objeto1.Color = 9
Objeto1.dir1 = 0
Objeto1.dir2 = 0
Objeto1.dir3 = 0
Objeto1.dir4 = 0
Objeto1.np = 0
Objeto1.nro = 0
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByVal A(,) As Integer,
ByVal nf As Integer, ByVal nc As Integer)
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
Next
srLector.Close()
End Sub
Sub MostrarObjeto(ByVal pmx As Integer, ByVal pmy As Integer, ByVal objeto1
As Buscador)
Console.ForegroundColor = objeto1.Color

Console.CursorLeft = pmx + objeto1.Cx


Console.CursorTop = pmy + objeto1.Cy
Console.Write("{0}", Hex(objeto1.Valor))
End Sub
Sub MostrarMatriz(ByVal cx As Integer, ByVal cy As Integer, ByVal B(,) As
Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
Console.CursorLeft = cx + col
Console.CursorTop = cy + fila
Console.ForegroundColor = B(fila, col)
Console.Write("{0} ", Hex(B(fila, col)))
Next
Next
End Sub
End Module

Archivos en Modo Consola. CAMBIARLO


Generar valores de una funcin de dos variables en la pantalla y luego grabarlo
para exportarlo a Excel

Module Module1
Function F(ByVal x As Single, ByVal y As Single) As Single
Return (Math.Sin(Math.Pow(x, 2) + Math.Pow(y, 2))) / (x * x + y * y)
'Return Math.Sin(x)
End Function
Sub Main()
Dim X, Y, Z As Single
Console.WriteLine(" VALORES DE UNA FUNCION F(x,y)")
For Y = -4 To 4

For X = -4 To 4 Step 1
Z = F(X, Y)
Console.Write("{0,8:f2}", Z)
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
Con archivos

Imports System.IO
Module Module1
Function F(ByVal x As Single, ByVal y As Single) As Single
Return (Math.Sin(Math.Pow(x, 2) + Math.Pow(y, 2))) / (x * x + y * y)
'Return Math.Sin(x)
End Function
Sub Main()
Dim X, Y, Z As Single
Dim se As StreamWriter
Dim na As String = "E:\datos\funcion.txt"
se = New StreamWriter(na)
se.WriteLine(" VALORES DE UNA FUNCION")
se.WriteLine(" {0,8}{1,8} ", "X", "Y")
For Y = -4 To 4
For X = -4 To 4 Step 1
Z = F(X, Y)
'Console.Write("{0,8:f2}", Z)
se.Write("{0,8:f2}{1}", Z, Chr(9))
Next
se.WriteLine()
Next
se.Close()
Console.WriteLine(" archivo {0} ok", na)
Console.ReadLine()
End Sub
End Module

Leer un Archivo

Option Explicit On
Option Strict On
Imports System.IO
Module Module2
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As String,
ByRef nf As Integer, ByVal nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer = 0, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
Do While Not (cadena Is Nothing)
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = subcadena

inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo {0} leido satisfactoriamente", nombrearchivo)
srLector.Close()
End Sub
Sub MostrarMatriz(ByRef A(,) As String, ByRef nf As Integer, ByVal nc As
Integer)
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) = Chr(9) Then Continue For
Console.Write("{0}", A(fila, col))
Next
Console.WriteLine()
Next
End Sub
End Module
Grabar los valores de una funcin en un archivo de texto exportable a Excel
Imports System.IO
Module Module1
Function F(ByVal x As Single) As Single
Return Math.Pow(x, 2)
'Return Math.Sin(x)
End Function
Sub Main()
Dim X, Y As Single
Dim se As StreamWriter
Dim na As String = "E:\datos\funcion.txt"
se = New StreamWriter(na)
se.WriteLine(" VALORES DE UNA FUNCION")
se.WriteLine(" {0,8}{1,8} ", "X", "Y")
For X = -2 To 3 Step 0.5
Y = F(X)
se.WriteLine("{0,8:f2}{1}{2,8:f4}", X, Chr(9), Y)
Next
se.Close()
Console.WriteLine(" archivo {0} ok", na)
Console.ReadLine()
End Sub
End Module

Los archivos usados en el proyecto son

Module Module1
Dim contador As Integer = 0
Const maxfilas As Integer = 500
Const maxcol As Integer = 10
Dim Matriz(maxfilas, maxcol) As Integer
Sub IniciarVector(ByVal Ruta() As Integer, ByVal np As Integer)
Dim col As Integer
For col = 0 To np - 1
Ruta(col) = 0
Next
End Sub
Sub ImprimirVector(ByVal Ruta() As Integer, ByVal np As Integer)
Dim col As Integer
For col = 0 To np - 1
Console.Write("{0} ", Ruta(col))
Next
End Sub
Sub ImpMatrizEntera(ByVal Matriz(,) As Integer, ByVal nf As Integer, ByVal nc
As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
Console.WriteLine()
Console.Write(" fila {0}==> ", fila)
For col = 0 To nc - 1
Console.Write("{0} ", Matriz(fila, col))
Next

Next
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
a(fila, col) = 0
Next
Next
End Sub
Sub ObtenerVector(ByVal A(,) As Integer, ByVal VA() As Integer, ByVal nc As
Integer, ByVal nrofila As Integer)
Dim col As Integer
For col = 0 To nc - 1
VA(col) = A(nrofila, col)
Next
End Sub
Sub permutaciones(ByVal A(,) As Integer, ByVal B() As Integer, ByVal B1() As
Integer, ByVal n As Integer, ByVal ncam As Integer, ByVal ne As Integer)
Dim i As Integer, k As Integer
If (n > 0) Then
For k = 0 To ncam - 1
B(n) = B1(k)
Call permutaciones(A, B, B1, n - 1, ncam, ne)
Next
Else
For k = 0 To ncam - 1
B(n) = B1(k)
For i = 0 To ne
A(contador, i) = B(i)
contador = contador + 1
Next i
Next k
End If
End Sub
Sub combinaciones(ByVal A(,) As Integer, ByVal B() As Integer, ByVal B1() As
Integer, ByVal n As Integer, ByVal ncam As Integer, ByVal ne As Integer)
Dim i As Integer, k As Integer, valor As Integer = 0
If n > 0 Then
For k = 0 To ncam - 1
B(n) = B1(k)
Call permutaciones(A, B, B1, n - 1, ncam, ne)
Next
Else

For k = 0 To ncam - 1
B(n) = B1(k)
Next k
valor = 1
For i = 0 To ne - 1
For j = 1 + 1 To ne
If B(i) = B(j) Then
valor = 0
Exit For
End If
Next j
Next i
If valor = 1 Then
For i = 0 To ne
A(contador, i) = B(i)
contador = contador + 1
Next i
End If
End If
End Sub
Sub main()
Dim B1(maxcol) As Integer
B1(0) = 1 : B1(1) = 1 : B1(2) = 2 : B1(3) = 3 : B1(4) = 4 : B1(5) = 5
Dim B(maxcol) As Integer
Call IniciarMatriz(Matriz, maxfilas - 1, maxcol - 1)
Dim n As Integer = 3, ncam As Integer = 3
Dim tcombi As Integer = 0, ne As Integer
ne = n
contador = 0
Call IniciarVector(B, maxcol)
permutaciones(Matriz, B, B1, ne - 1, ncam, ne - 1)
tcombi = contador
ImpMatrizEntera(Matriz, tcombi, ne)
Console.ReadLine()
End Sub
End Module

Mover un area de pantalla


Imports System.IO
Module Module1
Dim swEscritor As StreamWriter
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub main()
Console.WindowWidth = 100
Console.WindowHeight = 50
Console.BufferWidth = 100
Console.BufferHeight = 50
Console.Clear()
Console.BackgroundColor = ConsoleColor.Green
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("INGENERIA INDUSTRIAL 2014")
Console.WriteLine("***AREQUIPA ***")
'Sleep(10)
System.Threading.Thread.Sleep(1000) ' 1 segundo
Console.MoveBufferArea(0, 0, 20, 5, 80, 20, "", 15, 0)
Console.ReadLine()
End Sub

Modifique el programa para los pograma para los siguientes puntos


Punt Puebl
o
o
X
y
R1 R2 R3 R4 R5
1
0 10 10
1
2
3 -1 -1
2
1 35 22
0
2
4 -1 -1
3
2 40 12
0
1
3
4 -1
4
3 40
2
0
2
4 -1 -1
5
4 60 10
1
2
3 -1 -1
Modifique lo siguiente y obtendra
Public Const NFilas As Integer = 24, NCol As Integer = 70, npuntos = 5
Dim srLector = New StreamReader("e:\DATOS\puntos5.txt")
srLector = New StreamReader("e:\DATOS\Relaciones4X5.txt")

Se tiene el siguiente archivo recorrerlo con un automata celular

Module Module1
REM Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public relleno(16) As Integer
Public A(NFilas, NCol) As Integer
Dim nf As Integer = NFilas, nc As Integer = NCol
Dim X(16) As Integer
Dim Y(16) As Integer
Dim np As Integer = 5, k As Integer
Dim r As Single
Sub Main()
For fila = 0 To 14
relleno(fila) = fila + 1
Next
relleno(15) = 1
relleno(16) = 2
recuperar(X, Y, np)
imprimir(X, Y, np)
IniciarPantalla(A, nf, nc)
'*****EscribirEnMatriz(X, Y, np, A)
'**** GrabarMatriz(A, NFilas, NCol)
RecuperarArchivo(A, nf, nc)
Verpantalla(A, nf, nc)
Console.ReadLine()
For r = 1 To 30

crecerCirculo(A, X, Y, nf, nc, relleno, r, np)


Verpantalla(A, nf, nc)
Next
Console.ForegroundColor = 15
For k = 0 To np - 1
Console.CursorLeft = X(k)
Console.CursorTop = Y(k)
Console.Write("{0}", k + 1)
Next
Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim srLector As StreamReader
Dim swEscritor As StreamWriter
Public Const NFilas As Integer = 24, NCol As Integer = 70
Public Sub RecuperarArchivo(ByVal A(,) As Integer, ByVal nf As Integer, ByVal
nc As Integer)
srLector = New StreamReader("e:\DATOS\Pantalla70x24A.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do

End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub IniciarPantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 0
Next
Next
End Sub
Sub Verpantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.CursorLeft = col
Console.CursorTop = fila
Console.ForegroundColor = A(fila, col)
Console.Write("{0}", A(fila, col))
Next
Next
End Sub
Sub crecerCirculo(ByVal A(,) As Integer, ByVal X() As Integer, ByVal Y() As
Integer, ByVal nf As Integer, _
ByVal nc As Integer, ByVal relleno() As Integer, ByVal r As Single,
ByVal np As Integer)
Dim x1 As Integer, y1 As Integer, k As Integer
For k = 0 To np - 1
For y1 = Y(k) - r To Y(k) + r
For x1 = X(k) - r To X(k) + r
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r) And (x1 >
0) And (x1 < NCol) And (y1 > 0) And (y1 < NFilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If
End If
Next
Next
Next
End Sub

Sub GrabarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As


Integer)
swEscritor = New StreamWriter("e:\DATOS\pantalla70x24.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Sub EscribirEnMatriz(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer, ByRef A(,) As Integer)
Dim fila As Integer, filaMat As Integer, colMat As Integer
For fila = 0 To ne - 1
filaMat = Y(fila)
colMat = X(fila)
A(filaMat, colMat) = fila + 1
Next
End Sub
Sub recuperar(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos5.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine(" {0} {1} {2}", fila, X(fila), Y(fila))
Next
End Sub
End Module

Reemplace la funcion crecer con


Sub crecer(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer, ByVal
relleno As Integer)
Dim fila, col As Integer
Dim B(NFilas, NCol) As Integer
IniciarPantalla(B, nf, nc)
Dim vecinos As Integer
For fila = 2 To nf - 2
For col = 2 = col To nc - 1
REM si hay espacio crece si no no crece y por lo menos debe haber un vecino
vecinos = 0
If A(fila, col + 1) = relleno Then vecinos = vecinos + 1
If A(fila + 1, col) = relleno Then vecinos = vecinos + 1
If A(fila, col - 1) = relleno Then vecinos = vecinos + 1
If A(fila - 1, col) = relleno Then vecinos = vecinos + 1
If vecinos > 0 And A(fila, col) = 0 Then
B(fila, col) = relleno
Else : B(fila, col) = A(fila, col)
End If
Next
Next
REM traspone la matriz B a la A
IniciarPantalla(A, nf, nc)
TransferirMatriz(B, A, nf, nc)
End Sub
Voronoi en modo grafico
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim fila As Integer
Dim col As Integer
Dim tam As Integer = 10
Dim Color As Color
Dim Grafico As Graphics
Dim BrochaSolida As SolidBrush
Dim nombreArchivo As String
Dim nombreColores As String
Dim MColores(10, 3) As Integer
Sub MostrarMatrizEnPantalla(ByVal Cx As Integer, ByVal Cy As Integer, ByVal
A(,) As Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
Dim indice As Integer
For fila = 0 To nfilas - 1

For col = 0 To ncol - 1


indice = A(fila, col)
BrochaSolida.Color = Color.FromArgb(MColores(indice, 0),
MColores(indice, 1), MColores(indice, 2))
Grafico.FillRectangle(BrochaSolida, col * tam + Cx, fila * tam + Cy, tam,
tam)
Next col
Next fila
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PictureBox1.Width = nc * tam + 1
PictureBox1.Height = nf * tam + 1
Grafico = PictureBox1.CreateGraphics
BrochaSOLIDA = New SolidBrush(Color.Red)
End Sub
Private Sub BtnPrincipal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrincipal.Click
Dim MiFuente As New Font("Verdana", 16, FontStyle.Bold)
Iniciar()
recuperar(X, Y, np)
IniciarPantalla(A, nf, nc)
nombreArchivo = "e:\DATOS\PANTALLA70x24A.txt"
nombreColores = "e:\DATOS\colores3x40.txt"
RecuperarArchivo(A, nf, nc, nombreArchivo)
RecuperarArchivo(MColores, 10, 3, nombreColores)
MostrarMatrizEnPantalla(Cx, Cy, A, nf, nc)
For k = 1 To 25
crecer(A, nf, nc, np)
MostrarMatrizEnPantalla(Cx, Cy, A, nf, nc)
Next
BrochaSolida.Color = Color.White
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
End Sub
Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBorrar.Click
Grafico.Clear(Color.White)
End Sub
End Class
Imports System.IO
Module module1
'/*** declaraciones

Public Const NFilas As Integer = 24, NCol As Integer = 70


Public Cx As Integer = 10, Cy As Integer = 10
Public srLector As StreamReader
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public relleno(NCol) As Integer
Public A(NFilas, NCol) As Integer
Public B(NFilas, NCol) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public X(40) As Integer
Public Y(40) As Integer
Public np As Integer = 5, k As Integer
Public vecinos As Integer
Public Sub RecuperarArchivo(ByVal A(,) As Integer, ByVal nf As Integer, ByVal
nc As Integer, ByVal nombre As String)
srLector = New StreamReader(nombre)
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub IniciarPantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)

Dim fila As Integer, col As Integer


For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 0
Next
Next
End Sub
Sub recuperar(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos5.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine(" {0} {1} {2}", fila, X(fila), Y(fila))
Next
End Sub
Sub Iniciar()
For fila = 0 To NFilas
relleno(fila) = fila + 1
Next
End Sub
Sub crecer(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
ByVal np As Integer)
Dim fila1 As Integer, col1 As Integer
Dim k1 As Integer
IniciarPantalla(B, nf, nc)
For fila1 = 1 To nf - 1
For col1 = 1 To nc - 1

REM si hay espacio crece si no no crece y por lo menos debe haber un


vecino
For k1 = 0 To np - 1
vecinos = 0
If A(fila1, col1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1, col1 + 1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1 + 1, col1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1, col1 - 1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1 - 1, col1) = relleno(k1) Then vecinos = vecinos + 1
If vecinos > 0 And A(fila1, col1) = 0 Then
B(fila1, col1) = relleno(k1) 'relleno(k1)
Exit For
Else
B(fila1, col1) = A(fila1, col1)
End If
Next k1
Next col1
Next fila1
IniciarPantalla(A, nf, nc)
TransferirMatriz(B, A, nf, nc)
End Sub
Sub TransferirMatriz(ByVal A(,) As Integer, ByVal B(,) As Integer, ByVal nf As
Integer, ByVal nc As Integer)
For fila = 0 To nf - 1
For col = 0 To nc - 1
B(fila, col) = A(fila, col)
Next
Next
End Sub
End Module

Module Module1
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim MTrazos(Np, Np) As Integer
Sub Main()
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim p1 As Integer
Dim p2 As Integer
Dim B(50) As Integer
Dim nsr As Integer = 0
Dim fila As Integer
For fila = 0 To Np - 1
relleno(fila) = fila + 1
Next
recuperarPuntos(X, Y, Np)
imprimir(X, Y, Np)
IniciarMatriz(MRel, Np, Np)
EscribirEnMatriz(X, Y, Np, Matriz)
VerMatriz(Matriz, nf, nc, 1, 1)
REM al crecer obtien cuales son sus vecinos
For r = 1 To 20
crecerCirculo(Matriz, X, Y, nf, nc, relleno, r, Np)
VerMatriz(Matriz, nf, nc, 1, 1)
Next
Console.ForegroundColor = 15
For k = 0 To Np - 1

Console.CursorLeft = X(k)
Console.CursorTop = Y(k)
Console.Write("{0}", k)
Next
For fila = 0 To Np - 1
trazo(0) = fila + 1
cont = 1
crecer(Y(fila), X(fila), 0, relleno(fila))
REM VerMatriz(Matriz, nf, nc, 1, 1)
npuntos = cont
quitarRepetidos(trazo, B, npuntos, nsr)
Restar(B, nsr)
AsignarMatriz(MRel, B, nsr, fila)
Next
Console.ForegroundColor = 15
Console.CursorLeft = 1
Console.CursorTop = 24
ImprimirMatriz(MRel, Np, Np)
Console.ReadLine()
' graficar
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)
y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else
linea(x1, y1, x2, y2)
End If
End If
Next
Next
Console.ForegroundColor = 14
For k = 0 To Np - 1
Console.CursorLeft = X(k)
Console.CursorTop = Y(k)
Console.Write("{0}", k)
Next
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module module2
Public cx As Integer = 1, cy As Integer = 1
Public cont As Integer
Public npuntos As Integer
Public Matriz(NFilas, NCol) As Integer
Const NFilas As Integer = 24, NCol As Integer = 70
Public Np As Integer = 5
Public relleno(Np) As Integer
Public camino As Integer = 0
Public X(Np) As Integer
Public Y(Np) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public trazo(500) As Integer
Public MRel(Np, Np) As Integer
REM Public nt As Integer
Public espacio As Integer = 0
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = -1
Next
Next
End Sub
Sub ImprimirMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
Console.WriteLine()
For col = 0 To nc - 1
If A(fila, col) >= 0 Then
Console.Write("{0} ", A(fila, col))
End If
Next
Next
End Sub
Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
ByVal cx As Integer, ByVal cy As Integer)
Dim fila As Integer, col As Integer
Dim valor As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.CursorLeft = cx + col

Console.CursorTop = cy + fila
valor = A(fila, col)
Console.ForegroundColor = A(fila, col)
Console.Write("{0}", Hex(A(fila, col)))
Next
Next
End Sub
Sub crecerCirculo(ByVal A(,) As Integer, ByVal X() As Integer, ByVal Y() As
Integer, ByVal nf As Integer, _
ByVal nc As Integer, ByVal relleno() As Integer, ByVal r As Single,
ByVal np As Integer)
Dim x1 As Integer, y1 As Integer, k As Integer
For k = 0 To np - 1
For y1 = Y(k) - r To Y(k) + r
For x1 = X(k) - r To X(k) + r
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r) And (x1 >
0) And (x1 < NCol) And (y1 > 0) And (y1 < NFilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If
End If
Next
Next
Next
End Sub
Sub crecer(ByVal cy As Integer, ByVal cx As Integer, ByVal ser As Integer, ByVal
espacio As Integer)
Matriz(cy, cx) = ser
If Matriz(cy, cx + 1) = espacio Then
crecer(cy, cx + 1, ser, espacio)
Else
If Matriz(cy, cx + 1) <> ser Then
trazo(cont) = Matriz(cy, cx + 1)
cont = cont + 1
End If
End If
If Matriz(cy - 1, cx) = espacio Then
crecer(cy - 1, cx, ser, espacio)
Else
If Matriz(cy - 1, cx) <> ser Then
trazo(cont) = Matriz(cy - 1, cx)
cont = cont + 1
End If
End If
If Matriz(cy, cx - 1) = espacio Then
crecer(cy, cx - 1, ser, espacio)
Else

If Matriz(cy, cx - 1) <> ser Then


trazo(cont) = Matriz(cy, cx - 1)
cont = cont + 1
End If
End If
If Matriz(cy + 1, cx) = espacio Then
crecer(cy + 1, cx, ser, espacio)
Else
If Matriz(cy + 1, cx) <> ser Then
trazo(cont) = Matriz(cy + 1, cx)
cont = cont + 1
End If
End If
End Sub
Public Sub linea(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
Dim i As Single, vel As Integer = 10
Dim mayor As Single, ancho As Single, alto As Single, partex As Single,
partey As Single
Dim px As Single, py As Single
Dim dx As Single, dy As Single
ancho = Math.Abs(x2 - x1)
alto = Math.Abs(y2 - y1)
If x1 <= x2 Then
dx = 1
Else
dx = -1
End If
If y1 <= y2 Then
dy = 1
Else
dy = -1
End If
If ancho >= alto Then
mayor = ancho
Else
mayor = alto
End If
partex = ancho / (mayor)
partey = alto / (mayor)
For i = 0 To mayor Step 1
px = i * partex * dx * 1
py = i * partey * dy * 1
Console.CursorLeft = x1 + px
Console.CursorTop = y1 + py
Console.Write("*")

REM
A(y1 + py, x1 + px) = 0
REM Sleep(vel)
Next
End Sub
Sub GrabarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim swEscritor = New StreamWriter("e:\DATOS\pantalla70x24.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Sub EscribirEnMatriz(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer, ByRef A(,) As Integer)
Dim fila As Integer, filaMat As Integer, colMat As Integer
For fila = 0 To ne - 1
filaMat = Y(fila)
colMat = X(fila)
A(filaMat, colMat) = fila + 1
Next
End Sub
Sub recuperarPuntos(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos2x5.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)

Dim fila As Integer


For fila = 0 To ne - 1
Console.Write(" {0} ", Hex(X(fila)))
Next
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine(" {0} {1} {2}", fila, X(fila), Y(fila))
Next
End Sub
Sub quitarRepetidos(ByVal A() As Integer, ByRef B() As Integer, ByVal ne As
Integer, ByRef nsr As Integer)
Dim fila As Integer, col As Integer
Dim cont As Integer = 0
Dim valor As Integer = 0
For fila = 0 To ne
REM buscar
valor = 0
For col = 0 To cont
If A(fila) = B(col) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
B(cont) = A(fila)
cont = cont + 1
End If
Next
nsr = cont
End Sub
Sub Restar(ByRef B() As Integer, ByVal nsr As Integer)
Dim fila As Integer
For fila = 0 To nsr - 1
B(fila) = B(fila) - 1
Next
End Sub
Sub AsignarMatriz(ByRef M(,) As Integer, ByVal V() As Integer, ByVal ne As
Integer, ByVal nfila As Integer)
Dim col As Integer
For col = 0 To ne - 1
M(nfila, col) = V(col)
Next
End Sub
End Module

APLICACION MODELADO 3D

Los datos son

punt
o
1
2
3
cara x y z x y z x y z
0 0 0 0 1 0 0 1 1
1 1 0 0 1 0 1 1 1
2 0 0 1 0 1 1 1 1
3 0 0 0 0 1 0 0 1
4 0 1 0 1 1 0 1 1
5 0 0 0 0 0 1 1 0

4
x
0
1
1
1
1
1

y
0
1
1
0
0
1

z
1
1
0
0
1
0

0
0
1
1
1
0

Cdigo mdule 1
Imports System.IO
Module Module1
Public srLector As StreamReader
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub ObtenerNormales(ByVal A(,) As Single, ByVal Normales(,) As Single,
ByVal nf As Integer, ByVal D As Single)

Dim Pe As Single, R As Single


Dim AX As Single, Ay As Single, Az As Single, Bx As Single, By As Single, Bz
As Single
Dim NX As Single, Ny As Single, Nz As Single, Nx1 As Single, Ny1 As Single,
Nz1 As Single
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim x3 As Single, y3 As Single, z3 As Single
For fila = 0 To nf - 1
x1 = A(fila, 1)
y1 = A(fila, 2)
z1 = A(fila, 3)
x2 = A(fila, 4)
y2 = A(fila, 5)
z2 = A(fila, 6)
x3 = A(fila, 7)
y3 = A(fila, 8)
z3 = A(fila, 9)
AX = x2 - x1
Ay = y2 - y1
Az = z2 - z1
Bx = x3 - x2
By = y3 - y2
Bz = z3 - z2
NX = Ay * Bz - Az * By
Ny = AX * Bz - Az * Bx
Nz = AX * By - Ay * Bx
'PRODUCTO(CRUZ)
R = Math.Sqrt(NX * NX + Ny * Ny + Nz * Nz)
If R > 0 Then
Nx1 = NX / R
Else
Nx1 = 1000
End If
If R > 0 Then
Ny1 = Ny / R
Else
Ny1 = 1000
End If
If R > 0 Then
Nz1 = Nz / R
Else
Nz1 = 1000
End If
Pe = Nx1 * 0 + Ny1 * 0 + Nz1 * D
Normales(fila, 0) = Nx1
Normales(fila, 1) = Ny

Normales(fila, 2) = Nz1
Normales(fila, 3) = Pe
Next
End Sub
Sub CopiarMatriz(ByVal A(,) As Single, ByVal B(,) As Single, ByVal nf As
Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
B(fila, col) = A(fila, col)
Next
Next
End Sub
Sub IniciarMatriz(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 0
Next
Next
End Sub
Sub LeerArchivo(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As
Integer)
srLector = New StreamReader("e:\DATOS\caras2.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)

A(fila, cont) = Val(subcadena)


cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
srLector.Close()
End Sub
Sub ImprimirMatriz(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
Console.WriteLine()
For col = 0 To nc - 1
Console.Write("{0}", A(fila, col).ToString.PadLeft(5))
Next
Next
End Sub
End Module
Codigo del formulario
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Dim modo As Integer = 0
Dim D As Integer = 1000
Dim vel As Integer = 10
Dim Pen As Pen
Dim Grafico As Graphics
Const maxfilas As Integer = 50
Const maxcol As Integer = 60
Dim A(maxfilas, maxcol) As Single
Dim B(maxfilas, maxcol) As Single ' matriz para copias
Dim Normales(maxfilas, 4) As Single
Dim nf As Integer = 8
Dim nc As Integer = 4
Dim ntc As Integer = nc * 3 + 1 ' numeros totales de columnas
Dim Cx As Integer = 200
Dim Cy As Integer = 200
Dim Cz As Integer = 0
Dim ex As Single = 100
Dim ey As Single = -100
Dim ez As Single = 1
Dim anguloz As Single, dz As Single = 0.1
Dim anguloy As Single, dy As Single = 0.1
Dim angulox As Single, dx As Single = 0.1
Dim gradosx, gradosy, gradosz

Private Sub MnuCargarDatos_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MnuCargarDatos.Click
LeerArchivo(A, nf, nc)
CopiarMatriz(A, B, nf, nc)
ObtenerNormales(A, Normales, nf, D)
Me.Text = "Archivo leido satisfactoriamente"
' rellenarlo a un datagrid
DataGridView1.RowCount = nf + 1
DataGridView1.ColumnCount = ntc + 1
For fila = 0 To ntc
DataGridView1.Columns(fila).Width = 40
Next
DataGridView1.Columns(0).Name = "punto"
DataGridView1.Columns(1).Name = "X"
DataGridView1.Columns(2).Name = "Y"
DataGridView1.Columns(3).Name = "Z"
For fila = 0 To nf
For col = 0 To ntc
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
End Sub
Sub graficar(ByVal M(,) As Single, ByVal nf As Integer, ByVal nc As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal cz As Integer, _
ByVal ex As Single, ByVal ey As Single, ByVal ez As Single, ByVal D As
Integer, ByVal modo As Integer, ByVal Normales(,) As Single)
Dim fila As Integer, col As Integer
Dim x1 As Single, y1 As Single, z1 As Single
Dim px1 As Single, py1 As Single
Dim cara As Integer = 0
For fila = 0 To nf - 1
Dim Figura(nc - 1) As Point
cara = M(fila, 0)
For col = 0 To nc - 1
x1 = cx + M(fila, col * 3 + 1) * ex
y1 = cy + M(fila, col * 3 + 2) * ey
z1 = cz + M(fila, col * 3 + 3) * ez
px1 = (x1 * D) / (D + z1)
py1 = (y1 * D) / (D + z1)
Figura(col).X = px1
Figura(col).Y = py1
Next
If modo = 1 Then
If Normales(fila, 2) > 0 Then 'solo dibuja si el normal es mayor que 0
Grafico.DrawPolygon(New Pen(Color.Red, 3), Figura)

Select Case cara


Case 0 : Grafico.FillPolygon(Brushes.Green, Figura,
FillMode.Alternate)
Case 1 : Grafico.FillPolygon(Brushes.Red, Figura,
FillMode.Alternate)
Case 2 : Grafico.FillPolygon(Brushes.Blue, Figura,
FillMode.Alternate)
Case 3 : Grafico.FillPolygon(Brushes.Yellow, Figura,
FillMode.Alternate)
Case 4 : Grafico.FillPolygon(Brushes.Turquoise, Figura,
FillMode.Alternate)
Case 5 : Grafico.FillPolygon(Brushes.Silver, Figura,
FillMode.Alternate)
End Select
End If
Else
Grafico.DrawPolygon(New Pen(Color.Red, 3), Figura)
End If
Next fila
End Sub
Private Sub MnuCargarPropiedades_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MnuCargarPropiedades.Click
' rellenarlo a un datagrid
DataGridView2.RowCount = 11
DataGridView2.ColumnCount = 2
DataGridView2.Columns(1).Width = 40
DataGridView2.Columns(0).Name = "Propiedad"
DataGridView2.Columns(1).Name = "Valor"
DataGridView2.Rows(0).Cells(0).Value = "CX"
DataGridView2.Rows(0).Cells(1).Value = "100"
DataGridView2.Rows(1).Cells(0).Value = "CY"
DataGridView2.Rows(1).Cells(1).Value = "100"
DataGridView2.Rows(2).Cells(0).Value = "CZ"
DataGridView2.Rows(2).Cells(1).Value = "0"
DataGridView2.Rows(3).Cells(0).Value = "EX"
DataGridView2.Rows(3).Cells(1).Value = "10"
DataGridView2.Rows(4).Cells(0).Value = "EY"
DataGridView2.Rows(4).Cells(1).Value = "10"
DataGridView2.Rows(5).Cells(0).Value = "EZ"
DataGridView2.Rows(5).Cells(1).Value = "10"
DataGridView2.Rows(6).Cells(0).Value = "NF"
DataGridView2.Rows(6).Cells(1).Value = "8"
DataGridView2.Rows(7).Cells(0).Value = "Velocidad"
DataGridView2.Rows(7).Cells(1).Value = "10"
DataGridView2.Rows(8).Cells(0).Value = "D"
DataGridView2.Rows(8).Cells(1).Value = "1000"

DataGridView2.Rows(9).Cells(0).Value = "Modo"
DataGridView2.Rows(9).Cells(1).Value = "0"
DataGridView2.Rows(10).Cells(0).Value = "NC"
DataGridView2.Rows(10).Cells(1).Value = "4"
End Sub
Private Sub MnuIniciarfPropiedades_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MnuIniciarfPropiedades.Click
nf = DataGridView2.Rows(6).Cells(1).Value
Cx = DataGridView2.Rows(0).Cells(1).Value
Cy = DataGridView2.Rows(1).Cells(1).Value
Cz = DataGridView2.Rows(2).Cells(1).Value
ex = DataGridView2.Rows(3).Cells(1).Value
ey = DataGridView2.Rows(4).Cells(1).Value
ez = DataGridView2.Rows(5).Cells(1).Value
vel = DataGridView2.Rows(7).Cells(1).Value
D = DataGridView2.Rows(8).Cells(1).Value
modo = DataGridView2.Rows(9).Cells(1).Value
nc = DataGridView2.Rows(10).Cells(1).Value
End Sub
Private Sub MnuDibujar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuDibujar.Click
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub MnuBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
Pen = New Pen(Color.Red, 1)
End Sub
Private Sub MnuIzquierdaDerecha_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MnuIzquierdaDerecha.Click
For Cx = 100 To PictureBox1.Width - 100
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
Cx = PictureBox1.Width - 100
End Sub

Private Sub MnuderechaIzquierda_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles MnuderechaIzquierda.Click
For Cx = PictureBox1.Width - 100 To 10 Step -1
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
Cx = 100
End Sub
Private Sub MnuArribaAbajo_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MnuArribaAbajo.Click
For Cy = 100 To PictureBox1.Height - 100
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
Cy = PictureBox1.Height - 100
End Sub
Private Sub DeAbajoArriba_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DeAbajoArriba.Click
For Cy = PictureBox1.Height - 100 To 100 Step -1
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
Cy = 100
End Sub
Private Sub MnuRotEjeZ_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuRotEjeZ.Click
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim fila As Integer = 0, col As Integer
dz = 0.1
For anguloz = 0 To 2 * Math.PI Step dz
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = A(fila, col * 3 + 1)
y1 = A(fila, col * 3 + 2)
z1 = A(fila, col * 3 + 3)
x2 = x1 * Math.Cos(dz) - y1 * Math.Sin(dz)
y2 = x1 * Math.Sin(dz) + y1 * Math.Cos(dz)
z2 = z1
A(fila, col * 3 + 1) = x2
A(fila, col * 3 + 2) = y2

A(fila, col * 3 + 3) = z2
Next
Next
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
End Sub
Private Sub MnuRotX_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuRotX.Click
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
dx = 0.1
For angulox = 0 To 2 * Math.PI Step dx
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = A(fila, col * 3 + 1)
y1 = A(fila, col * 3 + 2)
z1 = A(fila, col * 3 + 3)
x2 = x1
y2 = y1 * Math.Cos(dx) - z1 * Math.Sin(dx)
z2 = y1 * Math.Sin(dx) + z1 * Math.Cos(dx)
A(fila, col * 3 + 1) = x2
A(fila, col * 3 + 2) = y2
A(fila, col * 3 + 3) = z2
Next
Next
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
End Sub
Private Sub MnuRotEjeY_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuRotEjeY.Click
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
dy = 0.1
For anguloy = 0 To 2 * Math.PI Step dy
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = A(fila, col * 3 + 1)
y1 = A(fila, col * 3 + 2)
z1 = A(fila, col * 3 + 3)
x2 = x1 * Math.Cos(dy) + z1 * Math.Sin(dy)
y2 = y1

z2 = -x1 * Math.Sin(dy) + z1 * Math.Cos(dy)


A(fila, col * 3 + 1) = x2
A(fila, col * 3 + 2) = y2
A(fila, col * 3 + 3) = z2
Next
Next
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
End Sub
Private Sub MnuAlejar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuAlejar.Click
For Cz = 0 To 400
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
Cz = 400
End Sub
Private Sub MnuAcercar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuAcercar.Click
For Cz = 400 To 0 Step -1
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
Cz = 0
End Sub
Private Sub MnuMenosPerspectiva_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MnuMenosPerspectiva.Click
For D = 10 To 1000 Step 10
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
D = 1000
End Sub
Private Sub MnuMasPerspectiva_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MnuMasPerspectiva.Click
For D = 1000 To 10 Step -10
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)

Sleep(vel)
Next
D = 10
End Sub
Private Sub AumentarEscalaX_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles AumentarEscalaX.Click
For ex = 1 To 20
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
ex = 20
End Sub
Private Sub DesminuirEscalaX_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles DesminuirEscalaX.Click
For ex = 20 To 1 Step -1
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
ex = 1
End Sub
Private Sub AumentarEscalaY_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles AumentarEscalaY.Click
For ey = 1 To 20
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
ey = 20
End Sub
Private Sub DesminuirEscalaY_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles DesminuirEscalaY.Click
For ey = 20 To 1 Step -1
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
ey = 1
End Sub
Private Sub AumentarEscalaZ_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles AumentarEscalaZ.Click

For ez = 1 To 20
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
ez = 20
End Sub
Private Sub DesminuirEscalaZ_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles DesminuirEscalaZ.Click
For ez = 20 To 1 Step -1
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
Sleep(vel)
Next
ez = 1
End Sub
Private Sub HSRX_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSRX.Scroll
gradosx = HSRX.Value
TxtX.Text = gradosx
angulox = gradosx * Math.PI / 180
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
dx = 2 * Math.PI / 360
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = A(fila, col * 3 + 1)
y1 = A(fila, col * 3 + 2)
z1 = A(fila, col * 3 + 3)
x2 = x1
y2 = y1 * Math.Cos(dx) - z1 * Math.Sin(dx)
z2 = y1 * Math.Sin(dx) + z1 * Math.Cos(dx)
A(fila, col * 3 + 1) = x2
A(fila, col * 3 + 2) = y2
A(fila, col * 3 + 3) = z2
Next
Next
Grafico.Clear(Color.White)
ObtenerNormales(A, Normales, nf, D)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSRY_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSRY.Scroll
Dim x1 As Single, y1 As Single, z1 As Single

Dim x2 As Single, y2 As Single, z2 As Single


gradosy = HSRY.Value
txtRY.Text = gradosy
anguloy = gradosy * Math.PI / 180
IniciarMatriz(B, nf + 1, nc + 1)
dy = 2 * Math.PI / 360
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = A(fila, col * 3 + 1)
y1 = A(fila, col * 3 + 2)
z1 = A(fila, col * 3 + 3)
x2 = x1 * Math.Cos(dy) + z1 * Math.Sin(dy)
y2 = y1
z2 = -x1 * Math.Sin(dy) + z1 * Math.Cos(dy)
A(fila, col * 3 + 1) = x2
A(fila, col * 3 + 2) = y2
A(fila, col * 3 + 3) = z2
Next
Next
Grafico.Clear(Color.White)
ObtenerNormales(A, Normales, nf, D)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSRZ_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSRZ.Scroll
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim fila As Integer = 0, col As Integer
gradosz = HSRZ.Value
txtRZ.Text = gradosz
anguloz = gradosz * Math.PI / 180
dz = 2 * Math.PI / 360
IniciarMatriz(B, nf + 1, nc + 1)
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = A(fila, col * 3 + 1)
y1 = A(fila, col * 3 + 2)
z1 = A(fila, col * 3 + 3)
x2 = x1 * Math.Cos(dz) - y1 * Math.Sin(dz)
y2 = x1 * Math.Sin(dz) + y1 * Math.Cos(dz)
z2 = z1
A(fila, col * 3 + 1) = x2
A(fila, col * 3 + 2) = y2
A(fila, col * 3 + 3) = z2
Next
Next

Grafico.Clear(Color.White)
ObtenerNormales(A, Normales, nf, D)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSTx_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSTx.Scroll
Cx = HSTx.Value
TxtTx.Text = Cx
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSTy_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSTy.Scroll
Cy = HSTy.Value
txtTY.Text = Cy
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSTz_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSTz.Scroll
Cz = HSTz.Value
TxtTZ.Text = Cz
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSTD_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSTD.Scroll
D = HSTD.Value
TxtD.Text = D
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSEx_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSEX.Scroll
ex = HSEX.Value
TxtEx.Text = ex
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSey_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSEY.Scroll
ey = HSEY.Value

TxtEy.Text = ey
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub HSEz_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HSEz.Scroll
ez = HSEz.Value
TxtEz.Text = ez
Grafico.Clear(Color.White)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub MnuModeloAlambre_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MnuModeloAlambre.Click
modo = 0
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub mnuModeloSolido_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs)
modo = 1
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub MnuNormales_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuNormales.Click
ObtenerNormales(A, Normales, nf, D)
End Sub
Sub esfera(ByVal M(,) As Single, ByVal radio As Single, ByVal nf As Single,
ByVal nc As Single)
' giramos un punto alrededor del eje y y lo almacenamos en en un vecto
Dim dy As Single, anguloy1 As Single
Dim fila As Integer, col As Integer
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
fila = 0
ntc = nc * 3 + 1
dy = 2 * Math.PI / nc
x1 = radio
y1 = 0
z1 = 0
anguloy1 = 0
M(fila, 0) = 0
col = 0
Do
x2 = x1 * Math.Cos(anguloy1) + z1 * Math.Sin(anguloy1)

y2 = y1
z2 = -x1 * Math.Sin(anguloy1) + z1 * Math.Cos(anguloy1)
M(fila, col) = x2 : col = col + 1
M(fila, col) = y2 : col = col + 1
M(fila, col) = z2 : col = col + 1
anguloy1 = anguloy1 + dy
Loop While (col < ntc)
End Sub
Private Sub MnuEsfera_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuEsfera.Click
Dim radio As Single = 2
IniciarMatriz(A, maxfilas, maxcol)
esfera(A, radio, nf, nc)
ObtenerNormales(A, Normales, nf, D)
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
Private Sub MnuTextura_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuTextura.Click
Dim Pen As Pen
Dim Grafico As Graphics
Dim bitmap As New Bitmap("E:\datos\epii.jpg")
Dim tBrush As New TextureBrush(bitmap)
Dim texturedPen As New Pen(tBrush, 30)
Grafico = PictureBox1.CreateGraphics
Pen = New Pen(Color.Red, 1)
Grafico.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height)
Grafico.DrawEllipse(texturedPen, 100, 20, 200, 100)
End Sub
Private Sub MnuSalir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuSalir.Click
Me.Close()
End Sub
Private Sub ModeloSolido_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ModeloSolido.Click
modo = 1
graficar(A, nf, nc, Cx, Cy, Cz, ex, ey, ez, D, modo, Normales)
End Sub
End Class

Option Explicit On
Imports System.Drawing
Public Class Form1
Dim Grafico As Graphics
Dim ColorFondo As Color = Color.FromArgb(255, 255, 255)
Dim pen1 As Pen
Dim pen2 As Pen
Dim Matriz(maxfilas, 6) As Single
Dim X(maxfilas) As Single
Dim Y(maxfilas) As Single
Dim Cx As Integer = 10
Dim Cy As Integer = 400
Dim ex As Single = 1
Dim ey As Single = -1
Sub MostrarPuntos(ByVal X() As Single, ByVal Y() As Single, ByVal nf As
Integer)
ListBox1.Items.Clear()
For fila = 0 To nf
ListBox1.Items.Add(X(fila) & " = " & Y(fila))
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
pen1 = New Pen(Color.FromArgb(255, 0, 0), 2)
pen2 = New Pen(Color.FromArgb(0, 0, 255), 3)
End Sub

Private Sub BtnBorrar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub Btndibujar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Btndibujar.Click
Grafico.DrawLine(pen1, 0, Cy, Cx * 2, Cy)
Grafico.DrawLine(pen1, Cx, 0, Cx, Cy * 2)
graficar(X, Y, Cx, Cy, ex, ey, np)
End Sub
Sub graficar(ByVal X() As Single, ByVal Y() As Single, ByVal Cx As Integer,
ByVal cy As Integer, ByVal ex As Single, ByVal ey As Single, ByVal np As Integer)
REM ListBox1.Items.Clear()
Dim Resultado As Integer
Dim graficar As Integer = 0
Dim cont2 As Integer = 0
Dim AX(4) As Single
Dim AY(4) As Single
Dim Matriz(maxfilas, 6) As Single
iniciarMatriz(Matriz, maxfilas, 6)
Dim fila As Integer
Dim col As Integer
Dim cont As Integer
Dim npuntos As Integer
Dim px1 As Single, py1 As Single, px2 As Single, py2 As Single
For fila = 0 To np - 2
For col = fila + 1 To np - 1
Matriz(cont, 0) = X(fila)
Matriz(cont, 1) = Y(fila)
Matriz(cont, 2) = X(col)
Matriz(cont, 3) = Y(col)
Matriz(cont, 4) = 0 ' no esta graficado
Matriz(cont, 5) = distancia(X(fila), Y(fila), X(col), Y(col))
cont = cont + 1
Next
Next
npuntos = cont
REM GrabarMatriz(Matriz, npuntos, 6)
OrdenarMatriz(Matriz, npuntos) ' *** no ordenar
GrabarMatriz(Matriz, npuntos, 6)
For fila = 0 To npuntos - 1 ' npuntos-1
graficar = 1 ' graficara
For col = 0 To npuntos - 1
REM fila con col graficar probar sis epuede
If fila <> col Then
If Matriz(col, 4) = 1 Then
ObtenerVectores(Matriz, AX, AY, fila, col)

Resultado = Interseccion(AX, AY)


If Resultado = 1 Then ' bata que se cruce con 1 para no graficar
graficar = 0 ' graficara
Exit For
End If
End If
End If
Next col
If graficar = 1 Then
px1 = Matriz(fila, 0)
py1 = Matriz(fila, 1)
px2 = Matriz(fila, 2)
py2 = Matriz(fila, 3)
Grafico.DrawLine(pen1, Cx + px1 * ex, cy + py1 * ey, Cx + px2 * ex, cy +
py2 * ey)
Matriz(fila, 4) = 1 ' ya esta graficado
End If
Next
MostrarMatriz(Matriz, npuntos)
GrabarMatriz(Matriz, npuntos, 6)
End Sub
Sub MostrarMatriz(ByVal A(,) As Single, ByVal nf As Integer)
Dim cadena As String
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
cadena = "fila " & fila
For col = 0 To 5
cadena = " " & cadena & " " & A(fila, col)
Next
ListBox1.Items.Add(cadena)
Next
End Sub
Private Sub btnRecuperar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRecuperar.Click
RecuperarPuntos(X, Y, np)
MostrarPuntos(X, Y, np)
End Sub
Private Sub btngenerar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btngenerar.Click
generarPuntos(X, Y, np)
End Sub
Private Sub Btnescala_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Btnescala.Click
ex = txtEx.Text
ey = TxtEy.Text
End Sub
End Class

CODIGO DEL MODULO


Option Explicit On
Imports System.IO
Module Module2
Public Const maxfilas As Integer = 5000
Public X(maxfilas) As Single
Public Y(maxfilas) As Single
Public np As Integer = 100
Function mayor(ByVal x1 As Single, ByVal x2 As Single) As Single
Dim maximo As Single
If x1 > x2 Then
maximo = x1
Else
maximo = x2
End If
Return maximo
End Function
Function menor(ByVal x1 As Single, ByVal x2 As Single) As Single
Dim minimo As Single
If x1 < x2 Then
minimo = x1
Else
minimo = x2
End If
Return minimo
End Function
Function Interseccion(ByVal X1() As Single, ByVal Y1() As Single) As Integer
Dim resultado As Integer = 0
Dim XA(4) As Single
Dim YA(4) As Single
Dim R1xmin As Single
Dim R1xmax As Single
Dim R1ymin As Single
Dim R1ymax As Single
Dim R2xmin As Single
Dim R2xmax As Single
Dim R2ymin As Single
Dim R2ymax As Single
Dim px As Single
Dim py As Single
R1xmin = menor(X1(0), X1(1))
R1xmax = mayor(X1(0), X1(1))
R1ymin = menor(Y1(0), Y1(1))
R1ymax = mayor(Y1(0), Y1(1))
R2xmin = menor(X1(2), X1(3))
R2xmax = mayor(X1(2), X1(3))

R2ymin = menor(Y1(2), Y1(3))


R2ymax = mayor(Y1(2), Y1(3))
copiar(X1, XA, 4)
REM limites(XA, xmin, xmax)
REM Console.WriteLine(" valores de xmin {0} xmax {1} ", xmin, xmax)
resultado = 0
copiar(Y1, YA, 4)
REM limites(YA, ymin, ymax)
If (X1(0) = X1(2) And Y1(0) = Y1(2)) Or (X1(0) = X1(3) And Y1(0) = Y1(3)) Or
(X1(1) = X1(2) And Y1(1) = Y1(2)) Or (X1(1) = X1(3) And Y1(1) = Y1(3)) Then
resultado = 0
Else
REM resultado = 1
px = ((X1(0) * Y1(1) - Y1(0) * X1(1)) * (X1(2) - X1(3)) - (X1(0) - X1(1)) *
(X1(2) * Y1(3) - Y1(2) * X1(3))) / ((X1(0) - X1(1)) * (Y1(2) - Y1(3)) - (Y1(0) - Y1(1)) *
(X1(2) - X1(3)))
py = ((X1(0) * Y1(1) - Y1(0) * X1(1)) * (Y1(2) - Y1(3)) - (Y1(0) - Y1(1)) *
(X1(2) * Y1(3) - Y1(2) * X1(3))) / ((X1(0) - X1(1)) * (Y1(2) - Y1(3)) - (Y1(0) - Y1(1)) *
(X1(2) - X1(3)))
If px >= R1xmin And px <= R1xmax And px >= R2xmin And px <= R2xmax
And py >= R1ymin And py <= R1ymax And py >= R2ymin And py <= R2ymax
Then
resultado = 1
Else
resultado = 0
End If
End If
Return resultado
End Function
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single) As Single
distancia = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
End Function
Sub IniciarMatriz(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 0
Next
Next
End Sub
Public Sub generarPuntos(ByRef X() As Single, ByRef Y() As Single, ByVal nf
As Integer)
Dim fila As Integer
For fila = 0 To nf - 1

X(fila) = Int(Rnd() * 600)


Y(fila) = Int(Rnd() * 400)
Next
X(fila) = X(0)
Y(fila) = Y(0)
End Sub
Public Sub RecuperarPuntos(ByVal X() As Single, ByVal Y() As Single, ByVal nf
As Integer)
Dim fila As Integer
Dim cadena As String
Dim pos As Integer
Dim srLector = New StreamReader("E:\datos\Puntos2x6.txt")
REM Dim srLector = New StreamReader("E:\datos\Puntos2x10.txt")
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
pos = InStr(1, cadena, Chr(9))
X(fila) = Mid(cadena, 1, pos - 1)
Y(fila) = Mid(cadena, pos + 1, Len(cadena))
Next
X(fila) = X(0)
Y(fila) = Y(0)
srLector.Close()
End Sub
Sub Imprimir(ByVal X() As Single, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.Write(" {0} ", X(fila))
Next
End Sub
Sub copiar(ByVal A() As Single, ByRef B() As Single, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
B(fila) = A(fila)
Next
End Sub
Sub Ordenar(ByVal A() As Single, ByVal np As Integer)
Dim fila As Integer
Dim col As Integer
Dim temp As Single
For fila = 0 To np - 2
For col = fila + 1 To np - 1
If (A(col) < A(fila)) Then
temp = A(fila)
A(fila) = A(col)
A(col) = temp
End If
Next col

Next fila
End Sub
Sub OrdenarMatriz(ByRef A(,) As Single, ByVal ne As Integer)
Dim fila As Integer
Dim col As Integer
Dim temp(6) As Single
For fila = 0 To ne - 2
For col = fila + 1 To ne - 1
If (A(col, 5) < A(fila, 5)) Then
For k = 0 To 6
temp(k) = A(fila, k)
Next
For k = 0 To 6
A(fila, k) = A(col, k)
Next
For k = 0 To 6
A(col, k) = temp(k)
Next
End If
Next col
Next fila
End Sub
Sub ObtenerVectores(ByVal A(,) As Single, ByRef AX() As Single, ByRef AY() As
Single, ByVal Nf As Integer, ByVal Nc As Integer)
AX(0) = A(Nf, 0)
AX(1) = A(Nf, 2)
AX(2) = A(Nc, 0)
AX(3) = A(Nc, 2)
AY(0) = A(Nf, 1)
AY(1) = A(Nf, 3)
AY(2) = A(Nc, 1)
AY(3) = A(Nc, 3)
End Sub
Sub GrabarMatriz(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As
Integer)
Dim swEscritor = New StreamWriter("e:\DATOS\matriz6xn.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
End Module

Imports System.Drawing
Public Class Form1
Dim Grafico As Graphics
Dim Color As Color
Dim Pantalla As Bitmap
Dim Pict1 As Bitmap
Const maxfilas As Integer = 810, maxcol As Integer = 810
Dim alto As Integer = maxfilas, ancho As Integer = maxcol
Dim Rojos(maxfilas, maxcol) As Integer, Verdes(maxfilas, maxcol) As
Integer, Azules(maxfilas, maxcol) As Integer
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub CopiarMatriz(ByVal A(,) As Integer, ByVal B(,) As Integer, ByVal nf As
Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
B(fila, col) = A(fila, col)
Next
Next
End Sub
Sub MostrarMatriz(ByVal cx As Integer, ByVal cy As Integer, ByVal nf As
Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Pantalla.SetPixel(cx + col, cy + fila, Color.FromArgb(Rojos(fila, col),
Verdes(fila, col), Azules(fila, col)))
Next
Next

PictureBox2.Image = Pantalla
End Sub
Sub Crecer(ByRef nf As Integer, ByRef nc As Integer)
Dim Rojos1(maxfilas, maxcol) As Integer
Dim Verdes1(maxfilas, maxcol) As Integer
Dim Azules1(maxfilas, maxcol) As Integer
Dim fila As Integer, col As Integer, cf As Integer = 0, cc As Integer = 0
For fila = 0 To nf - 1
cc = 0
For col = 0 To nc - 1
Rojos1(cf, cc) = Rojos(fila, col)
Verdes1(cf, cc) = Verdes(fila, col)
aZULES1(cf, cc) = Azules(fila, col)
cc = cc + 1
Rojos1(cf, cc) = Rojos(fila, col)
Verdes1(cf, cc) = Verdes(fila, col)
Azules1(cf, cc) = Azules(fila, col)
cc = cc + 1
Next col
cf = cf + 1
cc = 0
For col = 0 To nc - 1
Rojos1(cf, cc) = Rojos(fila, col)
Verdes1(cf, cc) = Verdes(fila, col)
Azules1(cf, cc) = Azules(fila, col)
cc = cc + 1
Rojos1(cf, cc) = Rojos(fila, col)
Verdes1(cf, cc) = Verdes(fila, col)
Azules1(cf, cc) = Azules(fila, col)
cc = cc + 1
Next col
cf = cf + 1
Next fila
nf = cf
nc = cc
CopiarMatriz(Rojos1, Rojos, nf, nc)
CopiarMatriz(Verdes1, Verdes, nf, nc)
CopiarMatriz(Azules1, Azules, nf, nc)
End Sub
Private Sub Graficar(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim contador As Integer = 1
Dim nelementos As Integer = 3
Dim cx As Integer = 10, cy As Integer = 10
Dim nf As Integer = 100, nc As Integer = 100
PictureBox2.BackColor = Color.FromArgb(255, 255, 255)

For fila = 0 To nf - 1
For col = 0 To nc - 1
Color = Pict1.GetPixel(col, fila)
Rojos(fila, col) = Color.R
Verdes(fila, col) = Color.G
Azules(fila, col) = Color.B
Next col
Next
For contador = 1 To nelementos
Crecer(nf, nc)
MostrarMatriz(cx, cy, nf, nc)
PictureBox2.Refresh()
Sleep(100)
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PictureBox2.Width = ancho
PictureBox2.Height = alto
Pantalla = New Bitmap(PictureBox2.Width, PictureBox2.Height)
Pict1 = New Bitmap("e:\datos\foto1.bmp")
Grafico = PictureBox2.CreateGraphics
End Sub
End Class

Programa de rompecabezas

Public Class Form1


Dim nf As Integer = 3
Dim nc As Integer = 3
Dim fila, col As Integer
Dim Cx As Integer = 0 '0
Dim Cy As Integer = 0
Dim nombre As String
Dim grafico As Graphics
Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles
btnIniciar.Click
DataGridView1.RowCount = nf
DataGridView1.ColumnCount = nc
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 40
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = fila & "," & col
Next
Next
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs)
Handles TextBox1.KeyDown

DataGridView1.Rows(Cy).Cells(Cx).Value = nombre
Select Case e.KeyCode
Case 88 ' TRASLACION EJE X
If Cx < nc - 1 Then Cx = Cx + 1
Case 89 ' TRASLACION EJE Y
If Cy < nf - 1 Then Cy = Cy + 1
Case 65 ' a
If Cx > 0 Then Cx = Cx - 1
Case 66 ' b
If Cy > 0 Then Cy = Cy - 1
End Select
nombre = DataGridView1.Rows(Cy).Cells(Cx).Value
DataGridView1.Rows(Cy).Cells(Cx).Value = "Gato"
TextBox1.Clear()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
Handles TextBox1.TextChanged
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
grafico = PictureBox2.CreateGraphics
' Create image.
Dim newImage(4)
newImage(0) = Image.FromFile("E:\datos\auto1.bmp")
newImage(1) = Image.FromFile("E:\datos\auto2.bmp")
'Dim newImage As Image = ImageList(1)
' Create Point for upper-left corner of image.
Dim ulCorner As New Point(100, 100)
' Draw image to screen.
grafico.DrawImage(newImage(0), 100, 100)
grafico.DrawImage(newImage(1), 200, 120)

End Sub
End Class

PUNTO
S
X
Y
0
7
6
1 16
5
2 24
4
3 40
2
4 45
2
5 50
6
6 43
6
7 38
7
8 32
8
9 25
9
10 28
9
11 22
9
12
9 10
13 10 13
14 31 12
15 34 15
16 12 16
17 13 19
18 27 19
19 29 18
20 28 21
21 14 21
22 14 24
23 30 23
24 39 23
25 43 23
26 43 20
27 41 18
28 44 23
29 46 16
30 44 13
31 49 18
32 56 12
33 59 15
34 51 15

R
1 R2 R3 R4
0
1 12 -1
2
0 11
2
4
1
3 10
6
2
4
6
8
3
5 -1
10
4
6 32
12
3
7 31
14
6 30
8
16
9
7 -1
18
8 10 -1
20
2 11 14
22
1 10 12
24
0 11 13
26 12 16 14
28 15 10 13
30 14 16 39
32 13 17 15
34 16 18 21
36 17 20 19
38 39 18 24
40 18 21 23
42 17 22 20
44 21 23 -1
46 22 20 24
48 23 25 19
50 24 26 37
52 27 25 36
54 26 28 -1
56 39 27 29
58 28 34 30
60 31
7 29
62 30 32 -1
64 33
5 -1
66 32 38 -1
68 29 33 -1

35
36
37
38
39

53
56
58
63
40

18
19
21
21
16

70
72
74
76
78

36
37
25
37
19

34
35
38
33
15

27
-1
36
-1
28

GRAFICA DE PUNTOS MEJORADO

Module Module1
Sub Main()
' todo tiene que ser en archivo
IniciarPantalla(A, nf, nc)
Iniciar(PuntosRelaciones, np, np)
Iniciar(Relaciones, np, np)
recuperar(X, Y, np)
imprimir(X, Y, np)
RecuperarPuntosRelaciones(PuntosRelaciones, np, np)
FormarRelaciones(PuntosRelaciones, Relaciones, np, np)
'MostrarMatriz(Relaciones, np, np)
Graficar(X, Y, Relaciones, np, np)
'GrabarMatriz(Relaciones, np, np)
GrabarMatriz(A, nf, nc)
Console.ReadLine()

End Sub
End Module
Imports System.IO
Module Module2
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim srLector As StreamReader
Dim swEscritor As StreamWriter
Public Const NFilas As Integer = 50, NCol As Integer = 55, npuntos = 40
Public relleno(NCol) As Integer
Public A(NFilas, NCol) As Integer
Public PuntosRelaciones(npuntos, npuntos) As Integer
Public Relaciones(npuntos, npuntos) As Integer
Public X(npuntos) As Integer
Public Y(npuntos) As Integer
Public np As Integer = npuntos, k As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Sub FormarRelaciones(ByVal A(,) As Integer, ByRef R(,) As Integer, ByVal nf As
Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) >= 0 Then
R(fila, A(fila, col)) = 1
End If
Next
Next
End Sub
Sub Graficar(ByVal X() As Integer, ByVal Y() As Integer, ByRef R(,) As Integer,
ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single
For fila = 0 To nf - 1
For col = 0 To nc - 1
If R(fila, col) = 1 Then
If fila <= col Then
x1 = X(fila)
y1 = Y(fila)
x2 = X(col)
y2 = Y(col)
Else
x1 = X(col)
y1 = Y(col)
x2 = X(fila)

y2 = Y(fila)
End If
linea(x1, y1, x2, y2)
End If
Next
Next
REM poner la ubicaciones de los puntos
For fila = 0 To nf - 1
Console.CursorLeft = X(fila)
Console.CursorTop = Y(fila)
Console.Write("{0}", fila + 1)
A(Y(fila), X(fila)) = fila + 1
Next
End Sub
Sub Iniciar(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = -1
Next
Next
End Sub
Sub IniciarPantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 99
Next
Next
End Sub
Public Sub MostrarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
Console.WriteLine()
For col = 0 To nc - 1
Console.Write("{0} ", A(fila, col))
Next
Next
End Sub
Public Sub GrabarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)

Dim fila As Integer, col As Integer


Dim dato As Integer
swEscritor = New StreamWriter("e:\DATOS\Matriz55x50.txt")
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) >= 0 Then
dato = A(fila, col)
End If
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Public Sub RecuperarPuntosRelaciones(ByVal A(,) As Integer, ByVal nf As
Integer, ByVal nc As Integer)
srLector = New StreamReader("e:\DATOS\Relaciones3X40.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub

Sub recuperar(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As Integer)


Dim srLector = New StreamReader("e:\DATOS\puntos2x40x55x50.txt")
'Dim srLector = New StreamReader("e:\DATOS\untos5.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine(" {0} {1} {2}", fila, X(fila), Y(fila))
Next
End Sub
End Module
Module Module3
Dim dist As Single
Dim menor As Single
Function distanciaEuclidiana(ByVal x1 As Single, ByVal y1 As Single, ByVal x2
As Single, ByVal y2 As Single)
distanciaEuclidiana = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
End Function
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
distancia = Math.Abs(x2 - x1) + Math.Abs(y2 - y1)
End Function
Function Area(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
Area = Math.Abs(x2 - x1) * Math.Abs(y2 - y1)
End Function
Function AreaTri(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single, _
ByVal x3 As Single, ByVal y3 As Single)

Dim a As Single, b As Single, c As Single, p As Single, s As Single


a = distanciaEuclidiana(x1, y1, x2, y2)
b = distanciaEuclidiana(x2, y2, x3, y3)
c = distanciaEuclidiana(x3, y3, x1, y1)
p = (a + b + c) / 2
s = Math.Sqrt(p * (p - a) * (p - b) * (p - c))
Return s
End Function
Sub linea(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal
y2 As Integer)
Dim px As Single, py As Single
Dim cx1 As Single, cy1 As Single
Dim area1 As Single, AreaMenor As Single
Dim xini As Single, yini As Single
Dim d1 As Single
Dim cont As Integer = 0
xini = x1
yini = y1
px = x1
py = y1
cx1 = px
cy1 = py
menor = distancia(px, py, x2, y2)
Console.CursorLeft = x1
Console.CursorTop = y1
Console.Write("1")
Do
AreaMenor = 100
px = x1
py = y1
cx1 = px
cy1 = py
d1 = distancia(px + 1, py, x2, y2)
If d1 <= menor Then
menor = d1
area1 = AreaTri(xini, yini, px + 1, py, x2, y2)
If area1 < AreaMenor Then
AreaMenor = area1
cx1 = px + 1
cy1 = py
End If
End If
d1 = distancia(px, py - 1, x2, y2)
If d1 <= menor Then
menor = d1
area1 = AreaTri(xini, yini, px, py - 1, x2, y2)

If area1 < AreaMenor Then


AreaMenor = area1
cx1 = px
cy1 = py - 1
End If
End If
d1 = distancia(px - 1, py, x2, y2)
If d1 <= menor Then
menor = d1
area1 = AreaTri(xini, yini, px - 1, py, x2, y2)
If area1 < AreaMenor Then
AreaMenor = area1
cx1 = px - 1
cy1 = py
End If
End If
d1 = distancia(px, py + 1, x2, y2)
If d1 <= menor Then
menor = d1
area1 = AreaTri(xini, yini, px, py + 1, x2, y2)
If area1 < AreaMenor Then
AreaMenor = area1
cx1 = px
cy1 = py + 1
End If
End If
x1 = cx1
y1 = cy1
Console.CursorLeft = x1
Console.CursorTop = y1
Console.WriteLine("*")
A(y1, x1) = 0
cont = cont + 1
Loop While menor > 1
End Sub
End Module
MODO GRAFICO

Option Explicit On
Imports System.Drawing
Public Class Form1
Dim fila As Integer
Dim col As Integer
Dim tam As Integer = 2
Dim Color As Color
Dim Grafico As Graphics
Dim BrochaSolida As SolidBrush
Dim nombreArchivo As String
Dim nombreColores As String
Dim MColores(Cantidad, 3) As Integer
Sub MostrarMatrizEnPantalla(ByVal Cx As Integer, ByVal Cy As Integer, ByVal
nfilas As Integer, ByVal ncol As Integer)
Dim indice As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
indice = A(fila, col)
BrochaSolida.Color = Color.FromArgb(MColores(indice, 0),
MColores(indice, 1), MColores(indice, 2))
Grafico.FillRectangle(BrochaSolida, col * tam + Cx, fila * tam + Cy, tam,
tam)
Next col
Next fila
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
PictureBox1.Width = nc * tam + 1
PictureBox1.Height = nf * tam + 1
Grafico = PictureBox1.CreateGraphics
BrochaSOLIDA = New SolidBrush(Color.Red)
End Sub
Private Sub BtnPrincipal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrincipal.Click
Dim MiFuente As New Font("Verdana", 10 + tam, FontStyle.Bold)
Iniciar()
recuperar(X, Y, np)
IniciarPantalla(A, nf, nc)
nombreArchivo = "e:\DATOS\Matriz550x500.txt"
nombreColores = "e:\DATOS\colores3x50.txt"
RecuperarArchivo(A, nf, nc, nombreArchivo)
RecuperarArchivo(MColores, Cantidad, 3, nombreColores)
MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
'For k = 1 To 100
' crecer(A, nf, nc, np)
' MostrarMatrizEnPantalla(Cx, Cy, A, nf, nc)
'Next
ruw(Cx, Cy, nf, nc)
End Sub
Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub btnMostrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMostrar.Click
Dim MiFuente As New Font("Verdana", 10, FontStyle.Bold)
MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
BrochaSolida.Color = Color.Blue
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
BrochaSolida.Color = Color.Blue
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
Next
End Sub
Private Sub MnuBuscador_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuBuscador.Click
Dim MiFuente As New Font("Verdana", 10 + tam, FontStyle.Bold)

Iniciar()
recuperar(X, Y, np)
IniciarPantalla(A, nf, nc)
nombreArchivo = "e:\DATOS\Matriz550x500.txt"
nombreColores = "e:\DATOS\colores3x50.txt"
RecuperarArchivo(A, nf, nc, nombreArchivo)
RecuperarArchivo(MColores, Cantidad, 3, nombreColores)
MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
'For k = 1 To 100
' crecer(A, nf, nc, np)
' MostrarMatrizEnPantalla(Cx, Cy, A, nf, nc)
'Next
'MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
BrochaSolida.Color = Color.Blue
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
End Sub
Private Sub MnuBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub MnuMostrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuMostrar.Click
Dim MiFuente As New Font("Verdana", 10 + tam, FontStyle.Bold)
MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
BrochaSolida.Color = Color.Blue
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
End Sub
Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
ContextMenuStrip1.Opening
Dim MiFuente As New Font("Verdana", 10 + tam, FontStyle.Bold)
MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
BrochaSolida.Color = Color.Blue
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
End Sub
Private Sub ttam_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ttam.Click

tam = InputBox("Ingrese tamao 1..20 ", "Ingres0", 1)


PictureBox1.Width = nc * tam + 1
PictureBox1.Height = nf * tam + 1
End Sub
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim MiFuente As New Font("Verdana", 10 + tam, FontStyle.Bold)
PictureBox1.Width = nc * tam + 1
PictureBox1.Height = nf * tam + 1
MostrarMatrizEnPantalla(Cx, Cy, nf, nc)
BrochaSolida.Color = Color.Blue
For k = 0 To np - 1
Grafico.DrawString(k + 1, MiFuente, BrochaSolida, X(k) * tam, Y(k) * tam)
Next
End Sub
End Class

Imports System.IO
Module module1
'/*** declaraciones
Public Const NFilas As Integer = 500, NCol As Integer = 550, Cantidad = 50
Public Cx As Integer = 1, Cy As Integer = 1
Public srLector As StreamReader
REM Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public relleno(NCol) As Integer
Public A(NFilas, NCol) As Integer
Public B(NFilas, NCol) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public X(Cantidad) As Integer
Public Y(Cantidad) As Integer
Public np As Integer = 40, k As Integer
Public vecinos As Integer
Public Sub RecuperarArchivo(ByRef A(,) As Integer, ByVal nf As Integer, ByVal
nc As Integer, ByVal nombre As String)
srLector = New StreamReader(nombre)
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()

longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub IniciarPantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 0
Next
Next
End Sub
Sub recuperar(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos2x40x550x500.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next

srLector.Close()
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine(" {0} {1} {2}", fila, X(fila), Y(fila))
Next
End Sub
Sub Iniciar()
For fila = 0 To NFilas
relleno(fila) = fila + 1
Next
End Sub
Sub crecer(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
ByVal np As Integer)
Dim fila1 As Integer, col1 As Integer
Dim k1 As Integer
IniciarPantalla(B, nf, nc)
For fila1 = 1 To nf - 1
For col1 = 1 To nc - 1
REM si hay espacio crece si no no crece y por lo menos debe haber un
vecino
For k1 = 0 To np - 1
vecinos = 0
If A(fila1, col1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1, col1 + 1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1 + 1, col1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1, col1 - 1) = relleno(k1) Then vecinos = vecinos + 1
If A(fila1 - 1, col1) = relleno(k1) Then vecinos = vecinos + 1
If vecinos > 0 And A(fila1, col1) = 0 Then
B(fila1, col1) = relleno(k1) 'relleno(k1)
Exit For
Else
B(fila1, col1) = A(fila1, col1)
End If
Next k1
Next col1
Next fila1
IniciarPantalla(A, nf, nc)
TransferirMatriz(B, A, nf, nc)
End Sub
Sub TransferirMatriz(ByVal A(,) As Integer, ByVal B(,) As Integer, ByVal nf As
Integer, ByVal nc As Integer)
For fila = 0 To nf - 1
For col = 0 To nc - 1

B(fila, col) = A(fila, col)


Next
Next
End Sub
End Module

Imports System.IO
Module module1
Public ancho As Integer = 900
Public alto As Integer = 500
Public tam As Integer = 4
Public Cx As Integer = 0, Cy As Integer = 0
Public Matriz(NFilas, NCol) As Integer
Public Const NFilas As Integer = 250, NCol As Integer = 250, maximo
= 1500
Public Const Np As Integer = 51
Public relleno(NCol) As Integer
Public X(Np) As Integer
Public Y(Np) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public MRel(Np, Np) As Integer
Public srLector As StreamReader
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public vecinos(maximo) As Integer
Public nvecinos As Integer
Sub contavecinos(ByRef ser As Integer, ByRef Vecinos() As Integer,
ByRef nvecinos As Integer)
Dim fila As Integer, col As Integer
Dim cont = 0
Dim valor As Integer = 0
Vecinos(0) = ser
cont = 1
For fila = 1 To nf - 2
For col = 1 To nc - 2
If (Matriz(fila, col) = ser) Then
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col + 1) = Vecinos(k) Then
valor = 1

Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col + 1)
cont = cont + 1
End If
REM //2
valor = 0
For k = 0 To cont - 1
If Matriz(fila - 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila - 1, col)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col - 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col - 1)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila + 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila + 1, col)
cont = cont + 1
End If
End If
Next
Next
nvecinos = cont

End Sub
Public Sub RecuperarArchivo(ByVal A(,) As Integer, ByVal nf As Integer,
ByVal nc As Integer, ByVal nombre As String)
srLector = New StreamReader(nombre)
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub crecerCirculo(ByVal A(,) As Integer, ByVal X() As Integer, ByVal Y()
As Integer, ByVal nf As Integer, _
ByVal nc As Integer, ByVal relleno() As Integer, ByVal r As
Single, ByVal np As Integer)
Dim x1 As Integer, y1 As Integer, k As Integer
For k = 0 To np - 1
For y1 = Y(k) - r To Y(k) + r
For x1 = X(k) - r To X(k) + r
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r)
And (x1 > 0) And (x1 < NCol) And (y1 > 0) And (y1 < NFilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If

End If
Next
Next
Next
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc
As Integer, ByVal nro As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = nro
Next
Next
End Sub
Sub recuperarPuntos(ByRef X() As Integer, ByRef Y() As Integer, ByVal
ne As Integer)
Dim srLector = New
StreamReader("e:\DATOS\datostxt\PUNTOS3X51A.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub AsignarMatriz(ByRef M(,) As Integer, ByVal V() As Integer, ByVal
ne As Integer, ByVal nfila As Integer)
Dim col As Integer
For col = 0 To ne - 1
M(nfila, col) = V(col)
Next
End Sub
Sub Iniciarvector(ByVal A() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
A(fila) = -1

Next
End Sub
Sub restar(ByRef a() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
a(fila) = a(fila) - 1
Next
End Sub
End Module

Option Explicit On
Imports System.Drawing
Public Class Form1
Dim pen As Pen
Dim Color As Color
Dim Grafico As Graphics
Dim BrochaSolida As SolidBrush
Dim nombreColores As String
Dim MColores(Np, 3) As Integer
Dim Ex As Single = tam * 2
Dim ey As Single = tam
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim p1 As Integer
Dim p2 As Integer
Dim MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
ListBox1.Items.Add(" X " & X(fila))
Next
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As
Integer)
ListBox1.Items.Clear()
Dim fila As Integer
For fila = 0 To ne - 1
ListBox1.Items.Add(" X " & X(fila) & " Y " & Y(fila))
Next
End Sub

Sub MostrarMatriz(ByVal Cx As Integer, ByVal Cy As Integer, ByVal A(,)


As Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
Dim indice As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
indice = A(fila, col)
BrochaSolida.Color = Color.FromArgb(MColores(indice, 0),
MColores(indice, 1), MColores(indice, 2))
Grafico.FillRectangle(BrochaSolida, col * tam + Cx, fila * tam +
Cy, tam, tam)
Next col
Next fila
End Sub
Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub btnMostrar_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnMostrar.Click
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
End Sub
Private Sub Btncargar_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Btncargar.Click
recuperarPuntos(X, Y, Np)
imprimir(X, Y, Np)
End Sub
Private Sub btnAleatorio_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAleatorio.Click
Dim fila As Integer
For fila = 0 To Np - 1
X(fila) = 50 + Int(Rnd() * 150)
Y(fila) = 50 + Int(Rnd() * 100)
imprimir(X, Y, Np)
Next
End Sub
Private Sub BTNTRIANGULOS_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BTNTRIANGULOS.Click
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)

y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else
Grafico.DrawLine(pen, x1 * tam, y1 * tam, x2 * tam, y2 *
tam)
End If
End If
Next
Next
BrochaSolida.Color = Color.Red
For k = 0 To Np - 1
Grafico.DrawString(k, MiFuente, BrochaSolida, X(k) * tam, Y(k) *
tam)
Next
End Sub
Private Sub btnCargar_Click_1(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCargar.Click
recuperarPuntos(X, Y, Np)
imprimir(X, Y, Np)
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PictureBox1.Width = ancho
PictureBox1.Height = alto
pen = New Pen(Color.Blue, 2)
Grafico = PictureBox1.CreateGraphics
BrochaSolida = New SolidBrush(Color.Red)
nombreColores = "e:\DATOS\DATOSTXT\colores3x60.txt"
RecuperarArchivo(MColores, Np, 3, nombreColores)
End Sub
Private Sub btnPrincipal_Click_1(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnPrincipal.Click
Try
REM Dim nsr As Integer = 0

Dim fila As Integer


For fila = 0 To Np - 1
relleno(fila) = fila + 1
Next
IniciarMatriz(MRel, Np, Np, -1)
IniciarMatriz(Matriz, nf, nc, 0)
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
REM al crecer obtien cuales son sus vecinos
For r = 0 To 40
crecerCirculo(Matriz, X, Y, nf, nc, relleno, r, Np)
Next
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
For fila = 0 To Np - 1
contavecinos(relleno(fila), vecinos, nvecinos)
restar(vecinos, nvecinos)
AsignarMatriz(MRel, vecinos, nvecinos, fila)
ListBox1.Items.Add("ser " & relleno(fila))
imprimirVector(vecinos, nvecinos)
Next
' graficar
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)
y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else
Grafico.DrawLine(pen, x1 * tam, y1 * tam, x2 * tam, y2
* tam)
End If
End If
Next
Next
BrochaSolida.Color = Color.Red
For k = 0 To Np - 1
Grafico.DrawString(k, MiFuente, BrochaSolida, X(k) * tam, Y(k)
* tam)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
End Class
Con 500 puntos aletorio

VER EN 3D y la grabacin y opengl

TRIANGULACION

Imports System.IO
Module module1
Public encontrado1 As Integer = 0
Public encontrado2 As Integer = 0
Public P3 As Integer
Public ntrifinales As Integer = 1
Public vP1(maximo) As Integer
Public vP2(maximo) As Integer
Public Ntri As Integer
Public contri As Integer
Public Ntriangulos As Integer
Public nfinaltriangulos As Integer
Public Tri(maximo, 3) As Integer
Public Trifinal(Np * 2, 2) As Integer
Public CANTTF As Integer
REM *************************
Public cont As Integer = 0
Public pen As Pen
Public Color As Color
Public Grafico As Graphics

Public BrochaSolida As SolidBrush


Public nombreColores As String
Public MColores(Np, 3) As Integer
Public Ex As Single = 40
Public ey As Single = 50
Public x1 As Integer
Public y1 As Integer
Public x2 As Integer
Public y2 As Integer
Public p1 As Integer
Public p2 As Integer
Public MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Public alto As Integer = 500
Public ancho As Integer = 500
Public tam As Integer = 10
Public Cx As Integer = 0, Cy As Integer = 0
Public Matriz(NFilas, NCol) As Integer
REM Public Const NFilas As Integer = 200, NCol As Integer = 300, maximo =
500
Public Const NFilas As Integer = 15, NCol As Integer = 15, maximo = 50
Public Const Np As Integer = 6
Public relleno(NCol) As Integer
Public X(Np) As Integer
Public Y(Np) As Integer
Public nf As Integer = NFilas, nc As Integer = NCol
Public MRel(Np, Np) As Integer
Public srLector As StreamReader
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public vecinos(maximo) As Integer
Public nvecinos As Integer
Sub contavecinos(ByRef ser As Integer, ByRef Vecinos() As Integer, ByRef
nvecinos As Integer)
Dim fila As Integer, col As Integer
Dim cont = 0
Dim valor As Integer = 0
Vecinos(0) = ser
cont = 1
For fila = 1 To nf - 2
For col = 1 To nc - 2
If (Matriz(fila, col) = ser) Then
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col + 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next

If valor = 0 Then
Vecinos(cont) = Matriz(fila, col + 1)
cont = cont + 1
End If
REM //2
valor = 0
For k = 0 To cont - 1
If Matriz(fila - 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila - 1, col)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila, col - 1) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila, col - 1)
cont = cont + 1
End If
valor = 0
For k = 0 To cont - 1
If Matriz(fila + 1, col) = Vecinos(k) Then
valor = 1
Exit For
End If
Next
If valor = 0 Then
Vecinos(cont) = Matriz(fila + 1, col)
cont = cont + 1
End If
End If
Next
Next
nvecinos = cont
End Sub
Public Sub RecuperarArchivo(ByVal A(,) As Integer, ByVal nf As Integer, ByVal
nc As Integer, ByVal nombre As String)
srLector = New StreamReader(nombre)

Dim cadena As String


Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
Dim inicio As Integer = 1
Dim cont As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
inicio = 1
cont = 0
Do
pos = InStr(inicio, cadena, Chr(9))
If pos > 0 Then
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, cont) = Val(subcadena)
inicio = pos + 1
cont += 1
Else
subcadena = Mid(cadena, inicio, longitud - inicio + 1)
A(fila, cont) = Val(subcadena)
cont += 1
Exit Do
End If
Loop While (inicio <= longitud)
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub crecerCirculo(ByVal A(,) As Integer, ByVal X() As Integer, ByVal Y() As
Integer, ByVal nf As Integer, _
ByVal nc As Integer, ByVal relleno() As Integer, ByVal r As Single, ByVal
np As Integer)
Dim x1 As Integer, y1 As Integer, k As Integer
For k = 0 To np - 1
For y1 = Y(k) - r To Y(k) + r
For x1 = X(k) - r To X(k) + r
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r) And (x1 >
0) And (x1 < NCol) And (y1 > 0) And (y1 < NFilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If
End If
Next
Next
Next
End Sub

Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,


ByVal nro As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = nro
Next
Next
End Sub
Sub recuperarPuntos(ByRef X() As Integer, ByRef Y() As Integer, ByVal ne As
Integer)
Dim srLector = New StreamReader("e:\DATOS\puntos2x6.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer = 0
Dim longitud As String
For fila = 0 To ne - 1
cadena = srLector.ReadLine()
longitud = Len(cadena)
pos = InStr(1, cadena, Chr(9)) ' pos tabulador
If pos > 0 Then
subcadena = Mid(cadena, 1, pos - 1)
X(fila) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, longitud)
Y(fila) = Val(subcadena)
End If
Next
srLector.Close()
End Sub
Sub AsignarMatriz(ByRef M(,) As Integer, ByVal V() As Integer, ByVal ne As
Integer, ByVal nfila As Integer)
Dim col As Integer
For col = 0 To ne - 1
M(nfila, col) = V(col)
Next
End Sub
Sub Iniciarvector(ByVal A() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
A(fila) = -1
Next
End Sub
Sub restar(ByRef a() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
a(fila) = a(fila) - 1
Next

End Sub
End Module
Option Explicit On
Imports System.Drawing
Imports System.IO
Public Class Form1
Sub imprimirVector(ByVal X() As Integer, ByVal ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
ListBox1.Items.Add(" X " & X(fila))
Next
End Sub
Sub imprimir(ByVal X() As Integer, ByVal Y() As Integer, ByVal ne As Integer)
ListBox1.Items.Clear()
Dim fila As Integer
For fila = 0 To ne - 1
ListBox1.Items.Add(" X " & X(fila) & " Y " & Y(fila))
Next
End Sub
Sub MostrarMatriz(ByVal Cx As Integer, ByVal Cy As Integer, ByVal A(,) As
Integer, ByVal nfilas As Integer, ByVal ncol As Integer)
Dim indice As Integer
For fila = 0 To nfilas - 1
For col = 0 To ncol - 1
indice = A(fila, col)
BrochaSolida.Color = Color.FromArgb(MColores(indice, 0),
MColores(indice, 1), MColores(indice, 2))
Grafico.FillRectangle(BrochaSolida, col * Ex + Cx, fila * ey + Cy, Ex, ey)
Next col
Next fila
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PictureBox1.Width = ancho
PictureBox1.Height = ALTO
pen = New Pen(Color.Blue, 2)
Grafico = PictureBox1.CreateGraphics
BrochaSolida = New SolidBrush(Color.Red)
nombreColores = "e:\DATOS\colores3x50.txt"
RecuperarArchivo(MColores, Np, 3, nombreColores)
End Sub

Private Sub BtnPrincipal_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnPrincipal.Click
Dim p11 As Integer = 0
Dim p22 As Integer = 0
Dim swEscritor As StreamWriter
Try
Dim fila As Integer
For fila = 0 To Np - 1
relleno(fila) = fila + 1
Next
IniciarMatriz(MRel, Np, Np, -1)
IniciarMatriz(Matriz, nf, nc, 0)
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
REM al crecer obtien cuales son sus vecinos
For r = 0 To 20
crecerCirculo(Matriz, X, Y, nf, nc, relleno, r, Np)
Next
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
For fila = 0 To Np - 1
contavecinos(relleno(fila), vecinos, nvecinos)
restar(vecinos, nvecinos)
AsignarMatriz(MRel, vecinos, nvecinos, fila)
ListBox1.Items.Add("ser " & relleno(fila))
imprimirVector(vecinos, nvecinos)
Next
' graficar formar vectores para triangulos
cont = 0
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)
y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else
vP1(cont) = p1
vP2(cont) = p2
cont = cont + 1
Grafico.DrawLine(pen, x1 * Ex, y1 * ey, x2 * Ex, y2 * ey)
End If
End If

Next
Next
Ntri = cont
For fila = 0 To Ntri - 1
p11 = vP1(fila)
p22 = vP2(fila)
For col = 0 To Np - 1
If col <> p11 And col <> p22 Then
P3 = col
encontrado1 = 0
encontrado2 = 0
' buscar si el primero esta con el tres
For k = 0 To Ntri - 1
If P3 = vP1(k) And p11 = vP2(k) Then
encontrado1 = 1
Exit For
End If
Next
For k = 0 To Ntri - 1
If P3 = vP1(k) And p22 = vP2(k) Then
encontrado2 = 1
Exit For
End If
Next
If encontrado1 = 1 And encontrado2 = 1 Then
Tri(contri, 0) = p11
Tri(contri, 1) = p22
Tri(contri, 2) = P3
Tri(contri, 3) = 0
contri = contri + 1
End If
End If
Next
Next
Trifinal(0, 0) = Tri(0, 0)
Trifinal(0, 1) = Tri(0, 1)
Trifinal(0, 2) = Tri(0, 2)
Dim r1 As Integer
Dim r2 As Integer
Dim r3 As Integer

Ntriangulos = Ntri
For fila = 0 To Ntriangulos - 1
p1 = Tri(fila, 0)
p2 = Tri(fila, 1)
P3 = Tri(fila, 2)
r1 = 0
r2 = 0
r3 = 0
For COL = 0 To ntrifinales - 1
If p1 = Trifinal(COL, 0) Or p1 = Trifinal(COL, 1) Or p1 = Trifinal(COL, 2)
Then r1 = 1
If p2 = Trifinal(COL, 0) Or p2 = Trifinal(COL, 1) Or p2 = Trifinal(COL, 2)
Then r2 = 1
If P3 = Trifinal(COL, 0) Or P3 = Trifinal(COL, 1) Or P3 = Trifinal(COL,
2) Then r3 = 1
Next
If fila = 3 Then
fila = 3
End If
If r1 = 1 And r2 = 1 And r3 = 1 Then
Else
Trifinal(ntrifinales, 0) = p1
Trifinal(ntrifinales, 1) = p2
Trifinal(ntrifinales, 2) = P3
ntrifinales = ntrifinales + 1
End If
Next
CANTTF = ntrifinales
swEscritor = New StreamWriter("E:\DATOS\TRELACIONES.txt")
For fila = 0 To ntrifinales - 1
swEscritor.WriteLine("{0}{1} {2} {3} {4}", Trifinal(fila, 0), Chr(9), Trifinal(fila,
1), Chr(9), Trifinal(fila, 2), Chr(9), Trifinal(fila, 2))
Next
swEscritor.Close()
' depurar triangulos
BrochaSolida.Color = Color.Red
For k = 0 To Np - 1
Grafico.DrawString(k, MiFuente, BrochaSolida, X(k) * Ex, Y(k) * ey)
Next
Catch ex As Exception

MsgBox(ex.Message)
End Try
End Sub
Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub btnMostrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnMostrar.Click
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
End Sub
Private Sub Btncargar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCargar.Click
recuperarPuntos(X, Y, Np)
imprimir(X, Y, Np)
End Sub
Private Sub btnAleatorio_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnaleatorio.Click
Dim fila As Integer
For fila = 0 To Np - 1
X(fila) = 50 + Int(Rnd() * 150)
Y(fila) = 50 + Int(Rnd() * 100)
imprimir(X, Y, Np)
Next
End Sub
Private Sub BTNTRIANGULOS_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnTriangulos.Click
For fila = 0 To Np - 1
p1 = MRel(fila, 0)
x1 = X(p1)
y1 = Y(p1)
For col = 1 To Np - 1
p2 = MRel(fila, col)
If MRel(fila, col) >= 0 Then
x2 = X(p2)
y2 = Y(p2)
If x1 = x2 And y1 = y2 Then
Else
Grafico.DrawLine(pen, x1 * Ex, y1 * ey, x2 * Ex, y2 * ey)
End If

End If
Next
Next
BrochaSolida.Color = Color.Red
For k = 0 To Np - 1
Grafico.DrawString(k, MiFuente, BrochaSolida, X(k) * Ex, Y(k) * ey)
Next
End Sub
End Class
a clase con las funciones del API
Imports Microsoft.VisualBasic
Imports System
' Para DllImport
Imports System.Runtime.InteropServices
Namespace elGuille.Util
Public Class WinAPI
' Constantes para SetWindowsPos
'

Valores de wFlags

Const SWP_NOSIZE As Integer = &H1


Const SWP_NOMOVE As Integer = &H2
Const SWP_NOACTIVATE As Integer = &H10
Const wFlags As Integer = SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE
'

Valores de hwndInsertAfter

Const HWND_TOPMOST As Integer = -1


Const HWND_NOTOPMOST As Integer = -2
'
''' <summary>
''' Para mantener la ventana siempre visible
''' </summary>
''' <remarks>No utilizamos el valor devuelto</remarks>
<DllImport("user32.DLL")> _
Private Shared Sub SetWindowPos( _
ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, _
ByVal X As Integer, ByVal Y As Integer, _

ByVal cx As Integer, ByVal cy As Integer, _


ByVal wFlags As Integer)
End Sub
Public Shared Sub SiempreEncima(ByVal handle As Integer)
SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, wFlags)
End Sub
Public Shared Sub NoSiempreEncima(ByVal handle As Integer)
SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags)
End Sub
End Class
End Namespace

El cdigo de la aplicacin de ejemplo


Imports siempreEncima_vb.elGuille.Util
Public Class Form1
Private frm2 As Form2
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.btnEncima.Enabled = False
Me.btnNoEncima.Enabled = False
End Sub
Private Sub btnMostrar_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnMostrar.Click
If frm2 Is Nothing OrElse frm2.IsDisposed Then
frm2 = New Form2
End If
frm2.Show()

Me.btnEncima.Enabled = True
Me.btnNoEncima.Enabled = True
End Sub
Private Sub btnEncima_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnEncima.Click
If frm2 Is Nothing OrElse frm2.IsDisposed Then
frm2 = New Form2
frm2.Show()
End If
WinAPI.SiempreEncima(frm2.Handle.ToInt32)
End Sub
Private Sub btnNoEncima_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnNoEncima.Click
If frm2 Is Nothing OrElse frm2.IsDisposed Then
frm2 = New Form2
frm2.Show()
End If
WinAPI.NoSiempreEncima(frm2.Handle.ToInt32)
End Sub
End Class

El cdigo para C# (cualquier versin)


La clase con las declaraciones del API
using System;
// Para DllImport
using System.Runtime.InteropServices;

namespace siempreEncima_cs
{
namespace elGuille.Util
{
public class WinAPI
{
// Constantes para SetWindowsPos
//

Valores de wFlags

const int SWP_NOSIZE = 0x1;


const int SWP_NOMOVE = 0x2;
const int SWP_NOACTIVATE = 0x10;
const int wFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE;
//

Valores de hwndInsertAfter

const int HWND_TOPMOST = -1;


const int HWND_NOTOPMOST = -2;
//
/// <summary>
/// Para mantener la ventana siempre visible
/// </summary>
/// <remarks>No utilizamos el valor devuelto</remarks>
[DllImport("user32.DLL")]
private extern static void SetWindowPos(
int hWnd, int hWndInsertAfter,
int X, int Y,
int cx, int cy,
int wFlags);
public static void SiempreEncima(int handle)
{
SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, wFlags);
}
public static void NoSiempreEncima(int handle)
{
SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags);
}
}

}
}

El cdigo del formulario principal


using System;
using System.Drawing;
using System.Windows.Forms;
using siempreEncima_cs.elGuille.Util;
namespace siempreEncima_cs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Form2 frm2;
private void Form1_Load(Object sender, EventArgs e)
{
this.btnEncima.Enabled = false;
this.btnNoEncima.Enabled = false;
}
private void btnMostrar_Click(Object sender, EventArgs e)
{
if (frm2 == null || frm2.IsDisposed)
{
frm2 = new Form2();
}
frm2.Show();
this.btnEncima.Enabled = true;
this.btnNoEncima.Enabled = true;

}
private void btnEncima_Click(Object sender, EventArgs e)
{
if (frm2 == null || frm2.IsDisposed)
{
frm2 = new Form2();
frm2.Show();
}
WinAPI.SiempreEncima(frm2.Handle.ToInt32());
}
private void btnNoEncima_Click(Object sender, EventArgs e)
{
if (frm2 == null || frm2.IsDisposed)
{
frm2 = new Form2();
frm2.Show();
}
WinAPI.NoSiempreEncima(frm2.Handle.ToInt32());
}
}
}

Arreglar

Option Explicit On
Option Strict On
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha As SolidBrush
Dim npuntos As Integer = 1000
Dim lx As Single = 3
Dim ly As Single = 0
Dim lambda As complexNum
Dim z0 As complexNum
Dim zx As Single = 1.5
Dim zy As Single = 0.4
'// Establace los limites de las coordenadas del plano complejo
Public xComplexMin As Single = -0.25 ' -200 * 4 '-2.0
Public xComplexMax As Single = 1.25 ' 50 * 8 ' 0.5
Public yComplexMin As Single = -0.75 '-125 * 4 '-1.25
Public yComplexMax As Single = 0.75 '125 * 4 '1.25
Public Ex As Single = 100
Public Ey As Single = 100
Public Cx As Single = 200
Public cy As Single = 200
Public Structure complexNum
Public x As Single

Public y As Single
End Structure
Sub solveQuadraticEq(ByVal lambda As complexNum, ByRef z As complexNum)
Dim lambdaMagSq, DscrMag As Single
Dim discscr As complexNum
Static fourOverLambda As complexNum
fourOverLambda.x = 0
fourOverLambda.y = 0
Static firstPoint As Boolean = True
If firstPoint = True Then
' calcula el numero compleo 4 dividido por lambda
lambdaMagSq = lambda.x * lambda.x + lambda.y * lambda.y
fourOverLambda.x = 4 * lambda.x / lambdaMagSq
fourOverLambda.y = -4 * lambda.y / lambdaMagSq
firstPoint = False
End If
discscr.x = 1 - z.x * fourOverLambda.x + z.y * fourOverLambda.y
discscr.y = z.x * fourOverLambda.y + z.y * fourOverLambda.x
DscrMag = CSng(Math.Sqrt(discscr.x * discscr.x + discscr.y * discscr.y))
If (DscrMag + discscr.x < 0) Then
z.x = 0
Else
z.x = CSng(Math.Sqrt((DscrMag - discscr.x) / 2))
End If
If (DscrMag - discscr.x < 0) Then
z.y = 0
Else
z.y = CSng(0.5 * CSng(Math.Sqrt((DscrMag - discscr.x) / 2)))
End If
'If (Rnd() < 0.5) Then
' z.x = -z.x
' z.y = -z.y
'End If
If discscr.y < 0 Then
z.x = -z.x
z.x = CSng(0.5 * (1 - z.x))
End If
End Sub
Sub plotPoint(ByVal z As complexNum)
Grafico.FillRectangle(brocha, Cx + z.x * Ex, cy + z.y * Ey, 14, 14)
End Sub
Sub SelfSqTransf(ByRef lambda As complexNum, ByVal z As complexNum, ByVal
NumPoints As Integer)
Dim k As Integer
' salta los primeros puntos
For k = 0 To 10 - 1
solveQuadraticEq(lambda, z)

Next
For k = 0 To NumPoints - 1
solveQuadraticEq(lambda, z)
plotPoint(z)
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
Pen = New Pen(Color.Red, 2)
brocha = New SolidBrush(Color.FromArgb(255, 0, 0))
End Sub
Private Sub BtnFractal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnFractal.Click
btnIniciarTodo_Click(sender, e)
lambda.x = lx
lambda.y = ly
z0.x = zx
z0.y = zy
SelfSqTransf(lambda, z0, npuntos)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnIniciar.Click
DataGridView1.ColumnCount = 2
DataGridView1.RowCount = 9
DataGridView1.Columns(1).Width = 70
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "VALOR"
DataGridView1.Rows(0).Cells(0).Value = "NPuntos"
DataGridView1.Rows(0).Cells(1).Value = npuntos
DataGridView1.Rows(1).Cells(0).Value = "lamdax"
DataGridView1.Rows(1).Cells(1).Value = lx
DataGridView1.Rows(2).Cells(0).Value = "lamday"
DataGridView1.Rows(2).Cells(1).Value = ly
DataGridView1.Rows(3).Cells(0).Value = "Cx"
DataGridView1.Rows(3).Cells(1).Value = Cx
DataGridView1.Rows(4).Cells(0).Value = "Cy"
DataGridView1.Rows(4).Cells(1).Value = Cy

DataGridView1.Rows(5).Cells(0).Value = "Ex"
DataGridView1.Rows(5).Cells(1).Value = Ex
DataGridView1.Rows(6).Cells(0).Value = "Ey"
DataGridView1.Rows(6).Cells(1).Value = Ey
DataGridView1.Rows(7).Cells(0).Value = "Zx"
DataGridView1.Rows(7).Cells(1).Value = Zx
DataGridView1.Rows(8).Cells(0).Value = "Zy"
DataGridView1.Rows(8).Cells(1).Value = Zy
End Sub
Private Sub btnIniciarTodo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnIniciarTodo.Click
npuntos = CInt(DataGridView1.Rows(0).Cells(1).Value)
lx = CInt(DataGridView1.Rows(1).Cells(1).Value)
ly = CInt(DataGridView1.Rows(2).Cells(1).Value)
Cx = CSng(DataGridView1.Rows(3).Cells(1).Value)
cy = CSng(DataGridView1.Rows(4).Cells(1).Value)
Ex = CSng(DataGridView1.Rows(5).Cells(1).Value)
Ey = CSng(DataGridView1.Rows(6).Cells(1).Value)
zx = CSng(DataGridView1.Rows(7).Cells(1).Value)
zy = CSng(DataGridView1.Rows(8).Cells(1).Value)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
End Class

Versin mejorada en modo DOS

Imports System.IO
Module Module2
Public camino As Integer = 0
Public Const niveles As Integer = 2
Public Const ne As Integer = 6
Public X(ne) As Integer
Public Y(ne) As Integer
Public Const maxfilas As Integer = 20
Public Const maxcol As Integer = 40
Public nf As Integer = 20
Public nc As Integer = 40
Public A(maxfilas, maxcol) As Integer
Public Cx As Integer = 1
Public Cy As Integer = 2
Sub VerMatriz(Cx As Integer, Cy As Integer, A(,) As Integer, nf As Integer, nc As
Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.SetCursorPosition(Cx + col, Cy + fila)
Console.ForegroundColor = A(fila, col)
Console.Write("{0}", A(fila, col))
Next
Next
End Sub

Sub ImPrimirSer(Cx As Integer, Cy As Integer, X() As Integer, Y() As Integer, ne


As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.ForegroundColor = 14 - fila
Console.SetCursorPosition(Cx + X(fila), Cy + Y(fila))
Console.Write("{0}", fila + 1)
Next
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByVal A(,) As Integer,
ByVal nf As Integer, ByVal nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
Next
'Form1.ListBox1.Items.Add("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Function ContarVecinos(Cx As Integer, Cy As Integer, nivel As Integer)
Dim fila, col As Integer
Dim suma As Integer = 0
Dim valor As Integer
Dim r As Integer
For fila = Cy - nivel To Cy + nivel
For col = Cx - nivel To Cx + nivel
valor = A(fila, col)
r = evaluar(col, fila)
If (valor = camino And r = 1) Then suma = suma + 1
Next
Next
Return suma
End Function

Function buscar(cx As Integer, cy As Integer)


Dim fila As Integer
Dim r1 As Integer = 0
For fila = 0 To ne - 1
If (X(fila) = cx And Y(fila) = cy) Then
r1 = 1
Exit For
End If
Next
Return r1
End Function
Function ContarCerca(cx As Integer, cy As Integer, nivel As Integer) As Integer
Dim fila As Integer
Dim suma As Integer = 0
Dim valor As Integer = 0
' cuanto vecinos mas cercanos t
For fila = cy - nivel To cy + nivel
For col = cx - nivel To cx + nivel
valor = buscar(col, fila)
If (valor = 1) Then suma = suma + 1
Next
Next
Return suma
End Function
Function Evaluar(cx As Integer, cy As Integer) As Integer
Dim r1 As Integer = 0
Dim r2 As Integer = 1
Dim r3 As Integer = 0
If (A(cy, cx) = camino) Then r1 = 1
For fila = 0 To ne - 1
If cx = X(fila) And cy = Y(fila) Then
r2 = 0
Exit For
End If
Next
If (r1 = 1 And r2 = 1) Then r3 = 1
Return r3
End Function
Function ModificarSer(X() As Integer, Y() As Integer) As Integer
Dim res As Integer
Dim Cx, Cy As Integer
Dim mayor As Integer = -1
Dim menor As Integer = 100
Dim cont As Integer = 0
Cx = X(0)
Cy = Y(0)

Dim Suma(3) As Integer


Dim smenor(3) As Integer
Dim dirMenor As Integer = 100
Dim dir1 As Integer = -1
For fila = 0 To 3
Suma(fila) = -1
smenor(fila) = 100
Next
If (Evaluar(Cx + 1, Cy) = 1) Then Suma(0) = ContarVecinos(Cx + 1, Cy,
niveles)
If (Evaluar(Cx, Cy - 1) = 1) Then Suma(1) = ContarVecinos(Cx, Cy - 1,
niveles)
If (Evaluar(Cx - 1, Cy) = 1) Then Suma(2) = ContarVecinos(Cx - 1, Cy,
niveles)
If (Evaluar(Cx, Cy + 1) = 1) Then Suma(3) = ContarVecinos(Cx, Cy + 1,
niveles)
If (Evaluar(Cx + 1, Cy) = 1) Then smenor(0) = ContarCerca(Cx + 1, Cy,
niveles)
If (Evaluar(Cx, Cy - 1) = 1) Then smenor(1) = ContarCerca(Cx, Cy - 1,
niveles)
If (Evaluar(Cx - 1, Cy) = 1) Then smenor(2) = ContarCerca(Cx - 1, Cy,
niveles)
If (Evaluar(Cx, Cy + 1) = 1) Then smenor(3) = ContarCerca(Cx, Cy + 1,
niveles)
' encontrar el mayor
If (Suma(0) >= mayor) Then
mayor = Suma(0)
dir1 = 1
End If
If (Suma(1) >= mayor) Then
mayor = Suma(1)
dir1 = 2
End If
If (Suma(2) >= mayor) Then
mayor = Suma(2)
dir1 = 3
End If
If (Suma(3) >= mayor) Then
mayor = Suma(3)
dir1 = 4
End If
If dir1 < 0 Then Return dir1
' si hay varios mayores empate si escoge el que tiene menos vecinos
For fila = 0 To 3
If Suma(fila) >= mayor Then
If (smenor(fila) <= menor) Then

menor = smenor(fila)
dirMenor = fila
cont = cont + 1
End If
End If
Next
' si hay mas de dos
For fila = ne - 1 To 1 Step -1
X(fila) = X(fila - 1)
Y(fila) = Y(fila - 1)
Next
If cont = 1 Then
' modificamos
Select Case dir1
Case 1
X(0) = Cx + 1
Case 2
Y(0) = Cy - 1
Case 3
X(0) = Cx - 1
Case 4
Y(0) = Cy + 1
End Select
Else ' si hay empate
Select Case dirMenor + 1
Case 1
X(0) = Cx + 1
Case 2
Y(0) = Cy - 1
Case 3
X(0) = Cx - 1
Case 4
Y(0) = Cy + 1
End Select
End If
Return dir1
End Function
End Module

Module Module1
Sub Main()
Dim Nombre As String = "E:\datos1\matriz40x20.txt"
Dim res As Integer, fila As Integer
For fila = 0 To ne - 1

X(fila) = 4
Y(fila) = 5 + fila
Next
RecuperarMatriz(Nombre, A, nf, nc)
VerMatriz(Cx, Cy, A, nf, nc)
Console.ForegroundColor = 14
ImPrimirSer(Cx, Cy, X, Y, ne)
Console.ReadLine()
Console.ForegroundColor = 10
While (1)
' Console.Clear()
VerMatriz(Cx, Cy, A, nf, nc)
res = ModificarSer(X, Y)
ImPrimirSer(Cx, Cy, X, Y, ne)
If res <= 0 Then
Exit While
End If
System.Threading.Thread.Sleep(50) ' 1 segundo
' Console.ReadLine()
End While
Console.WriteLine("FINal\b")
Console.ReadLine()
End Sub
End Module

El siguiente simula el cortado de una pieza de acuerdo a un patrn


establecido

Imports System.IO
Imports System.Drawing
Public Class Form1
Dim contador As Integer
Dim Grafico As Graphics
Dim pen As Pen
Dim x1 As Integer, y1 As Integer
Dim x2 As Integer, y2 As Integer
Dim a(1000, 4) As Integer
Dim cont As Integer = 0
Dim posx As Integer
Dim posy As Integer
Dim paso As Integer = 5
Dim altura As Integer = 0
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
Me.Text = "X= " & e.X & "y=" & e.Y & "boton " & e.Button
If e.Button = Windows.Forms.MouseButtons.None Then
x2 = e.X
y2 = e.Y
Else
x1 = x2
y1 = y2
x2 = e.X
y2 = e.Y

DataGridView1.Rows(contador).Cells(0).Value = contador
DataGridView1.Rows(contador).Cells(1).Value = e.X
DataGridView1.Rows(contador).Cells(2).Value = e.Y
DataGridView1.Rows(contador).Cells(3).Value = altura
a(contador, 0) = contador
a(contador, 1) = e.X
a(contador, 2) = e.Y
a(contador, 3) = altura
contador = contador + 1
Grafico.DrawLine(pen, x1, y1, x2, y2)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Grafico = Panel1.CreateGraphics
pen = New Pen(Color.FromArgb(255, 0, 0), 5)
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).Width = 40
DataGridView1.Columns(1).Width = 40
DataGridView1.Columns(2).Width = 40
DataGridView1.Columns(3).Width = 40
DataGridView1.Columns(0).Name = "p"
DataGridView1.Columns(1).Name = "X"
DataGridView1.Columns(2).Name = "Y"
DataGridView1.Columns(3).Name = "Z"
DataGridView1.RowCount = 1000
End Sub
Private Sub btnGrabar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGrabar.Click
Dim fila As Integer
Dim swEscritor As StreamWriter
swEscritor = New StreamWriter("E:\DATOS\Puntos.txt")
For fila = 0 To contador
swEscritor.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7}", a(fila, 0), Chr(9), a(fila,
1), Chr(9), a(fila, 2), Chr(9), a(fila, 3), Chr(9))
Next fila
swEscritor.Close()
MsgBox("EL ARCHIVO HA SIDO Grabado satisfactoriamente")
End Sub
Private Sub Btnrecuperar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Btnrecuperar.Click
Dim srLector As StreamReader = New
StreamReader("E:\DATOS\PUNTOS.txt")
Dim cadena As String
Dim subcadena As String

contador = 0
cadena = srLector.ReadLine()
Dim pos1 As Integer = 1, pos2 As Integer
Dim largo As Integer = Len(cadena)
Do While Not (cadena Is Nothing)
largo = Len(cadena)
pos2 = InStr(pos1, cadena, Chr(9))
subcadena = Mid(cadena, pos1, pos2 - pos1)
DataGridView1.Rows(contador).Cells(0).Value = subcadena
a(contador, 0) = Val(subcadena)
pos1 = pos2 + 1
pos2 = InStr(pos1, cadena, Chr(9))
subcadena = Mid(cadena, pos1, pos2 - pos1)
DataGridView1.Rows(contador).Cells(1).Value = subcadena
a(contador, 1) = Val(subcadena)
pos1 = pos2 + 1
pos2 = InStr(pos1, cadena, Chr(9))
subcadena = Mid(cadena, pos1, pos2 - pos1)
DataGridView1.Rows(contador).Cells(2).Value = subcadena
a(contador, 2) = Val(subcadena)
pos1 = pos2 + 1
subcadena = Mid(cadena, pos1, Len(cadena))
DataGridView1.Rows(contador).Cells(3).Value = subcadena
a(contador, 3) = Val(subcadena)
cadena = srLector.ReadLine()
contador = contador + 1
pos1 = 1
Loop
srLector.Close()
contador = contador - 1
MsgBox(" numero de elementos" & contador)
End Sub
Private Sub BtnMostrarRecuperado_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BtnMostrarRecuperado.Click
For fila = 0 To contador - 2
x1 = a(fila, 1)
y1 = a(fila, 2)
x2 = a(fila + 1, 1)
y2 = a(fila + 1, 2)
Grafico.DrawLine(pen, x1, y1, x2, y2)
Next
End Sub
Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBorrar.Click
Grafico.Clear(Color.White)
End Sub

Private Sub Btncortar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Btncortar.Click
Dim x3 As Integer, y3 As Integer
pen.Color = Color.FromArgb(0, 255, 0)
For fila = 0 To contador - 2
x1 = a(fila, 1)
y1 = a(fila, 2)
x2 = a(fila + 1, 1)
y2 = a(fila + 1, 2)
Grafico.DrawLine(pen, x1, y1, x2, y2)
If fila > paso Then
x3 = a(fila + paso, 1)
y3 = a(fila + paso, 2)
btnCortador.Left = x3
btnCortador.Top = y3
Sleep(10)
End If
Next
pen.Color = Color.FromArgb(255, 0, 0)
BtnMostrarRecuperado_Click(sender, e)
End Sub
Private Sub btnMover_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMover.Click
posx = a(cont, 1)
posy = a(cont, 2)
btnCortador.Left = posx
btnCortador.Top = posy
If cont < contador Then
cont = cont + 1
Else : cont = 0
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Select Case Chr(e.KeyCode)
Case "X" : altura = altura + 1
Case "x" : altura = altura + 1
Case "Y" : If altura > 0 Then altura = altura - 1
Case "y" : If altura > 0 Then altura = altura - 1
End Select
TextBox1.Clear()
TextBox1.Text = altura
End Sub
End Class

Pregunta 3 ( alternativa A)Modo Visual. Cargar los siguientes nmeros a se tiene


los siguientes datos en Excel, leer el archivo de texto y rellenarlo a un cuadro
combinado y un cuadro de lista como se muestra en el grafico ( dos puntos)

Imports System.IO
Public Class Form1
Private Sub BtnCargar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnCargar.Click
Dim srLector As StreamReader = New
StreamReader("E:\DATOS\PUNTOS8.txt")
Dim cadena As String
Dim subcadena As String
Dim pos As Integer, tam As Integer
ComboBox1.Items.Clear()
ListBox1.Items.Clear()
cadena = srLector.ReadLine()
Do While Not (cadena Is Nothing)
tam = Len(cadena)
pos = InStr(1, cadena, Chr(9))
subcadena = Mid(cadena, 1, pos - 1)
ComboBox1.Items.Add(subcadena)
ListBox1.Items.Add(Mid(cadena, pos + 1, Len(cadena)))

cadena = srLector.ReadLine()
Loop
srLector.Close()
ListBox2.Items.Add("numero de elementos" & ListBox1.Items.Count)
Dim mayor As Integer = -100
Dim valor As Integer
For fila = 0 To ListBox1.Items.Count - 1
valor = ListBox1.Items(fila)
If valor > mayor Then mayor = valor
Next
ListBox2.Items.Add("elemento mayor encontrado es " & mayor)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Dim indice As Integer
indice = ComboBox1.SelectedIndex
ListBox1.SelectedIndex = indice
End Sub
End Class

Imagines

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Private WithEvents dataGridView1 As New DataGridView()
Private highPriImage As Bitmap
Private mediumPriImage As Bitmap

Private lowPriImage As Bitmap


Public Sub New()
' Initialize the images.
Try
highPriImage = New Bitmap("E:\datos\auto1.bmp")
mediumPriImage = New Bitmap("E:\datos\carta1.bmp")
lowPriImage = New Bitmap("E:\datos\carta2.bmp")
Catch ex As ArgumentException
MessageBox.Show("The Priority column requires Bitmap images" & _
"named highPri.bmp, mediumPri.bmp, and lowPri.bmp " & _
"residing in the same directory as the executable file.")
End Try
' Initialize the DataGridView.
With dataGridView1
.Dock = DockStyle.Fill
.AllowUserToAddRows = False
.Columns.AddRange(New DataGridViewTextBoxColumn(), _
New DataGridViewImageColumn())
.Columns(0).Name = "Balance"
.Columns(1).Name = "Priority"
.Rows.Add("-100", "high")
'.Rows.Add("-100")
.Rows.Add("0", "medium")
.Rows.Add("100", "low")
End With
Me.Controls.Add(dataGridView1)
End Sub
' Changes how cells are displayed depending on their columns and values.
Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
Handles dataGridView1.CellFormatting
' Set the background to red for negative values in the Balance column.
If dataGridView1.Columns(e.ColumnIndex).Name.Equals("Balance") Then
'Dim intValue As Int32
If CInt(e.Value) < 0 Then
'if Int32.TryParse((String)e.Value, out intValue) &&
' (intValue < 0))

e.CellStyle.BackColor = Color.Red
e.CellStyle.SelectionBackColor = Color.DarkRed
End If
End If
' Replace string values in the Priority column with images.
If dataGridView1.Columns(e.ColumnIndex).Name.Equals("Priority") Then
' Ensure that the value is a string.
Dim stringValue As String = TryCast(e.Value, String)
If stringValue Is Nothing Then Return
' Set the cell ToolTip to the text value.
Dim cell As DataGridViewCell = _
dataGridView1(e.ColumnIndex, e.RowIndex)
cell.ToolTipText = stringValue
' Replace the string value with the image value.
Select Case stringValue
Case "high"
e.Value = highPriImage
Case "medium"
e.Value = mediumPriImage
Case "low"
e.Value = lowPriImage
End Select
End If
End Sub
Public Sub Main()
Application.Run(New Form1())
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load
End Sub
End Class

Public Class Form1


Dim Cadena As String
Dim np As Integer = 10
Dim Indice As Integer = 1
Dim Vel As Integer = 10
Dim GPencil As Integer = 4
Dim li As Single = -3
Dim ls As Single = 3
Dim dx As Single = 0
Dim Ex As Single = 20
Dim Ey As Single = -20
Dim Cx As Single = 200
Dim Cy As Single = 200
Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha As SolidBrush
Dim valor As Single
Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles
btnIniciar.Click
DataGridView1.RowCount = 6
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "X (min)"
DataGridView1.Columns(2).HeaderText = "Y (Max)"
DataGridView1.Columns(0).Width = 100
DataGridView1.Columns(1).Width = 40
DataGridView1.Columns(2).Width = 40
DataGridView1.Rows(0).Cells(0).Value = "NP Dx"
DataGridView1.Rows(0).Cells(1).Value = np
DataGridView1.Rows(1).Cells(0).Value = "Linf Lsup"
DataGridView1.Rows(1).Cells(1).Value = li
DataGridView1.Rows(1).Cells(2).Value = ls
DataGridView1.Rows(2).Cells(0).Value = "Cx Cy"
DataGridView1.Rows(2).Cells(1).Value = Cx
DataGridView1.Rows(2).Cells(2).Value = Cy
DataGridView1.Rows(3).Cells(0).Value = "Ex Ey"
DataGridView1.Rows(3).Cells(1).Value = Ex
DataGridView1.Rows(3).Cells(2).Value = Ey
DataGridView1.Rows(4).Cells(0).Value = "Grosor pencil Indice"
DataGridView1.Rows(4).Cells(1).Value = GPencil
DataGridView1.Rows(4).Cells(2).Value = Indice
DataGridView1.Rows(5).Cells(0).Value = "Velocidad"
DataGridView1.Rows(5).Cells(1).Value = Vel

dx = (ls - li) / np
DataGridView1.Rows(0).Cells(2).Value = dx
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
End Sub
Private Sub btnProcesar_Click(sender As Object, e As EventArgs) Handles
btnProcesar.Click
Cadena = "2*3"
Dim pos As Integer
Dim valor1 As Single
Dim valor2 As Single
' buscar primero los producto
pos = InStr(Cadena, "*")
valor1 = Mid(Cadena, 1, pos - 1)
valor2=Mid(Cadena,pos+1,
'Dim TestString As String = "perro ferozt"
'' Returns "Shipping List".
'Dim aString As String = Replace(TestString, "perro", "lobo")
'Cadena = TestString
''valor = TextBox1.Text
TextBox1.Text = valor
'cadena1=
End Sub
Adicionales

BITMAPAS

Module Module1
Public nombre As String
Public nfilas As Integer = 5
Public Cxf As Integer = 10
Public Cyf As Integer = 10
Public Anchof As Integer = 100
Public Altof As Integer = 100
Public Cxd As Integer = 350
Public Cyd As Integer = 10
Public Anchod As Integer = 200
Public Altod As Integer = 200
Public grafico As Graphics
Public pincel As Pen
Public brocha As SolidBrush
Public anchofigura As Integer = 200
Public altofigura As Integer = 200
Public anchocuadro As Integer = 200
Public altocuadro As Integer = 200
Public modo As Integer = 0
Public myBitmap As Bitmap
End Module
Public Class Form1
Private Sub BtnIniciar_Click(sender As Object, e As EventArgs)
Handles BtnIniciar.Click
DataGridView1.RowCount = nfilas
DataGridView1.ColumnCount = 3

DataGridView1.Columns(0).HeaderText = "Propiedad"
DataGridView1.Columns(1).HeaderText = "Valor X"
DataGridView1.Columns(2).HeaderText = "Valor Y"
DataGridView1.Columns(1).Width = 50
DataGridView1.Columns(2).Width = 50
For i = 0 To nfilas - 1
DataGridView1.Rows(i).HeaderCell.Value = i.ToString
Next
DataGridView1.Rows(0).Cells(0).Value = "Fuente Cx,Cy "
DataGridView1.Rows(0).Cells(1).Value = Cxf
DataGridView1.Rows(0).Cells(2).Value = Cyf
DataGridView1.Rows(1).Cells(0).Value = "Fuente Ancho Alto "
DataGridView1.Rows(1).Cells(1).Value = Anchof
DataGridView1.Rows(1).Cells(2).Value = Altof
DataGridView1.Rows(2).Cells(0).Value = "Destino Cx,Cy "
DataGridView1.Rows(2).Cells(1).Value = Cxd
DataGridView1.Rows(2).Cells(2).Value = Cyd
DataGridView1.Rows(3).Cells(0).Value = "Destino Ancho Alto "
DataGridView1.Rows(3).Cells(1).Value = Anchod
DataGridView1.Rows(3).Cells(2).Value = Altod
DataGridView1.Rows(4).Cells(0).Value = "Modo "
DataGridView1.Rows(4).Cells(1).Value = modo
End Sub
Private Sub btnModificarBitmap_Click(sender As Object, e As
EventArgs) Handles btnModificarBitmap.Click
Dim anchof2, altof2 As Integer
If modo = 0 Then
grafico.DrawImage(myBitmap, 0, 0)
anchof2 = Anchof / 2
altof2 = Altof / 2
grafico.DrawRectangle(Pens.Red, Cxf - anchof2, Cyf - altof2,
Anchof, Altof)
End If
Dim sourceRectangle As New Rectangle(Cxf, Cyf, Anchof, Altof)
Dim destRectangle1 As New Rectangle(Cxd, Cyd, Anchod, Altod)
grafico.DrawImage(myBitmap, destRectangle1, sourceRectangle,
GraphicsUnit.Pixel)

End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
btnAbrir.Click
OpenFileDialog1.ShowDialog()
nombre = OpenFileDialog1.FileName
myBitmap = New Bitmap(nombre)
PictureBox2.Load(nombre)
grafico.DrawImage(myBitmap, 0, 0)
anchofigura = myBitmap.Width
altofigura = myBitmap.Height
End Sub
Private Sub btnObtenerValores_Click(sender As Object, e As
EventArgs) Handles btnObtenerValores.Click
Cxf = DataGridView1.Rows(0).Cells(1).Value
Cyf = DataGridView1.Rows(0).Cells(2).Value
Anchof = DataGridView1.Rows(1).Cells(1).Value()
Altof = DataGridView1.Rows(1).Cells(2).Value
Cxd = DataGridView1.Rows(2).Cells(1).Value
Cyd = DataGridView1.Rows(2).Cells(2).Value
Anchod = DataGridView1.Rows(3).Cells(1).Value
Altod = DataGridView1.Rows(3).Cells(2).Value
modo = DataGridView1.Rows(4).Cells(1).Value
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
grafico = PictureBox1.CreateGraphics
pincel = New Pen(Brushes.Azure, 2)
brocha = New SolidBrush(Color.AliceBlue)
anchocuadro = PictureBox1.Width
altocuadro = PictureBox1.Height
End Sub
Private Sub btnBorrar_Click(sender As Object, e As EventArgs)
Handles btnBorrar.Click
grafico.Clear(Color.Black)
End Sub

Private Sub txtCxCyF_KeyDown(sender As Object, e As


KeyEventArgs) Handles txtCxCyF.KeyDown
Select e.KeyCode
Case Keys.Down
If (Cyf + Altof) < altofigura Then Cyf = Cyf + 1
Case Keys.Up
If Cyf > 0 Then Cyf = Cyf - 1
Case Keys.Right
If (Cxf + Anchof) < anchofigura Then Cxf = Cxf + 1
Case Keys.Left
If Cxf > 0 Then Cxf = Cxf - 1
End Select
DataGridView1.Rows(0).Cells(1).Value = Cxf
DataGridView1.Rows(0).Cells(2).Value = Cyf
btnObtenerValores_Click(sender, e) ' no es necesario
btnModificarBitmap_Click(sender, e)
End Sub
Private Sub txtCxCyd_KeyDown(sender As Object, e As
KeyEventArgs) Handles txtCxCyd.KeyDown
Select Case e.KeyCode
Case Keys.Down
If (Cyd + Altod) < altocuadro Then Cyd = Cyd + 1
Case Keys.Up
If Cyd > 0 Then Cyd = Cyd - 1
Case Keys.Right
If (Cxd + Anchod) < anchocuadro Then Cxd = Cxd + 1
Case Keys.Left
If Cxd > 0 Then Cxd = Cxd - 1
End Select
DataGridView1.Rows(2).Cells(1).Value = Cxd
DataGridView1.Rows(2).Cells(2).Value = Cyd
btnObtenerValores_Click(sender, e) ' no es necesario
btnModificarBitmap_Click(sender, e)
End Sub
Private Sub txtTamDest_KeyDown(sender As Object, e As
KeyEventArgs) Handles txtTamDest.KeyDown
Select Case e.KeyCode

Case Keys.Down
If (Cyd + Altod) < altocuadro Then Altod = Altod + 1
Case Keys.Up
If Altod > 0 Then Altod = Altod - 1
Case Keys.Right
If (Cxd + Anchod) < anchocuadro Then Anchod = Anchod + 1
Case Keys.Left
If Anchod > 0 Then Anchod = Anchod - 1
End Select
DataGridView1.Rows(3).Cells(1).Value = Anchod
DataGridView1.Rows(3).Cells(2).Value = Altod
btnObtenerValores_Click(sender, e) ' no es necesario
btnModificarBitmap_Click(sender, e)
End Sub
Private Sub txtTamfuente_KeyDown(sender As Object, e As
KeyEventArgs) Handles txtTamfuente.KeyDown
Select Case e.KeyCode
Case Keys.Down
If (Cyf + Altof) < altofigura Then Altof = Altof + 1
Case Keys.Up
If Altof > 0 Then Altof = Altof - 1
Case Keys.Right
If (Cxf + Anchof) < anchofigura Then Anchof = Anchof + 1
Case Keys.Left
If Anchof > 0 Then Anchof = Anchof - 1
End Select
DataGridView1.Rows(1).Cells(1).Value = Anchof
DataGridView1.Rows(1).Cells(2).Value = Altof
btnObtenerValores_Click(sender, e) ' no es necesario
btnModificarBitmap_Click(sender, e)
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As
MouseEventArgs) Handles PictureBox1.MouseDown
If modo = 0 Then
DataGridView1.Rows(0).Cells(1).Value = e.X
DataGridView1.Rows(0).Cells(2).Value = e.Y
btnObtenerValores_Click(sender, e) ' no es necesario
btnModificarBitmap_Click(sender, e)

End If
End Sub
End Class

S-ar putea să vă placă și