Académique Documents
Professionnel Documents
Culture Documents
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()
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
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
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)
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
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
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
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
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
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
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
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, _
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
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
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
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
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
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
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
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
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)
APLICACION MODELADO 3D
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)
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)
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
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
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
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
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
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
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)
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
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
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
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
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
End Sub
End Class
Con 500 puntos aletorio
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
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)
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
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
Valores de hwndInsertAfter
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
namespace siempreEncima_cs
{
namespace elGuille.Util
{
public class WinAPI
{
// Constantes para SetWindowsPos
//
Valores de wFlags
Valores de hwndInsertAfter
}
}
}
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
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
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
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
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
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
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
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