Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Cuando trabajamos con aplicaciones Windows, existen dos tipos de interfaces o formas
de presentar la información en pantalla , éstas son:
1. Interface de Simple Documentos (SDI): Presenta un documento en su propia
ventana, cada ventana es independiente. Por ejemplo se usan SDI, el bloc de notas,
el Paint, el WordPad, Office 2000, etc.
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -746-
2. Interface de Múltiples Documentos (MDI) : Presenta todos los documentos sobre
una ventana principal (Formulario padre) sobre la cual se muestra cada documento
en su ventana secundaria (Formulario hijo). Por ejemplo , se usan MDI: el Visual
Estudio.NET, SQL Enterprise Manager, Office 97, etc.
El ejemplo trata sobre un Editor de documentos similar al Wordpad , pero con funciones
básicas . Este ejemplo trabaja con dos formularios ; el primero es un formulario MDI
padre que tiene un menú principal , barras de herramientas y barra de estado; el
segundo formulario es la base para crear formularios MDI hijos que representan un
documento donde pueda escribir textos enriquecidos. Formato rtf
Elija DropDownItems
En image escoger
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -751-
6. Añadir un segundo formulario; del menú “Project” elegir “Add” Windows Form” ,
escribir como nombre frmDocumento y clic “Open”.
7. Seleccionar el formulario frmDocumento arrastrar un control ContextMenu y 1
RichTextBox, luego configurar sus propiedades, tal como se muestra en el siguiente
cuadro.
Lo mismo puede hacer con toolstrip y automáticamente adiciona los controles estándar
La alfombra de Sierpiński es un conjunto fractal descrito por primera vez por Wacław
Sierpiński en 1916.1 Constituye una generalización a dos dimensiones del conjunto de
Cantor. Comparte con él muchas propiedades: también es un conjunto compacto, no
numerable y de medida nula. Su dimensión de Hausdorff-Besicovitch es
Construcción
La construcción de la alfombra de Sierpinski se define de forma recursiva:
1. Comenzamos con un cuadrado.
2. El cuadrado se corta en 9 cuadrados congruentes, y eliminamos el cuadrado
central.
3. El paso anterior vuelve a aplicarse recursivamente a cada uno de los 8
cuadrados restantes.
La alfombra de Sierpinski es el límite de este proceso tras un número infinito de
iteraciones.
Construcción de la alfombra de Sierpinski:
(ver aplicación)
( ver en la aplicacion)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -762-
Imports System.Drawing
Module Module1
Public Const dx As Single = 0.6
Public nro As Integer
Public ColorPen As Color = Color.FromArgb(255, 0, 0)
Public ColorBrocha As Color = Color.FromArgb(0, 255, 0)
Public ColorFondo As Color = Color.FromArgb(255, 255, 255)
Public Nombre As String
Public grosor As Integer = 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -764-
''***********
Public ancho As Integer = 500
Public alto As Integer = 500
Public ancho1 As Integer = 400
Public alto1 As Integer = 400
Public Cx As Integer = 0
Public Cy As Integer = 0
Public Cx1 As Integer
Public Cy1 As Integer
Public Const alfa As Single = 1.047
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
distancia = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
End Function
End Module
Imports System.Drawing
Public Class Form1
Private Sub GrosorDeLineaToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles GrosorDeLineaToolStripMenuItem.Click
grosor = InputBox("Ingrese grosor de linea", "Tamaño Linea", 2)
End Sub
Private Sub MnuAlfombraDeSierpinski_Click(sender As Object, e As EventArgs)
Handles MnuAlfombraDeSierpinski.Click
nro = nro + 1
Nombre = "Alfombra de Sierpiński "
FrmAlfombra.MdiParent = Me
FrmAlfombra.Text = Nombre & nro.ToString
FrmAlfombra.Show()
End Sub
Private Sub MnuTriánguloDeSierpinski_Click(sender As Object, e As EventArgs)
Handles MnuTriánguloDeSierpinski.Click
nro = nro + 1
Nombre = "Alfombra de Sierpiński "
frmTriangulo.MdiParent = Me
frmTriangulo.Text = Nombre & nro.ToString
frmTriangulo.Show()
End Sub
Private Sub MnuMontañaFractal_Click(sender As Object, e As EventArgs) Handles
MnuMontañaFractal.Click
nro = nro + 1
Nombre = "Montaña Fractal "
frmMontaña.MdiParent = Me
frmMontaña.Text = Nombre & nro.ToString
frmMontaña.Show()
End Sub
Sub Fractal(ByVal px1 As Single, ByVal py1 As Single, ByVal px2 As Single, ByVal
py2 As Single)
Dim ax As Single, ay As Single
Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single, x3 As Single, y3 As
Single, rx As Single, ry As Single
ax = (px2 - px1) / 3.0
ay = (py2 - py1) / 3.0
pen5.Color = colorPen5
grafico5.DrawLine(pen5, Cx + px1, Cy + py1, Cx + px2, Cy + py2)
x1 = Cx + px1 + ax
y1 = Cy + py1 + ay
rx = ax * Math.Cos(alfa) - ay * Math.Sin(alfa)
ry = ax * Math.Sin(alfa) + ay * Math.Cos(alfa)
x2 = x1 + rx
y2 = y1 + ry
x3 = Cx + px1 + 2 * ax
y3 = Cy + py1 + 2 * ay
grafico5.DrawLine(pen5, x1, y1, x2, y2)
grafico5.DrawLine(pen5, x2, y2, x3, y3)
pen5.Color = ColorFondo5
grafico5.DrawLine(pen5, x1, y1, x3, y3)
' System.Threading.Thread.Sleep(vel) ' 1 segundo
If distancia(px1, py1, px2, py2) > 10 Then
Fractal(px1 + ax, py1 + ay, px1 + ax + rx, py1 + ay + ry)
Fractal(px1 + ax + rx, py1 + ay + ry, px1 + 2 * ax, py1 + 2 * ay)
Fractal(px1, py1, px1 + ax, py1 + ay)
Fractal(px1 + 2 * ax, py1 + 2 * ay, px2, py2)
End If
End Sub
FRACTALES DE MALDEBROT
Option Explicit On
Option Strict On
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -772-
Module Module1
Public brocha As SolidBrush
Public Const limite As Integer = 200
Public Grafico As Graphics
Public nc As Integer = 5
Public nf As Integer = 6 '6
Public Pen As Pen
Public vel As Integer = 10
Public nx As Integer = 100
Public ny As Integer = 100
Public MaxIter As Integer = 10
CODIGO DE FORMULARIO
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
Sub plotPoint(ByVal zx As Single, ByVal zy As Single)
Grafico.FillRectangle(brocha, Cx + zx * Ex, cy + zy * Ey, 4, 4)
End Sub
DataGridView1.Rows(1).Cells(0).Value = "Ny"
DataGridView1.Rows(1).Cells(1).Value = ny
DataGridView1.Rows(2).Cells(0).Value = "MaxIter"
DataGridView1.Rows(2).Cells(1).Value = MaxIter
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
End Sub
Private Sub btnIniciarTodo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnIniciarTodo.Click
nx = CInt(DataGridView1.Rows(0).Cells(1).Value)
ny = CInt(DataGridView1.Rows(1).Cells(1).Value)
MaxIter = 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)
End Sub
Imports System.IO
Module Module1
Public Structure Puntos
Public nro As Integer
Public X As Single
Public Y As Single
Public Z As Single
Public Rela As Integer
End Structure
Public modelo As Integer = 0
Public AnguloX As Integer = 0
Public AnguloY As Integer = 0
Public AnguloZ As Integer = 0
Public Const limite As Integer = 100
Public vel As Integer = 10
Public Const maximo As Integer = 7000
Public P(maximo) As Puntos
Public P1(maximo) As Puntos
Public Grafico As Graphics
Public ColorFondo As Color = Color.FromArgb(255, 255, 255)
Public pincel As Pen
Public Brocha As SolidBrush
Public valor As Single = 100 ' mas alto la monta
Public factor As Single = 0.5 ' 0.5 ' se relaciona con el valor factor proyeccion
Public ancho As Integer = 700
Public alto As Integer = 500
Public Ndivisiones As Integer = 5
Public ContPuntos As Integer
Public MiFuente As New Font("Verdana", 24, FontStyle.Bold)
Public Tx As Single = 0
Public Ty As Single = 0
Public tz As Single = 0
Public Ex As Single = 1
Public Ey As Single = 1
Public Ez As Single = 1
Public VEx As Single = 0.1
Public VEy As Single = 0.1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -777-
Public VEz As Single = 0.1
Public CARAS(maximo, 4) As Integer
Public Normales(maximo, 4) As Single
Public D As Single = 1000
Public contcaras As Integer
Public ver1 As Integer, ver2 As Integer, ver3 As Integer, ver4 As Integer
Public Modo As Integer = 0
Public NombreArchivoPuntos = "E:\datos\puntos4x28.txt"
Public NombreArchivoCaras = "E:\datos\caras4x28.txt"
Sub RotacionXYZ(P() As Puntos, ByVal AnguloX As Single, ByVal AnguloY As
Single, ByVal anguloZ As Single, np As Integer)
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim fila As Integer = 0
Dim arx = AnguloX * Math.PI / 180
For fila = 0 To np - 1
x1 = P(fila).X
y1 = P(fila).Y
z1 = P(fila).Z
x2 = x1
y2 = CSng(y1 * Math.Cos(arx) - z1 * Math.Sin(arx))
z2 = CSng(y1 * Math.Sin(arx) + z1 * Math.Cos(arx))
P(fila).X = x2
P(fila).Y = y2
P(fila).Z = z2
Next
Dim ary = AnguloY * Math.PI / 180
For fila = 0 To np - 1
x1 = P(fila).X
y1 = P(fila).Y
z1 = P(fila).Z
AX = x2 - x1
Ay = y2 - y1
Az = z2 - z1
Bx = x3 - x2
By = y3 - y2
Bz = z3 - z2
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -779-
NX = Ay * Bz - Az * By
Ny = AX * Bz - Az * Bx
Nz = AX * By - Ay * Bx
'PRODUCTO(CRUZ)
R = Math.Sqrt(NX * NX + Ny * Ny + Nz * Nz)
If R > 0 Then
Nx1 = NX / R
Else
Nx1 = 1000
End If
If R > 0 Then
Ny1 = Ny / R
Else
Ny1 = 1000
End If
If R > 0 Then
Nz1 = Nz / R
Else
Nz1 = 1000
End If
Pe = Nx1 * 0 + Ny1 * 0 + Nz1 * D
Normales(fila, 0) = Nx1
Normales(fila, 1) = Ny1
Normales(fila, 2) = Nz1
Normales(fila, 3) = Pe
Form1.ListBox1.Items.Add("normal" & Normales(fila, 2))
Next
End Sub
Sub RecuperarPuntos(ByVal nombrearchivo As String, P() As Puntos, ByRef nf 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 4
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
Select Case col
Case 0 : P(fila).nro = CInt(subcadena)
Case 1 : P(fila).X = CSng(subcadena)
Case 2 : P(fila).Y = CSng(subcadena)
Case 3 : P(fila).Z = CSng(subcadena)
Case 4 : P(fila).Rela = CInt(subcadena)
P(fila).nro = subcadena
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -780-
End Select
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila - 1
Console.WriteLine("Archivo {0} leido satisfactoriamente", nombrearchivo)
srLector.Close()
End Sub
Option Explicit On
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Sub Iniciar()
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -781-
DataGridView1.ColumnCount = 6
DataGridView1.RowCount = 5
Dim fila As Integer
For fila = 1 To 5
DataGridView1.Columns(fila).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "UNIDAD"
DataGridView1.Columns(2).HeaderText = "EjeX"
DataGridView1.Columns(3).HeaderText = "Eje Y"
DataGridView1.Columns(4).HeaderText = "Eje Z"
DataGridView1.Columns(5).HeaderText = "D o W"
End Sub
Sub Rectangulo(ByVal px1 As Single, ByVal py1 As Single, ByVal pz1 As Single, _
ByVal px2 As Single, ByVal py2 As Single, ByVal pz2 As Single, _
ByVal px3 As Single, ByVal py3 As Single, ByVal pz3 As Single, _
ByVal px4 As Single, ByVal py4 As Single, ByVal pz4 As Single, _
ByVal ndivisiones As Integer, ByVal valor As Single, _
ByVal ver1 As Integer, ByVal ver2 As Integer, ByVal ver3 As Integer, ByVal ver4
As Integer)
Dim v1 As Integer, v2 As Integer, v3 As Integer, v4 As Integer
Dim v12 As Integer, v23 As Integer, v34 As Integer, v14 As Integer
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -782-
Dim vmedio As Integer
Dim px12 As Single, py12 As Single, pz12 As Single
Dim px23 As Single, py23 As Single, pz23 As Single
Dim px34 As Single, py34 As Single, pz34 As Single
Dim px14 As Single, py14 As Single, pz14 As Single
Dim xmed As Single, ymed As Single, zmed As Single
Dim puntocentral As Integer
If (ndivisiones > 1) Then
xmed = (px1 + px2 + px3 + px4) / 4.0
ymed = (py1 + py2 + py3 + py4) / 4.0
'zmed = (pz1 + pz2 + pz3 + pz4) / 4.0 + Int(Rnd() * valor)
zmed = (pz1 + pz2 + pz3 + pz4) / 4.0 - valor + Int(Rnd() * 2 * valor)
ContPuntos = ContPuntos + 1
puntocentral = ContPuntos
P(ContPuntos).nro = ContPuntos
P(ContPuntos).X = xmed
P(ContPuntos).Y = ymed
P(ContPuntos).Z = zmed
P(ContPuntos).Rela = puntocentral
vmedio = puntocentral
px12 = (px1 + px2) / 2.0
px23 = (px2 + px3) / 2.0
px34 = (px3 + px4) / 2.0
px14 = (px1 + px4) / 2.0
ContPuntos = ContPuntos + 1
P(ContPuntos).nro = ContPuntos
P(ContPuntos).X = px34
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -783-
P(ContPuntos).Y = py34
P(ContPuntos).Z = pz34
P(ContPuntos).Rela = puntocentral
' CARAS(ContCaras).P3 = P(ContPuntos).nro
v34 = ContPuntos
ContPuntos = ContPuntos + 1
P(ContPuntos).nro = ContPuntos
P(ContPuntos).X = px14
P(ContPuntos).Y = py14
P(ContPuntos).Z = pz14
P(ContPuntos).Rela = puntocentral
v14 = ContPuntos
v1 = ver1
v2 = ver2
v3 = ver3
v4 = ver4
Rectangulo(px1, py1, pz1, px12, py12, pz12, xmed, ymed, zmed, px14, py14,
pz14, ndivisiones - 1, valor * factor, v1, v12, vmedio, v14)
Rectangulo(px12, py12, pz12, px2, py2, pz2, px23, py23, pz23, xmed, ymed,
zmed, ndivisiones - 1, valor * factor, v12, v2, v23, vmedio)
Rectangulo(xmed, ymed, zmed, px23, py23, pz23, px3, py3, pz3, px34, py34,
pz34, ndivisiones - 1, valor * factor, vmedio, v23, v3, v34)
Rectangulo(px14, py14, pz14, xmed, ymed, zmed, px34, py34, pz34, px4, py4,
pz4, ndivisiones - 1, valor * factor, v14, vmedio, v34, v4)
Else
If ndivisiones = 1 Then
CARAS(contcaras, 0) = ver1
CARAS(contcaras, 1) = ver2
CARAS(contcaras, 2) = ver3
CARAS(contcaras, 3) = ver4
contcaras = contcaras + 1
End If
End If
End Sub
Sub graficarCara(ByVal contcaras As Integer)
Dim X1 As Single, y1 As Single, z1 As Single
Dim X2 As Single, y2 As Single, z2 As Single
Dim px1 As Single, py1 As Single
Dim px2 As Single, py2 As Single
Dim Figura(3) As Point
Dim col As Integer
Dim color1 As Integer
For fila = 0 To contcaras - 1
For col = 0 To 2
X1 = P1(CARAS(fila, col)).X
y1 = P1(CARAS(fila, col)).Y
z1 = P1(CARAS(fila, col)).Z
X2 = P1(CARAS(fila, col + 1)).X
y2 = P1(CARAS(fila, col + 1)).Y
z2 = P1(CARAS(fila, col + 1)).Z
px1 = (X1 * D) / (D + z1)
py1 = (y1 * D) / (D + z1)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -784-
px2 = (X2 * D) / (D + z2)
py2 = (y2 * D) / (D + z2)
Figura(col).X = px1
Figura(col).Y = py1
Next
Figura(3).X = px2
Figura(3).Y = py2
If Normales(fila, 2) > 0 Then 'solo dibuja si el normal es mayor que 0
Select Case Modo
Case 0
Grafico.DrawPolygon(pincel, Figura)
Case 1
color1 = Normales(fila, 2) * 255
Select Case modelo
Case 0 ' gris
Brocha.Color = Color.FromArgb(color1, color1, color1)
Case 1 ' rojo
Brocha.Color = Color.FromArgb(color1, 0, 0)
Case 2 ' verde
Brocha.Color = Color.FromArgb(0, color1, 0)
Case 3 ' azul
Brocha.Color = Color.FromArgb(0, 0, color1)
Case 4 ' rojo-verde
Brocha.Color = Color.FromArgb(255 - color1, color1, 0)
Case 5 ' verde-rojo
Brocha.Color = Color.FromArgb(color1, 255 - color1, 0)
Case 6 ' amarillo -azul
Brocha.Color = Color.FromArgb(color1, color1, 255 - color1)
Case 7 ' amarillo -azul
Brocha.Color = Color.FromArgb(255 - color1, 255 - color1, 255 - color1)
End Select
Grafico.FillPolygon(Brocha, Figura, FillMode.Alternate)
Case 2
color1 = Normales(fila, 2) * 255
Select Case modelo
Case 0 ' gris
Brocha.Color = Color.FromArgb(color1, color1, color1)
Case 1 ' rojo
Brocha.Color = Color.FromArgb(color1, 0, 0)
Case 2 ' verde
Brocha.Color = Color.FromArgb(0, color1, 0)
Case 3 ' azul
Brocha.Color = Color.FromArgb(0, 0, color1)
Case 4 ' rojo-verde
Brocha.Color = Color.FromArgb(255 - color1, color1, 0)
Case 5 ' verde-rojo
Brocha.Color = Color.FromArgb(color1, 255 - color1, 0)
Case 6 ' amarillo -azul
Brocha.Color = Color.FromArgb(color1, color1, 255 - color1)
Case 7 ' amarillo -azul
Brocha.Color = Color.FromArgb(255 - color1, 255 - color1, 255 - color1)
End Select
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -785-
Grafico.FillPolygon(Brocha, Figura, FillMode.Alternate)
Grafico.DrawPolygon(pincel, Figura)
End Select
End If
' Grafico.DrawLine(pincel, px1, py1, px2, py2)
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim col As Integer
PictureBox1.Width = ancho + 10
PictureBox1.Height = alto + 10
PictureBox1.BackColor = ColorFondo
Grafico = PictureBox1.CreateGraphics
MiFuente = New Font("arial", 11, FontStyle.Bold)
Brocha = New SolidBrush(Color.Red)
pincel = New Pen(Color.Blue, 1)
Iniciar()
DataGridView2.ColumnCount = 5
DataGridView2.RowCount = 1
For col = 0 To 4
DataGridView2.Columns(col).Width = 60
Next
End Sub
Private Sub MnuMontaña_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMontaña.Click
Dim i, j As Integer
Grafico.Clear(Color.Black)
Randomize()
Dim Px1 As Integer = 100, py1 As Integer = 100, pz1 As Integer = 10
Dim px2 As Integer = 600, py2 As Integer = 100, pz2 As Integer = 10
Dim px3 As Integer = 600, py3 As Integer = 400, pz3 As Integer = 10
Dim px4 As Integer = 100, py4 As Integer = 400, pz4 As Integer = 10
contcaras = 0
ver1 = 0
ver2 = 1
ver3 = 2
ver4 = 3
P(0).nro = 0 : P(0).X = Px1 : P(0).Y = py1 : P(0).Z = pz1 : P(0).Rela = 1
P(1).nro = 1 : P(1).X = px2 : P(1).Y = py2 : P(1).Z = pz2 : P(1).Rela = 2
P(2).nro = 2 : P(2).X = px3 : P(2).Y = py3 : P(2).Z = pz3 : P(2).Rela = 3
P(3).nro = 3 : P(3).X = px4 : P(3).Y = py4 : P(3).Z = pz4 : P(3).Rela = 0
ContPuntos = 3
ListBox1.Items.Clear()
ListBox1.Items.Add("CANTIDAD de divisiones " & Ndivisiones)
Randomize()
Rectangulo(Px1, py1, pz1, px2, py2, pz2, px3, py3, pz3, px4, py4, pz4,
Ndivisiones, valor, ver1, ver2, ver3, ver4)
ListBox1.Items.Add("CANTIDAD DE Caras " & contcaras)
ListBox1.Items.Add("CANTIDAD DE puntos " & ContPuntos)
For i = 0 To ContPuntos
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -786-
ListBox1.Items.Add("Punto Nro" & P(i).nro & " X " & P(i).X & " Y " & P(i).Y & " Z "
& P(i).Z & "rela " & P(i).Rela)
Next
pincel.Color = Color.Red
Dim swEscritor As StreamWriter
swEscritor = New StreamWriter("E:\DATOS\FRACTAL.txt")
For i = 0 To ContPuntos
swEscritor.WriteLine("{0}{1}{2}{3}{4}{5}{6}{7}{8}", P(i).nro, Chr(9), P(i).X, Chr(9),
P(i).Y, Chr(9), P(i).Z, Chr(9), P(i).Rela)
Next
swEscritor.Close()
swEscritor = New StreamWriter("E:\DATOS\CARAS.txt")
For i = 0 To contcaras
For j = 0 To 3
swEscritor.Write("{0} {1}", CARAS(i, j), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
CopiarVector(P, P1, ContPuntos)
ObtenerNormales()
graficarCara(contcaras)
End Sub
Private Sub MnGraficar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMontaña.Click
graficarCara(contcaras)
End Sub
Tx = DataGridView1.Rows(1).Cells(2).Value
Ty = DataGridView1.Rows(1).Cells(3).Value
tz = DataGridView1.Rows(1).Cells(4).Value
D = DataGridView1.Rows(1).Cells(5).Value
Ex = DataGridView1.Rows(2).Cells(2).Value
Ey = DataGridView1.Rows(2).Cells(3).Value
Ez = DataGridView1.Rows(2).Cells(4).Value
Modo = DataGridView1.Rows(3).Cells(2).Value
vel = DataGridView1.Rows(3).Cells(3).Value
modelo = DataGridView1.Rows(3).Cells(4).Value
Ndivisiones = DataGridView1.Rows(3).Cells(5).Value
Else
Ey = -limite
End If
Case 90 ' escalado eJE Z
If Ez <= limite Then
Ez = Ez + VEz
Else
Ez = -limite
End If
End Select
DataGridView1.Rows(2).Cells(2).Value = Ex
DataGridView1.Rows(2).Cells(3).Value = Ey
DataGridView1.Rows(2).Cells(4).Value = Ez
txtescalado.Text = ""
BtnIniciarTodo_Click(sender, e)
End Sub
Imports System.IO
Module Module2
'Public NombreArchivo As String = "E:\datos\puntos6.txt"
Public NombreArchivo As String = "E:\datos\puntos20.txt"
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -792-
Public Const Maxfilas As Integer = 200
Public Const Maxcol As Integer = 200
Public Const Maxpuntos As Integer = 2000
Public camino As Integer = 0
Public np As Integer = 20
Public np1 As Integer = 0
Public A(Maxfilas, Maxcol) As Integer
Public B(Maxfilas, Maxcol) As Integer
Public X(Maxpuntos) As Integer
Public Y(Maxpuntos) As Integer
Public VX(Maxpuntos) As Integer
Public VY(Maxpuntos) As Integer
Public relleno(Maxpuntos) As Integer
Public nf As Integer = 100
Public nc As Integer = 100
Public cx As Integer = 2
Public cy As Integer = 2
Public tam As Integer = 40
Sub IniciarPuntosMatriz(ByRef A(,) As Integer, X() As Integer, Y() As Integer, Z() As
Integer, np As Integer)
Dim fila As Integer
For fila = 0 To np - 1
A(Y(fila), X(fila)) = Z(fila)
Next
End Sub
Sub IniciarMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
valor As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = valor
Next
Next
End Sub
Sub MatrizVectorXYZ(ByVal A(,) As Integer, ByRef X() As Integer, ByRef Y() As
Integer, ByRef Z() As Integer, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
X(fila) = A(fila, 0)
Y(fila) = A(fila, 1)
Z(fila) = A(fila, 2)
Next
End Sub
Sub VerPantalla(ByVal cx As Integer, ByVal cy As Integer, ByVal A(,) As Integer,
ByVal nf As Integer, ByVal 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}", Hex(A(fila, col)))
Next
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -793-
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 = CInt(Y(k) - r) To CInt(Y(k) + r)
For x1 = CInt(X(k) - r) To CInt(X(k) + r)
If (Math.Pow(x1 - X(k), 2) + Math.Pow(y1 - Y(k), 2) <= r * r) And (x1 > 0)
And (x1 < Maxcol) And (y1 > 0) And (y1 < Maxfilas) Then
If (A(y1, x1) = 0) Then
A(y1, x1) = relleno(k)
End If
End If
Next
Next
Next
End Sub
Sub MostrarVectores(Vx() As Integer, Vy() As Integer, Ne As Integer)
Dim fila As Integer
For fila = 0 To Ne - 1
Console.WriteLine("{0} {1} {2} {3} {4} ", fila, vbTab, Vx(fila), vbTab, Vy(fila))
Next
End Sub
Sub GrabarVectores(Vx() As Integer, Vy() As Integer, Ne As Integer)
Dim fila As Integer
Dim archivo As StreamWriter
archivo = New StreamWriter("E:\datos\delaunay.txt")
For fila = 0 To Ne - 1
archivo.WriteLine("{0} {1} {2} {3} {4} ", fila, vbTab, Vx(fila), vbTab, Vy(fila))
Next
archivo.Close()
End Sub
Function EncontrarValor(VX() As Integer, VY() As Integer, np As Integer, valor1 As
Integer, valor2 As Integer)
Dim res As Integer = 0
Dim fila As Integer
For fila = 0 To np - 1
If valor1 = VX(fila) And valor2 = VY(fila) Then
res = 1
Exit For
End If
Next
Return res
End Function
Sub EncontrarPares(ByRef A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer,
VX() As Integer, VY() As Integer, ByRef np1 As Integer, relleno1 As
Integer)
Dim R1 As Integer
Dim R2 As Integer
Dim cont As Integer = np1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -794-
For fila = 1 To nf - 1
For col = 1 To nc - 1
If A(fila, col) = relleno1 Then
If A(fila, col + 1) <> camino And A(fila, col + 1) <> relleno1 Then
R1 = EncontrarValor(VX, VY, cont, relleno1, A(fila, col + 1))
R2 = EncontrarValor(VX, VY, cont, A(fila, col + 1), relleno1)
If R1 = 0 And R2 = 0 Then
VX(cont) = relleno1
VY(cont) = A(fila, col + 1)
cont = cont + 1
End If
End If
If A(fila, col - 1) <> camino And A(fila, col - 1) <> relleno1 Then
R1 = EncontrarValor(VX, VY, cont, relleno1, A(fila, col - 1))
R2 = EncontrarValor(VX, VY, cont, A(fila, col - 1), relleno1)
If R1 = 0 And R2 = 0 Then
VX(cont) = relleno1
VY(cont) = A(fila, col - 1)
cont = cont + 1
End If
End If
If A(fila + 1, col) <> camino And A(fila + 1, col) <> relleno1 Then
R1 = EncontrarValor(VX, VY, cont, relleno1, A(fila + 1, col))
R2 = EncontrarValor(VY, VX, cont, relleno1, A(fila + 1, col))
If R1 = 0 And R2 = 0 Then
VX(cont) = relleno1
VY(cont) = A(fila + 1, col)
cont = cont + 1
End If
End If
If A(fila - 1, col) <> camino And A(fila - 1, col) <> relleno1 Then
R1 = EncontrarValor(VX, VY, cont, relleno1, A(fila - 1, col))
R2 = EncontrarValor(VY, VX, cont, relleno1, A(fila - 1, col))
If R1 = 0 And R2 = 0 Then
VX(cont) = relleno1
VY(cont) = A(fila - 1, col)
cont = cont + 1
End If
End If
End If
Next
Next
np1 = cont
End Sub
Sub JuegoVida(ByRef A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim B(Maxfilas, Maxcol) As Integer
Dim relleno1 As Integer
IniciarMatriz(B, nf, nc, 0)
Dim fila, col, vecinos, x1, y1, x2, y2, fila1, col1 As Integer
For k = 0 To np - 1
relleno1 = relleno(k)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -795-
For fila = 0 To nf - 1
For col = 0 To nc - 1
vecinos = 0
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
For fila1 = y1 To y2
For col1 = x1 To x2
If (fila1 = fila And col1 = col) Then Continue For
If A(fila1, col1) = relleno1 Then vecinos = vecinos + 1
Next
Next
If vecinos = 8 Then
B(fila, col) = 0
Else
B(fila, col) = A(fila, col)
End If
Next
Next
IniciarMatriz(A, nf, nc, 0)
TransferirMatriz(B, A, nf, nc)
Next
End Sub
Sub TransferirMatriz(ByVal MA(,) As Integer, ByRef MB(,) As Integer, ByVal nf As
Integer, ByVal nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf
For col = 0 To nc
MB(fila, col) = MA(fila, col)
Next
Next
End Sub
Sub linea(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As
Single)
Dim i As Integer, vel As Single = 10
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -796-
Dim mayor, ancho, alto, partex, partey, px, py, dx, dy As Single
If (x2 - x1 = 0 And y2 - y1 = 0) Then Exit Sub
Module Module1
Sub graficar(VX() As Integer, VY() As Integer, np1 As Integer)
Dim x1, y1, x2, y2 As Single
Dim fila As Integer
For fila = 0 To np1 - 1
x1 = X(VX(fila) - 1)
y1 = Y(VX(fila) - 1)
x2 = X(VY(fila) - 1)
y2 = Y(VY(fila) - 1)
linea(x1, y1, x2, y2)
Next
End Sub
Sub Main()
Dim r As Integer
IniciarMatriz(A, nf, nc, 0)
RecuperarMatriz(NombreArchivo, A, np, 3)
MatrizVectorXYZ(A, X, Y, relleno, np)
MostrarVectores(X, Y, np)
IniciarMatriz(A, nf, nc, 0)
For r = 0 To 50
crecerCirculo(A, X, Y, nf, nc, relleno, r, np)
Next
VerPantalla(cx, cy, A, nf, nc)
Console.ReadLine()
JuegoVida(A, nf, nc)
VerPantalla(cx, cy, A, nf, nc)
For r = 0 To np - 1
EncontrarPares(A, nf, nc, VX, VY, np1, relleno(r))
Next
Console.WriteLine("resultados")
MostrarVectores(VX, VY, np1)
GrabarVectores(VX, VY, np1)
Console.ForegroundColor = 14
graficar(VX, VY, np1)
VerPantalla(cx, cy, A, nf, nc)
Console.ReadLine()
End Sub
End Module
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -798-
Imports System.Drawing
Public Class Form1
Dim grafico As Graphics
Dim Pincel As Pen
Dim Pincel1 As Pen
Dim brocha As SolidBrush
Sub graficarGrafica(VX() As Integer, VY() As Integer, np1 As Integer)
Dim x1, y1, x2, y2 As Single
Dim fila As Integer
For fila = 0 To np1 - 1
x1 = X(VX(fila) - 1)
y1 = Y(VX(fila) - 1)
x2 = X(VY(fila) - 1)
y2 = Y(VY(fila) - 1)
grafico.DrawLine(Pincel1, cx + x1 * tam, cy + y1 * tam, cx + x2 * tam, cy + y2 *
tam)
Next
End Sub
Sub VerPantallaGrafica(ByVal cx As Integer, ByVal cy As Integer, ByVal A(,) As
Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
Dim verde As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
verde = A(fila, col)
brocha.Color = Color.FromArgb(0, verde * 10, 0)
grafico.DrawRectangle(Pincel, cx + col * tam, cy + fila * tam, tam, tam)
grafico.FillRectangle(brocha, cx + col * tam, cy + fila * tam, tam, tam)
Next
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 4
DataGridView1.RowCount = np
DataGridView1.Columns(0).HeaderText = "Nro"
DataGridView1.Columns(1).HeaderText = "X"
DataGridView1.Columns(2).HeaderText = "Y"
DataGridView1.Columns(3).HeaderText = "Z"
For fila = 0 To 3
DataGridView1.Columns(fila).Width = 40
Next fila
txtPuntos.Text = np
grafico = PictureBox1.CreateGraphics
Pincel = New Pen(Color.Red, 1)
Pincel1 = New Pen(Color.Yellow, 3)
brocha = New SolidBrush(Color.Green)
End Sub
Sub MostrarVectoresCuadricula(Vx() As Integer, Vy() As Integer, Vz() As Integer, Ne
As Integer)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -799-
Dim fila As Integer
For fila = 0 To Ne - 1
DataGridView1.Rows(fila).Cells(0).Value = fila
DataGridView1.Rows(fila).Cells(1).Value = Vx(fila)
DataGridView1.Rows(fila).Cells(2).Value = Vy(fila)
DataGridView1.Rows(fila).Cells(3).Value = Vz(fila)
Next
End Sub
Private Sub btnAbrir_Click(sender As Object, e As EventArgs) Handles btnAbrir.Click
IniciarMatriz(A, nf, nc, 0)
RecuperarMatriz(NombreArchivo, A, np, 3)
MatrizVectorXYZ(A, X, Y, relleno, np)
MostrarVectoresCuadricula(X, Y, relleno, np)
End Sub
PUNTO X y R1 R2 R3
0 55 120 1 12 -1
1 130 100 0 11 2
2 190 70 1 3 10
3 320 40 2 4 6
4 360 30 3 5 -1
5 400 110 4 6 32
6 345 125 3 7 31
7 300 143 6 30 8
8 255 170 9 7 -1
9 260 183 8 10 -1
10 220 170 2 11 14
11 175 188 1 10 12
12 70 201 0 11 13
13 82 266 12 16 14
14 247 234 15 10 13
15 269 299 14 16 39
16 93 319 13 17 15
17 100 371 16 18 21
18 217 371 17 20 19
19 260 360 39 18 24
20 220 410 18 21 23
21 110 425 17 22 20
22 110 480 21 23 -1
23 240 460 22 20 24
24 310 450 23 25 19
25 340 450 24 26 37
26 340 400 27 25 36
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -801-
27 330 360 26 28 -1
28 350 320 39 27 29
29 370 310 28 34 30
30 350 260 31 7 29
31 420 250 30 32 -1
32 450 230 33 5 -1
33 470 290 32 38 -1
34 410 300 29 33 -1
35 420 350 36 34 27
36 450 380 37 35 -1
37 460 420 25 38 36
38 500 410 37 33 -1
39 320 320 19 15 28
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -802-
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -803-
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim Grafico As Graphics
Dim BrochaSólida As SolidBrush
Dim pen As Pen
Dim pen1 As Pen
Dim penArbol As Pen
Sub ObtenerRuta(ByVal i As Integer, ByVal j As Integer)
Dim Sij As Integer
Sij = S(i, j)
If Sij = j Then
Ruta(ner) = i
ListBox1.Items.Add(" i " & i & " J " & j & " SIJ " & Sij)
ner = ner + 1
Else
ObtenerRuta(i, Sij)
ObtenerRuta(Sij, j)
End If
End Sub
Sub Graficar(ByVal X() As Single, ByVal Y() As Single, ByRef R(,) As Integer, _
ByVal nf As Integer, ByVal nc As Integer, ByVal ex As Single, ByVal ey As
Single)
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
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -804-
x1 = X(fila) * ex
y1 = Y(fila) * ey
x2 = X(col) * ex
y2 = Y(col) * ey
Grafico.DrawLine(pen, x1, y1, x2, y2)
End If
Next
Next
End Sub
Module Module1
Sub InicioArbol()
Dim contador As Integer = 0
Dim k As Integer
Dim k1 As Integer
Dim filamenor As Integer
Dim menor As Single = 1000
LeerArchivo(X, Y, np)
C(0) = 0
For k = 0 To nc1 - 1
C1(k) = k + 1
Next
While nc1 > 0
menor = 1000
colMenor = 0
filamenor = 0
For k = 0 To nc - 1
p1 = C(k)
For k1 = 0 To nc1 - 1
p2 = C1(k1)
d1 = distancia(X(p1), Y(p1), X(p2), Y(p2))
If (d1 < menor) And d1 > 0 Then
menor = d1
filamenor = C(k)
colMenor = k1
End If
Next
Next
CFila(contador) = filamenor
CCol(contador) = C1(colMenor)
contador = contador + 1
C(nc) = C1(colMenor)
nc = nc + 1
nc1 = nc1 - 1
For k1 = colMenor To nc1 - 1
C1(k1) = C1(k1 + 1)
Next
End While
ne = contador
End Sub
Function distanciaTotalArbol(ByVal CFila() As Integer, ByVal CCol() As Integer,
ByVal np As Integer)
Dim fila As Integer
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -808-
Dim d1 As Single
Dim dt As Single = 0
For fila = 0 To np - 1
d1 = distancia(X(CFila(fila)), Y(CFila(fila)), X(CCol(fila)), Y(CCol(fila)))
dt = dt + d1
Next
Return dt
End Function
End Module
MODULO 2
Option Explicit On
Imports System.IO
Module Module2
Public ne As Integer
Public d1 As Single
Public C(Npuntos) As Integer
Public C1(Npuntos) As Integer
Public CCol(Npuntos) As Integer
Public CFila(Npuntos) As Integer
Public colMenor As Integer
Public Const Npuntos As Integer = 5
Public cont As Integer = 0
Public Cx As Integer = 1
Public Cy As Integer = 1
Public D(Npuntos, Npuntos) As Single
Public destino As Integer = 4
Public ex As Single = 6
Public ey As Single = 2
Public nc As Integer = 1
Public nc1 As Integer = Npuntos - 1
Public ner As Integer = 0
Public np As Integer = Npuntos
Public origen As Integer = 0
Public p1 As Integer
Public p2 As Integer
Public PuntosRelaciones(Npuntos, Npuntos) As Integer
Public Relaciones(Npuntos, Npuntos) As Integer
Public Ruta(Npuntos) As Integer
Public S(Npuntos, Npuntos) As Integer
Public srLector As StreamReader
Public X(Npuntos) As Single
Public Y(Npuntos) As Single
Sub iniciar()
IniciarPantalla(PuntosRelaciones, np, np)
IniciarPantalla(Relaciones, np, np)
IniciarPantalla(S, np, np)
End Sub
Sub LeerArchivo(ByVal X() As Single, ByVal Y() As Single, ByVal nf As Integer)
srLector = New StreamReader("e:\DATOS\puntos2x5.txt")
Dim cadena As String
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -809-
Dim pos As Integer = 0
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
pos = InStr(1, cadena, Chr(9))
If pos > 0 Then
X(fila) = Val(Mid(cadena, 1, pos - 1))
Y(fila) = Val(Mid(cadena, pos + 1, Len(cadena)))
End If
REM srLector.Close()
Next
End Sub
x P(x) acum L 2
1 5,00 5 Q 10
2 20,00 25 C1 0,1
3 40,00 65 C3 5
4 25,00 90 Z 10
5 10,00 100 z 4
SUMA 100
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -813-
Imports System.Drawing
Public Class Form1
Dim Grafico As Graphics
Dim ColorFondo As Color = Color.FromArgb(255, 255, 255)
Dim pen As Pen
Dim pen2 As Pen
Dim pen3 As Pen
Dim valor As Integer = 10
Dim ancho = 600, alto = 400
Dim BrochaSolida As SolidBrush
Sub mostrar(ByVal vector() As Single, ByVal n As Integer)
Dim i As Integer
For i = 0 To n - 1
ListBox1.Items.Add(i & " " & vector(i))
Next
End Sub
Sub MostrarMatriz(ByRef A(,) As Single, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 50
Next
DataGridView1.ColumnCount = 10
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Console.WriteLine()
Next
End Sub
Imports System.IO
Module Module1
Public Const maxfilas As Integer = 365
Public Const nprob As Integer = 10
Public ncol As Integer = 10
Public nfilas As Integer = maxfilas
Public vector(maxfilas) As Single
Public nro(nprob) As Single
Public p(nprob) As Single
Public A(nfilas, ncol) As Single
Public C1 As Single = 0.1
Public C3 As Single = 5
Public Z1 As Single = 10
Public z2 As Single = 4
Public demora As Single = 2 'L
Public hizopedido As Integer = 0
Public Cx As Single = 100
Public Cy As Single = 200
Public ex As Single = 10
Public ey As Single = -10
Public CAcum As Single = 0
Sub RellenarMatriz(ByRef A(,) As Single, ByVal nro() As Single, ByVal vector() As
Single, ByVal np As Integer)
Dim fila As Integer
Dim I1 As Single = 8, I2 As Single, r As Integer
Dim t As Single = 0
Dim pedido As Single
Dim cmantenimiento As Single = 0, caprovisionamiento As Single = 0
Dim Ctotal As Single = 0
fila = 0
' primero inicializamos
A(fila, 0) = nro(fila)
A(fila, 1) = Z1
A(fila, 2) = vector(fila)
I2 = A(fila, 1) - vector(0)
A(fila, 3) = I2
A(fila, 4) = pedido
cmantenimiento = C1 * A(fila, 1)
A(fila, 6) = cmantenimiento
A(fila, 7) = caprovisionamiento
Ctotal = cmantenimiento + caprovisionamiento
A(fila, 8) = Ctotal
CAcum = Ctotal
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -816-
A(fila, 9) = Ctotal
A(fila, 0) = fila
For fila = 1 To nfilas - 1
r = vector(fila)
A(fila, 0) = fila
I1 = A(fila - 1, 3)
A(fila, 5) = 0
If t >= demora Then ' llega el pedido
I1 = I1 + pedido
A(fila - 1, 5) = pedido
t=0
pedido = 0
hizopedido = 0
Else
t=t+1
End If
A(fila, 1) = I1
A(fila, 2) = vector(fila)
I2 = I1 - r
A(fila, 3) = I2
A(fila, 4) = 0
If (I2 < z2) Then
If hizopedido = 0 Then ' solo aumenta cuando no se hizo pedido
pedido = Z1 - I2
A(fila, 4) = pedido
t=0
hizopedido = 1
End If
End If
' calculo de costos
A(fila, 6) = 0
A(fila, 7) = 0
If A(fila, 1) > 0 Then
cmantenimiento = C1 * A(fila, 1)
A(fila, 6) = cmantenimiento
End If
If A(fila, 4) > 0 Then
caprovisionamiento = C3
Else
caprovisionamiento = 0
End If
A(fila, 7) = caprovisionamiento
Ctotal = cmantenimiento + caprovisionamiento
A(fila, 8) = Ctotal
CAcum = CAcum + Ctotal
A(fila, 9) = CAcum
Next
End Sub
Sub GrabarMatriz(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As Integer)
Dim swEscritor = New StreamWriter("E:\DATOS\Invent5x30.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -817-
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Function generar(ByVal nro() As Single, ByVal p() As Single, ByVal n As Integer) As
Integer
Dim r As Integer, ng As Integer, i As Integer
r = Int(Rnd() * 100)
For i = 0 To n - 1
If (p(i) > r) Then
ng = nro(i)
Exit For
End If
Next
Return ng
End Function
Sub rellenar(ByVal vector() As Single, ByVal nro() As Single, ByVal p() As Single,
ByVal nprob As Integer, ByVal nper As Integer)
Dim i As Integer
Randomize()
For i = 0 To nper - 1
vector(i) = generar(nro, p, nprob)
Next
End Sub
Sub Iniciar()
nro(0) = 1 : nro(1) = 2 : nro(2) = 3 : nro(3) = 4 : nro(4) = 5
p(0) = 5
p(1) = 25
p(2) = 65
p(3) = 90 : p(4) = 100
End Sub
End Module
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim p1 As Integer
Dim p2 As Integer
Dim nsr As Integer = 0
Dim fila As Integer
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
Imports System.IO
Module module1
Public tam As Integer = 1
Public Cx As Integer = 10, Cy As Integer = 10
Public npuntos As Integer
Public Matriz(NFilas, NCol) As Integer
Public Const NFilas As Integer = 500, NCol As Integer = 700, maximo = 100
Public Np As Integer = 40
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
Public nseres As Integer = 40
Public vecinos(maximo) As Integer
Public nvecinos As Integer
Public pen As Pen
Public Color As Color
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -821-
Public Grafico As Graphics
Public BrochaSolida As SolidBrush
Public nombreColores As String
Public MColores(50, 3) As Integer
Public Ex As Single = tam
Public ey As Single = -tam
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim nro1 As Integer
Dim nro2 As Integer
Dim resultado As Integer
Dim pen1 As Pen
Dim pen2 As Pen
Dim Color As Color
Dim Grafico As Graphics
Dim BrochaSolida As SolidBrush
Dim Cx As Integer = 300, Cy As Integer = 300
Dim MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Dim ex As Integer = 1, ey As Integer = -1
Dim ancho As Integer = 600, alto As Integer = 600
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
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
Dim factor As Single = 0.1
Dim tam1 As Integer = tam * (1 - factor)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -825-
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, Cx + col * tam + tam * factor, Cy + fila *
tam * ey - tam1 - factor, tam1, tam1)
Next col
Next fila
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
pen1 = New Pen(Color.Red, 2)
pen2 = New Pen(Color.Green, 1)
Grafico = PictureBox1.CreateGraphics
BrochaSolida = New SolidBrush(Color.Blue)
End Sub
Private Sub BtnIniciar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnIniciar.Click
IniciarMatriz(Matriz, nf, nc, 0)
MostrarMatriz(Cx, Cy, Matriz, nf, nc)
End Sub
Private Sub btnTablero_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTablero.Click
BrochaSolida.Color = Color.Blue
Grafico.DrawLine(pen1, 0, Cy, ancho, Cy)
Grafico.DrawLine(pen1, Cx, 0, Cx, alto)
For k = -NCol To NCol
Grafico.DrawString(k, MiFuente, BrochaSolida, Cx + k * tam, Cy)
Grafico.DrawLine(pen2, Cx + k * tam, 0, Cx + k * tam, alto)
Next
For k = -NFilas To NFilas
Grafico.DrawString(k, MiFuente, BrochaSolida, Cx, Cy + k * tam * ey)
Grafico.DrawLine(pen2, 0, Cy + k * tam, ancho, Cy + k * tam)
Next
End Sub
Module Module1
Public Matriz(NFilas, NCol) As Integer
Public Const NFilas As Integer = 10, NCol As Integer = 10, maximo = 5
Public relleno(maximo) As Integer
Public tam As Integer = 30
Public nf As Integer = NFilas, nc As Integer = NCol
Public VUnidades1(NCol) As Integer
Public VDecenas1(NCol) As Integer
Public VCentenas1(NCol) As Integer
Public VMillares1(NCol) As Integer
Public MColores(maximo, 3) As Integer
Sub Iniciarvector(ByRef A() As Integer, ByVal nro As Integer, ByVal inicial As Integer,
ByVal final As Integer)
Dim fila As Integer
For fila = inicial To inicial + final
A(fila) = nro
Next
End Sub
Sub IniciarColores()
MColores(0, 0) = 255
MColores(0, 1) = 255
MColores(0, 2) = 255
MColores(1, 0) = 255
MColores(1, 1) = 0
MColores(1, 2) = 0
MColores(2, 0) = 0
MColores(2, 1) = 0
MColores(2, 2) = 255
MColores(3, 0) = 0
MColores(3, 1) = 255
MColores(3, 2) = 0
MColores(4, 0) = 255
MColores(4, 1) = 255
MColores(4, 2) = 0
End Sub
Imports System.IO
Module Module1
Public srLector As StreamReader
Public A(10) As String
Public B(10) As String
End Module
Imports System.IO
Public Class Form1
Public srLector1 As StreamReader
Public srLector2 As StreamReader
Public swEscritor As StreamWriter
Public A(200) As String
Public B(200) As String
Public nterminos As Integer = 0
11.10 BUSCADOR
Imports System.IO
Module module1
'/*** declaraciones
Public Const maxfilas As Integer = 20, maxcol As Integer = 30
Public Matriz(maxfilas, maxcol) As Integer
Public Cx As Integer = 1, Cy As Integer = 1
Public dir As Integer = 0, valor As Integer = 0
Public final As Integer = 0, cont As Integer = 0
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -833-
Public nfilasPantalla = 22, NcolPantalla = 32
Public srLector As StreamReader
Public nf As Integer
Public nc As Integer
Public Objetos(maxfilas * maxcol)
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Imports System.Drawing
Public Class Form1
Dim fila As Integer
Dim col As Integer
Dim tam As Integer = 20
Dim nf As Integer
Dim nc As Integer
Dim Color As Color
Dim Grafico As Graphics
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -834-
Dim BrochaSólida As SolidBrush
Public Structure Buscador
Public nro As Integer
Public dir1 As Integer, dir2 As Integer, dir3 As Integer, dir4 As Integer ' declarar
matrices de 4
Public Cx As Integer
Public Cy As Integer
Public np As Integer
Public Valor As Integer, rojo As Integer, verde As Integer, azul As Integer, Direc As
Integer
End Structure
Public Objeto1 As Buscador
Sub InicializarObjeto(ByRef Objeto1 As Buscador)
Objeto1.Cx = 14
Objeto1.Cy = 13
Objeto1.rojo = 255
Objeto1.verde = 0
Objeto1.azul = 0
Objeto1.Valor = 1
Objeto1.dir1 = 0
Objeto1.dir2 = 0
Objeto1.dir3 = 0
Objeto1.dir4 = 0
Objeto1.np = 0
Objeto1.nro = 0
End Sub
Se ingresas 4 puntos ( puntos inicial y final de dos rectas) determiner si esos puntos se
Cruzan o no se Cruzan
Module Module1
Sub Main()
Dim resultado1 As Integer = 0 ' " 0 no hay cruce 1 hay cruce
RecuperarPuntos(X, Y, np)
Console.WriteLine(" vector X")
Imprimir(X, np)
Console.WriteLine(" vector Y")
Imprimir(Y, np)
resultado1 = Interseccion(X, Y)
Console.WriteLine()
If resultado1 = 1 Then
Console.WriteLine(" EL valor es =={0} HAY CRUCE ", resultado1)
Else
Console.WriteLine(" EL valor es =={0} no hay cruce ", resultado1)
End If
Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Public X(4) As Single
Public Y(4) As Single
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -839-
Public np As Integer = 4
Public Sub RecuperarPuntos(ByVal X() As Single, ByVal Y() As Single, ByVal nf As
Integer)
Dim fila As Integer
Dim cadena As String
Dim pos As Integer
Dim srLector = New StreamReader("E:\datos\Puntos2x4.txt")
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
pos = InStr(1, cadena, Chr(9))
X(fila) = Mid(cadena, 1, pos - 1)
Y(fila) = Mid(cadena, pos + 1, Len(cadena))
Next
srLector.Close()
End Sub
Function Interseccion(ByVal X() As Single, ByVal Y() As Single) As Integer
Dim resultado As Integer
Dim XA(4) As Single
Dim YA(4) As Single
Dim xmin As Single
Dim ymin As Single
Dim xmax As Single
Dim ymax As Single
Dim px As Single
Dim py As Single
copiar(X, XA, 4)
limites(XA, xmin, xmax)
REM Console.WriteLine(" valores de xmin {0} xmax {1} ", xmin, xmax)
copiar(Y, YA, 4)
limites(YA, ymin, ymax)
If (X(0) = X(2) And Y(0) = Y(2)) Or (X(1) = X(3) And Y(1) = Y(3)) Then
resultado = 0
Else
px = ((X(0) * Y(1) - Y(0) * X(1)) * (X(2) - X(3)) - (X(0) - X(1)) * (X(2) * Y(3) - Y(2) *
X(3))) / ((X(0) - X(1)) * (Y(2) - Y(3)) - (Y(0) - Y(1)) * (X(2) - X(3)))
py = ((X(0) * Y(1) - Y(0) * X(1)) * (Y(2) - Y(3)) - (Y(0) - Y(1)) * (X(2) * Y(3) - Y(2) *
X(3))) / ((X(0) - X(1)) * (Y(2) - Y(3)) - (Y(0) - Y(1)) * (X(2) - X(3)))
If px >= xmin And px <= xmax And py >= ymin And py <= ymax Then
resultado = 1
Else
resultado = 0
End If
End If
Return resultado
End Function
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim px1 As Integer
Dim py1 As Integer
Dim Grafico As Graphics
Dim ColorFondo As Color = Color.FromArgb(255, 255, 255)
Dim pen1 As Pen
Dim pen2 As Pen
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -842-
Dim X(maxfilas) As Single
Dim Y(maxfilas) As Single
Dim Cx As Integer = 100
Dim Cy As Integer = 300
Dim ex As Single = 1
Dim ey As Single = -1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
pen1 = New Pen(Color.FromArgb(255, 0, 0), 2)
pen2 = New Pen(Color.FromArgb(0, 0, 255), 3)
End Sub
Private Sub BtnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub Btndibujar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Btndibujar.Click
Dim fila As Integer
Dim resultado1 As Integer = 0
Dim cadena1 As String
Dim cadenaPos As String
Dim psx As Integer
Dim psy As Integer
Dim pos As Integer
Dim px1 As Integer = 16
Dim py1 As Integer = 6
Dim valor As Integer = 0
Grafico.DrawLine(pen1, 0, Cy, Cx * 2, Cy)
Grafico.DrawLine(pen1, Cx, 0, Cx, Cy * 2)
RecuperarTabla(Tabla, nreg, ncampos)
MostrarTabla(Tabla, nreg, ncampos)
For fila = 0 To nreg - 1
cadena1 = Tabla(fila, 2)
np = Tabla(fila, 1)
cadenaPos = Tabla(fila, 3)
pos = InStr(1, cadenaPos, ";")
psx = Mid(cadenaPos, 1, pos - 1)
psy = Mid(cadenaPos, pos + 1, Len(cadenaPos))
ObtenerVectores(X, Y, np, cadena1)
graficar(X, Y, Cx, Cy, ex, ey, np)
Next
End Sub
Sub graficar(ByVal X() As Single, ByVal Y() As Single, ByVal Cx As Integer, ByVal cy
As Integer, ByVal ex As Single, ByVal ey As Single, ByVal np As Integer)
Dim fila As Integer
For fila = 1 To np
Grafico.DrawLine(pen2, Cx + X(fila - 1) * ex, cy + Y(fila - 1) * ey, Cx + X(fila) *
ex, cy + Y(fila) * ey)
Next
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -843-
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
ListBox1.Items.Clear()
Dim informe As String
Dim retorno As Integer = 0
Dim fila As Integer
Dim resultado1 As Integer = 0
Dim valor As Integer = 0
Dim psx As Integer
Dim psy As Integer
Dim pos As Integer
Dim cadena1 As String
Dim cadenaPos As String
Me.Text = "X = " & e.X & " Y = " & e.Y
px1 = e.X - Cx
py1 = -(e.Y - Cy)
txtX.Text = px1
txtY.Text = py1
X1(0) = px1
Y1(0) = py1
fila = 1
For fila = 0 To nreg - 1
cadena1 = Tabla(fila, 2)
np = Tabla(fila, 1)
cadenaPos = Tabla(fila, 3)
pos = InStr(1, cadenaPos, ";")
psx = Mid(cadenaPos, 1, pos - 1)
psy = Mid(cadenaPos, pos + 1, Len(cadenaPos))
ObtenerVectores(X, Y, np, cadena1)
X1(1) = psx
Y1(1) = psy
valor = 0
For k = 1 To np
X1(2) = X(k - 1) : Y1(2) = Y(k - 1)
X1(3) = X(k) : Y1(3) = Y(k)
resultado1 = Interseccion(X1, Y1)
If resultado1 = 1 Then
valor = 1
Exit For
End If
Next
ListBox1.Items.Add(" EL valor es == " & valor)
If valor = 0 Then
informe = Tabla(fila, 4)
Exit For
End If
Next
If valor = 0 Then
TextBox1.Text = informe
Else
TextBox1.Text = "FUERA"
End If
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -844-
End Sub
End Class
Imports System.IO
Module Module2
Public cadena As String
Public Const maxfilas As Integer = 20
Public Const maxcol As Integer = 20
Public resultado As Integer = 0
Public Tabla(maxfilas, maxfilas) As String
Public X1(maxfilas) As Single
Public Y1(maxfilas) As Single
Public XA(maxfilas) As Single
Public YA(maxfilas) As Single
Public xmin As Single
Public xmax As Single
Public ymin As Single
Public ymax As Single
Public nreg As Integer = 4
Public ncampos As Integer = 5
Public nf As Integer = maxfilas, nc As Integer = maxcol
Public np As Integer
Public Ser As Integer = 1
Public espacio As Integer = 0
Sub limites(ByRef A() As Single, ByRef xmin As Single, ByRef xmax As Single)
Dim fila As Integer
Dim col As Integer
REM primero ordenamos
Dim temp As Single
For fila = 0 To 2
For col = fila + 1 To 3
If (A(col) < A(fila)) Then
temp = A(fila)
A(fila) = A(col)
A(col) = temp
End If
Next col
Next fila
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -846-
xmin = A(1)
xmax = A(2)
End Sub
11.13 MODELADO 3D si tiene los siguientes puntos para un cubo realizar el modelado
3D
CARA X Y Z X Y Z X Y Z X Y Z X Y Z
1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0
2 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0
3 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1
4 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0
5 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0
6 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 1 2 3 4 5 6 7 8 9 10
cubo rx ry rz ex ey ez tx ty tz color
1 0 0 0 8 0.3 4 0 0 0 4 0
2 0 0 0 0.2 2 4 0 0.3 0 5 0
3 0 0 0 8 2 0.2 0 0 4 3 0
4 0 0 0 0.2 2 4 8 0.3 0 2 0
5 0 0 0 2 1 0.2 1 0.3 0 6 0
6 0 0 0 5 2 0.2 3 0.3 0 1 0
7 0 0 0 1 2 0.1 0 0.3 0 4 0
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -847-
Module Module1
Public Color1 As Integer = 1
Public PosObjeto As Integer = 0
Public Const limite As Integer = 200
Public Const maxcol As Integer = 15
Public Const maxfilas As Integer = 6
Public Const maxplanos As Integer = 10
Public MXYZ(maxfilas, maxcol) As Single
Public MXYZ1(maxfilas, maxcol) As Single ' matriz copia
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -848-
Public MXYZ2(maxfilas, maxcol) As Single ' matriz copia
Public Mobjetos(maxfilas, maxcol) As Single ' matriz de ojetoscopia
Public Mplanos(maxplanos, maxfilas, maxcol) As Single ' matriz copia 2
Public Mplanos2(maxplanos, maxfilas, maxcol) As Single 'copia de mplanos para
trabajar
x2 = A(fila, 3)
y2 = A(fila, 4)
z2 = A(fila, 5)
x3 = A(fila, 6)
y3 = A(fila, 7)
z3 = A(fila, 8)
AX = x2 - x1
Ay = y2 - y1
Az = z2 - z1
Bx = x3 - x2
By = y3 - y2
Bz = z3 - z2
NX = Ay * Bz - Az * By
Ny = AX * Bz - Az * Bx
Nz = AX * By - Ay * Bx
'PRODUCTO(CRUZ)
R = Math.Sqrt(NX * NX + Ny * Ny + Nz * Nz)
If R > 0 Then
Nx1 = NX / R
Else
Nx1 = 1000
End If
If R > 0 Then
Ny1 = Ny / R
Else
Ny1 = 1000
End If
If R > 0 Then
Nz1 = Nz / R
Else
Nz1 = 1000
End If
Pe = Nx1 * 0 + Ny1 * 0 + Nz1 * D
Normales(fila, 0) = Nx1
Normales(fila, 1) = Ny
Normales(fila, 2) = Nz1
If Nz1 > mayor Then mayor = Nz1
Normales(fila, 3) = Pe
Next
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -852-
Return mayor
End Function
For fila = 0 To nf - 1
For col = 0 To ncol - 1
A(fila, col * 3) = A(fila, col * 3) + tx
A(fila, col * 3 + 1) = A(fila, col * 3 + 1) + ty
A(fila, col * 3 + 2) = A(fila, col * 3 + 2) + tz
Next
Next
End Sub
Imports System.Drawing
Imports System.IO
Imports System.Drawing.Drawing2D
Public Class Form1
Dim MiFuente As New Font("Verdana", 10, FontStyle.Bold)
Sub Iniciar()
DataGridView1.ColumnCount = 6
DataGridView1.RowCount = 5
Dim fila As Integer
For fila = 1 To 5
DataGridView1.Columns(fila).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
RecuperarMatriz(nombrearchivo, MXYZ, nf, nc)
CopiarMatriz(MXYZ, MXYZ1, nf, nc)
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "UNIDAD"
DataGridView1.Columns(2).HeaderText = "EjeX"
DataGridView1.Columns(3).HeaderText = "Eje Y"
DataGridView1.Columns(4).HeaderText = "Eje Z"
DataGridView1.Columns(5).HeaderText = "D o W"
End Sub
Ex = CSng(DataGridView1.Rows(2).Cells(2).Value)
Ey = CSng(DataGridView1.Rows(2).Cells(3).Value)
Ez = CInt(DataGridView1.Rows(2).Cells(4).Value)
modo = DataGridView1.Rows(3).Cells(2).Value
vel = DataGridView1.Rows(3).Cells(3).Value
Grafico.Clear(Color.White)
For fila = 0 To Nobj - 1
' fila = PosObjeto
ObtenerPlanoObjeto(Mplanos, MXYZ1, nf, nc, fila)
Color1 = CInt(DataGridView2.Rows(fila).Cells(10).Value)
CopiarMatriz(MXYZ1, MXYZ2, nf, nc)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -856-
RotacionXYZ(MXYZ2, AnguloX, AnguloY, AnguloZ, nf, nc)
EscaladoXYZ(MXYZ2, Ex, Ey, Ez, nf, nc)
TraslacionXYZ(MXYZ2, tx, ty, tz, nf, nc)
graficar(MXYZ2, Normales, nf, nc, Color1)
Next
End Sub
Private Sub TxtEscala_KeyDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TxtEscalado.KeyDown
Select Case e.KeyCode
Case 65 ' A inverso de X
If Ex >= -limite Then
Ex = Ex - 1
Else
Ex = limite
End If
Case 66 ' B Inverso De Y
If Ey >= -limite Then
Ey = Ey - 1
Else
Ey = limite
End If
DataGridView2.RowCount = Nobj + 1
DataGridView2.ColumnCount = NcObj + 1
DataGridView2.Columns(0).HeaderText = "Objeto"
DataGridView2.Columns(1).HeaderText = "ROx"
DataGridView2.Columns(2).HeaderText = "ROy"
DataGridView2.Columns(3).HeaderText = "ROz"
DataGridView2.Columns(4).HeaderText = "EOx"
DataGridView2.Columns(5).HeaderText = "EOy"
DataGridView2.Columns(6).HeaderText = "EOz"
DataGridView2.Columns(7).HeaderText = "TOx"
DataGridView2.Columns(8).HeaderText = "TOy"
DataGridView2.Columns(9).HeaderText = "TOz"
DataGridView2.Columns(10).HeaderText = "Color"
For fila = 0 To NcObj
DataGridView2.Columns(fila).Width = 40
Next
txtNobj.Text = PosObjeto
End Sub
Private Sub Btnauto_Click(sender As Object, e As EventArgs) Handles Btnauto.Click
Timer1.Interval = vel
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If AnguloX <= 360 * 5 Then
AnguloX = AnguloX + 1
AnguloY = AnguloY + 1
AnguloZ = AnguloZ + 1
tx = tx + 0.1
ty = ty + 0.1
tz = tz + 0.1
Ex = Ex + 0.1
Ey = Ey + 0.1
Ez = Ez + 0.1
Else
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -859-
AnguloX = 0
AnguloY = 0
AnguloZ = 0
tx = 0
ty = 0
tz = 0
Ex = 10
Ey = 10
Ez = 10
End If
DataGridView1.Rows(0).Cells(2).Value = AnguloX
DataGridView1.Rows(0).Cells(3).Value = AnguloY
DataGridView1.Rows(0).Cells(4).Value = AnguloZ
DataGridView1.Rows(1).Cells(2).Value = tx
DataGridView1.Rows(1).Cells(3).Value = ty
DataGridView1.Rows(1).Cells(4).Value = tz
DataGridView1.Rows(2).Cells(2).Value = Ex
DataGridView1.Rows(2).Cells(3).Value = Ey
DataGridView1.Rows(2).Cells(4).Value = Ez
BtnIniciarTodo_Click(sender, e)
End Sub
Private Sub BtnDetener_Click(sender As Object, e As EventArgs) Handles
BtnDetener.Click
Timer1.Stop()
End Sub
Private Sub btnCargarObjeto_Click(sender As Object, e As EventArgs) Handles
btnCargarObjeto.Click
RecuperarMatriz(nombrearchivoObjetos, Mobjetos, Nobj, NcObj)
For fila = 0 To Nobj - 1
For col = 0 To NcObj - 1
DataGridView2.Rows(fila).Cells(col).Value = Mobjetos(fila, col)
Next
Next
End Sub
DataGridView2.Rows(PosObjeto).Cells(1).Value = RoX
DataGridView2.Rows(PosObjeto).Cells(2).Value = Roy
DataGridView2.Rows(PosObjeto).Cells(3).Value = Roz
BtnObjeto_Click(sender, e)
txtRotObjeto.Text = ""
End Sub
BtnIniciarTodo_Click(sender, e)
txtTraslacion.Text = ""
End Sub
valorProp = DataGridView2.Rows(robjeto).Cells(rprop).Value
Select rprop
Case 1, 2, 3
If valorProp < 3600 Then
valorProp = valorProp + 1
Else
valorProp = 0
End If
Case 4, 5, 6 'escalado
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -865-
If valorProp < 400 Then
valorProp = valorProp + 1
Else
valorProp = 0
End If
Case 7, 8, 9 'traslado
If valorProp < 400 Then
valorProp = valorProp + 1
Else
valorProp = 0
End If
End Select
PosObjeto = robjeto
DataGridView2.Rows(PosObjeto).Cells(rprop).Value = valorProp
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
aleatorio()
BtnObjeto_Click(sender, e)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
aleatorio()
End Sub
Private Sub btnDetener2_Click(sender As Object, e As EventArgs) Handles
btnDetener2.Click
Timer2.Stop()
End Sub
End Class
MODELADO 3D
La siguiente aplicación permite realizar las operaciones de rotación, traslacion y
escalado 3D
Permite dibujar las siguientes primitivas
Plano
Caja
Piramide
Cono
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -866-
Esfera
Figura Cargada del archivo
Realiza las operaciones
Borrar
Actualizar. Actualiza los datos que figuran en la cuadricula
Operar. Dibuja las primitivas
Con las teclas X,Y Z se realiza las operaciones de rotación trsalacion y escalado
Y se puede escoger tanto para el objtfo como el fondo
Se trabaja con rellenado usando Vectores Normales
Posteriormente se vera las coordenadas globales y locales
Sub Iniciar()
DataGridView1.ColumnCount = 6
DataGridView1.RowCount = 7
Dim fila As Integer
For fila = 1 To 5
DataGridView1.Columns(fila).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "UNIDAD"
DataGridView1.Columns(2).HeaderText = "EjeX"
DataGridView1.Columns(3).HeaderText = "Eje Y"
DataGridView1.Columns(4).HeaderText = "Eje Z"
DataGridView1.Columns(5).HeaderText = "DW/paso"
MnuOperar_Click(sender, e)
TxtEscalado.Text = ""
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If cont < 500 Then
AnguloX = AnguloX + prot
DataGridView1.Rows(0).Cells(2).Value = AnguloX
Else
If cont < 1000 Then
AnguloY = AnguloY + prot
DataGridView1.Rows(0).Cells(3).Value = AnguloY
Else
If cont < 2000 Then
AnguloZ = AnguloZ + prot
DataGridView1.Rows(0).Cells(4).Value = AnguloZ
Else
tx = 0
ty = 0
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -873-
tz = 0
cont = 0
End If
End If
End If
cont = cont + 1
MnuActualizar_Click(sender, e)
Grafico.Clear(Color.Black)
MnuOperar_Click(sender, e)
End Sub
ancho = DataGridView1.Rows(4).Cells(2).Value
alto = DataGridView1.Rows(4).Cells(3).Value
Profundidad = DataGridView1.Rows(4).Cells(4).Value
TipoObjeto = DataGridView1.Rows(4).Cells(5).Value
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -874-
modorelleno = DataGridView1.Rows(3).Cells(2).Value
rojo = DataGridView1.Rows(5).Cells(2).Value
verde = DataGridView1.Rows(5).Cells(3).Value
azul = DataGridView1.Rows(5).Cells(4).Value
Transparencia = DataGridView1.Rows(5).Cells(5).Value
rojo1 = DataGridView1.Rows(6).Cells(2).Value
verde1 = DataGridView1.Rows(6).Cells(3).Value
azul1 = DataGridView1.Rows(6).Cells(4).Value
Transparencia1 = DataGridView1.Rows(6).Cells(5).Value
End Sub
Private Sub MnuPiramide_Click(sender As Object, e As EventArgs) Handles
MnuPiramide.Click
TipoObjeto = 2
DataGridView1.Rows(4).Cells(5).Value = TipoObjeto
MnuOperar_Click(sender, e)
End Sub
'***************mdoulo 1
Imports System.IO
Module Module1
Public PonerCoord As Integer = 1 ' pone cooordendas
Public rojo As Integer = 255
Public verde As Integer = 255
Public azul As Integer = 255
Public Transparencia As Integer = 0
Public rojo1 As Integer = 0
Public verde1 As Integer = 0
Public azul1 As Integer = 0
Public Transparencia1 As Integer = 0
Public alto As Single = 1
Public ancho As Single = 1
Public AnguloX As Integer = 0
Public AnguloY As Integer = 0
Public AnguloZ As Integer = 0
Public brocha As SolidBrush
Public BrochaCoord As SolidBrush
Public Cad() As String = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A"}
Public CadCaras(maximo) As String
Public CadCarasTemp(maximo) As String
Public CadenasCubo() As String = {"000003002001", "001002006005",
"004005006007", _
"000004007003", "003007006002", "000001005004",
"000003002001"}
Public CadenasPiramide() As String = {"000001002003", "001004002", "002004003",
"003004000", "000004001"}
Public CadenasPlano() As String = {"000001002003"}
Public CadenaEsfera(maximo) As String
Public cont As Integer
Public CuboX() As Single = {0, 1, 1, 0, 0, 1, 1, 0, 0}
Public CuboY() As Single = {0, 0, 1, 1, 0, 0, 1, 1, 0}
Public CuboZ() As Single = {0, 0, 0, 0, 1, 1, 1, 1, 0}
Public Cx As Integer = 200
Public Cy As Integer = 200
Public Cz As Integer = 0
Public D As Single = 2000
Public EsferaX(maximo) As Single
Public EsferaY(maximo) As Single
Public EsferaZ(maximo) As Single
Public Ex As Single = 80
Public Ey As Single = 80
Public Ez As Integer = 80
Public Grafico As Graphics
Public limiteE As Integer = 200
Public limiteT As Integer = 200
Public Const maximo As Integer = 1200
Public modorelleno As Integer = 3
Public ncaras As Integer
Public NombreArchivo As String = "E:\datos\esfera5x5.txt"
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -877-
Public NormalW(maximo) As Single
Public NormalX(maximo) As Single
Public NormalY(maximo) As Single
Public NormalZ(maximo) As Single
Public nv As Integer = 900 '
Public Pen As Pen
Public pesca As Single = 1
Public PiramideX() As Single = {0, 2, 2, 0, 1, 0}
Public PiramideY() As Single = {0, 0, 0, 0, 2, 0}
Public PiramideZ() As Single = {0, 0, 2, 2, 1, 0}
Public PlanoX() As Single = {0, 1, 1, 0, 0}
Public PlanoY() As Single = {0, 0, 1, 1, 0}
Public PlanoZ() As Single = {0, 0, 0, 0, 0}
Public PlumaCoord As Pen
Public Profundidad As Single = 1
Public prot As Single = 10
Public ptras As Single = 1
Public ring As Integer = 16
Public Segmentos As Integer = 16
Public tipo As Integer
Public TipoObjeto As Integer = 1 ' es caja
Public tx As Single = 0
Public ty As Single = 0
Public tz As Single = 0
Public vel As Integer = 10
Public WX(maximo) As Single
Public WY(maximo) As Single
Public WZ(maximo) As Single
End Module
'***************** mdoulo 2
Imports System.IO
Module Module2
Sub ImprimirVector(CadCaras() As String, n As Integer)
Dim fila As Integer
For fila = 0 To n - 1
Console.WriteLine(" {0} {1} {2}", fila, vbTab, CadCaras(fila))
Next
End Sub
Sub ObtenerCarasEsfera(CadCaras() As String, ByRef ncaras As Integer, np As
Integer)
Dim fila, cont As Integer
For fila = 0 To ncaras - 1
CadCarasTemp(fila) = ""
CadCarasTemp(fila) = CadCarasTemp(fila) + Format(fila, "00#") + Format(fila +
1, "00#") + _
Format(fila + np + 1, "00#") + Format(fila + np, "00#")
Next
cont = 0 ' eliminando las caras fallidas
For fila = 0 To ncaras - 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -878-
If fila Mod np = np - 1 Then Continue For
CadCaras(cont) = CadCarasTemp(fila)
cont = cont + 1
Next
ncaras = cont
End Sub
Function ObtenerNormales(X() As Single, Y() As Single, Z() As Single, _
XNORM() As Single, YNORM() As Single, ZNORM() As Single,
WNORM() As Single, _
Cadenas() As String, ncaras As Integer)
Dim Cadena As String
Dim p0, p1, p2 As Integer
Dim mayor As Single = -100000
Dim Pe As Single, R As Single
Dim AX As Single, Ay As Single, Az As Single, Bx As Single, By As Single, Bz As
Single
Dim NX As Single, Ny As Single, Nz As Single, Nx1 As Single, Ny1 As Single, Nz1
As Single
Dim x0 As Single, y0 As Single, z0 As Single
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
For fila = 0 To ncaras - 1
Cadena = Cadenas(fila)
p0 = Val(Mid(Cadena, 1, 3))
p1 = Val(Mid(Cadena, 4, 3))
p2 = Val(Mid(Cadena, 7, 3))
x0 = X(p0)
y0 = Y(p0)
z0 = Z(p0)
x1 = X(p1)
y1 = Y(p1)
z1 = Z(p1)
x2 = X(p2)
y2 = Y(p2)
z2 = Z(p2)
AX = x1 - x0
Ay = y1 - y0
Az = z1 - z0
Bx = x2 - x1
By = y2 - y1
Bz = z2 - z1
NX = Ay * Bz - Az * By
Ny = AX * Bz - Az * Bx
Nz = AX * By - Ay * Bx
'PRODUCTO(CRUZ)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -879-
R = Math.Sqrt(NX * NX + Ny * Ny + Nz * Nz)
If R > 0 Then
Nx1 = NX / R
Ny1 = Ny / R
Nz1 = Nz / R
Else
Nx1 = 1000
Ny1 = 1000
Nz1 = 1000
End If
Pe = Nx1 * 0 + Ny1 * 0 + Nz1 * D
XNORM(fila) = Nx1
YNORM(fila) = Ny1
ZNORM(fila) = Nz1
If Nz1 > mayor Then mayor = Nz1
WNORM(fila) = Pe
Next
Return mayor
End Function
Sub CopiarVertices(X() As Single, Y() As Single, Z() As Single, _
X1() As Single, Y1() As Single, Z1() As Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
X1(fila) = X(fila)
Y1(fila) = Y(fila)
Z1(fila) = Z(fila)
Next
End Sub
Sub CopiarCaras(Caras() As String, Caras1() As String, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
Caras1(fila) = Caras(fila)
Next
End Sub
Sub EscaladoXYZ(X() As Single, Y() As Single, Z() As Single, _
ByVal Ex As Single, ByVal Ey As Single, ByVal Ez As Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
X(fila) = X(fila) * Ex
Y(fila) = Y(fila) * Ey
Z(fila) = Z(fila) * Ez
Next
End Sub
Sub TraslacionXYZ(X() As Single, Y() As Single, Z() As Single, _
ByVal tx As Single, ByVal ty As Single, ByVal tz As Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
X(fila) = X(fila) + tx
Y(fila) = Y(fila) + ty
Z(fila) = Z(fila) + tz
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -880-
Next
End Sub
Sub RotacionXYZ(X() As Single, Y() As Single, Z() As Single, _
ByVal AnguloX As Single, ByVal AnguloY As Single, ByVal anguloZ As
Single, nf As Integer)
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim fila As Integer = 0
REM rotacion X
Dim arx = AnguloX * Math.PI / 180
For fila = 0 To nf - 1
x1 = X(fila)
y1 = Y(fila)
z1 = Z(fila)
x2 = x1
y2 = CSng(y1 * Math.Cos(arx) - z1 * Math.Sin(arx))
z2 = CSng(y1 * Math.Sin(arx) + z1 * Math.Cos(arx))
X(fila) = x2
Y(fila) = y2
Z(fila) = z2
Next
REM rotacion Y
Dim ary = AnguloY * Math.PI / 180
For fila = 0 To nf - 1
x1 = X(fila)
y1 = Y(fila)
z1 = Z(fila)
x2 = CSng(x1 * Math.Cos(ary) - z1 * Math.Sin(ary))
y2 = y1
z2 = CSng(-x1 * Math.Sin(ary) + z1 * Math.Cos(ary))
X(fila) = x2
Y(fila) = y2
Z(fila) = z2
Next
REM rotacion Z
Dim arz = anguloZ * Math.PI / 180
For fila = 0 To nf - 1
x1 = X(fila)
y1 = Y(fila)
z1 = Z(fila)
x2 = CSng(x1 * Math.Cos(arz) - y1 * Math.Sin(arz))
y2 = CSng(x1 * Math.Sin(arz) + y1 * Math.Cos(arz))
z2 = z1
X(fila) = x2
Y(fila) = y2
Z(fila) = z2
Next
End Sub
Sub IniciarVector(A() As Single, np As Integer, tipo As Integer, valor As Integer)
Dim fila As Integer
For fila = 0 To np - 1
If tipo = 1 Then
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -881-
A(fila) = fila
Else
A(fila) = valor
End If
Next
End Sub
Sub Main()
ncaras = ring * Segmentos
ObtenerCarasEsfera(CadCaras, ncaras, ring)
ImprimirVector(CadCaras, ncaras)
Console.ReadLine()
End Sub
End Module
Hoy quería presentar un tema un poco relacionado con la entrada sobre combinatoria
algorítmica pero más relacionado con lo que considero que va a ser el futuro de la
computación y (¿por qué no?) un poco de biología. Además aprovecho para
adelantarme a wikipedia que casi no tiene información al respecto de esto.
Empecemos por la parte biológica. El ADN (DNA en inglés, ácido desoxirribonucleico)
es básicamente la información de todo lo que forma un ser vivo. Cada célula tiene
nuestro ADN y éste es quién dicta qué se forma y cuando y de qué manera. Realmente
lo que nos interesa de esto es que es una doble cadena de nucleótidos.
Ejemplo de cadena
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -882-
La primer parte que nos interesa de todo esto es que en esta doble cadena las dos
partes están pegadas entre sí por una regla muy sencilla. Si de un lado hay una
Adenina, del otro hay una Timina y si de un lado hay una Citosina, del otro hay una
Guanina, por lo que si las escribimos como lista, siempre se ve del siguiente estilo.
ATGTTAACGGTG…
TACAATTGCCAC…
Resulta que uno de los problemas con que TODA la información de cómo estamos
formados esté ahí es que si se modifica en una célula, esa célula puede empezar a
funcionar diferente, a producir otras cosas. Eso es justamente lo que hace un virus. Un
virus no tiene la capacidad de reproducirse solo, pero puede llegar a una célula,
inyectar su ADN y hacer que la célula empiece a producir copias del virus (adentro de
ella) hasta que explota y los virus nuevos van infectando células nuevas hasta matar al
organismo. Sin embargo, como este es un problema que lleva suficiente tiempo, las
células han desarrollado medios para evitar esto (hasta cierto punto). Lo que tienen son
una enzimas llamadas enzimas de corte, que van leyendo una parte del ADN y si
encuentra cierta secuencia (ajena al ADN usual, como lo que pondría un virus) cortan
el ADN en ese momento.
Module Module2
Function Replicar(cadena As String) As String
Dim fila As Integer
Dim letra1 As String = "A"
Dim letra2 As String = "A"
Dim cadena2 As String = ""
For fila = 0 To Len(cadena) - 1
letra1 = cadena(fila)
Select Case letra1
Case "A" : letra2 = "T"
Case "T" : letra2 = "A"
Case "C" : letra2 = "G"
Case "G" : letra2 = "C"
End Select
cadena2 = cadena2 + letra1 + letra2
Next
Return cadena2
End Function
Function EvaluarCadena(ByVal adn As String) As Boolean
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -883-
Dim largo As Integer, col As Integer
Dim valor As Boolean = True
Dim letra As Char, letra1 As Char
largo = Len(adn)
If largo Mod 2 <> 0 Then
valor = False
Else
For col = 0 To largo - 2 Step 2
letra = adn(col)
letra1 = adn(col + 1)
Select Case letra
Case "A" : If letra1 <> "T" Then
valor = False
Exit For
End If
Case "T" : If letra1 <> "A" Then
valor = False
Exit For
End If
Case "C" : If letra1 <> "G" Then
valor = False
Exit For
End If
Case "G" : If letra1 <> "C" Then
valor = False
Exit For
End If
Case Else
valor = False
Exit For
End Select
Next
End If
EvaluarCadena = valor
End Function
Sub dividir(adn As String, ByRef adn1 As String, ByRef adn2 As String)
Dim col As Integer
adn1 = "" : adn2 = ""
For col = 0 To Len(adn) - 1
If (col Mod 2 = 0) Then
adn1 = adn1 + adn(col)
Else
adn2 = adn2 + adn(col)
End If
Next
End Sub
End Module
Module Module1
Sub Main()
Dim resultado As Boolean
Dim adn As String = "ATCGTA", adn1 As String = "", adn2 As String = ""
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -884-
Console.WriteLine(" Ingrese secuencia")
adn1 = Console.ReadLine
Console.WriteLine("ADN Original {0}", adn)
resultado = EvaluarCadena(adn1)
If resultado = True Then
Console.WriteLine("secuencia correcta")
Else
Console.WriteLine("secuencia INCORRECTA")
End If
If resultado = True Then
dividir(adn, adn1, adn2)
Console.WriteLine("CADENAS DIVIDIDAS")
Console.WriteLine("Cadena 1 {0}", adn1)
Console.WriteLine("Cadena 2 {0}", adn2)
Console.WriteLine("Cadenas Replicada")
Console.WriteLine("Cadena 1 {0}", Replicar(adn1))
Console.WriteLine("Ccadena 2 {0}", Replicar(adn2))
End If
Console.ReadLine()
End Sub
End Module
Cadena
Cadena1 izquierda I
Cadena2 Cadena derecha D
k=k+1
CadR(k) = Cadena1R
k=k+1
CadR(k) = Cadena2R
Console.WriteLine("cadena replicada1 IZ {0} ", Cadena1R)
Console.WriteLine("cadena replicada2 DER {0} ", Cadena2R)
If cont < lim Then
ReplicarADN(Cadena1R, cont + 1, lim)
ReplicarADN(Cadena2R, cont + 1, lim)
End If
End Sub
Function Replicar(cadena As String, tipo As Integer) As String
Dim fila As Integer
Dim letra1 As String = "A"
Dim letra2 As String = "B"
Dim cadena2 As String = ""
For fila = 0 To Len(cadena) - 1
letra1 = cadena(fila)
Select Case letra1
Case "A" : letra2 = "T"
Case "T" : letra2 = "A"
Case "C" : letra2 = "G"
Case "G" : letra2 = "C"
End Select
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -886-
Select Case tipo
Case 1 : cadena2 = cadena2 + letra2 + letra1 ' izquierdo
Case 2 : cadena2 = cadena2 + letra1 + letra2 ' derecho
End Select
Next
Return cadena2
End Function
Sub ImprimirCadenas(cadena() As String, nf As String)
Dim fila As Integer
For fila = 0 To nf + 1
Console.WriteLine("{0} {1} ", fila, cadena(fila))
Next
End Sub
Sub dividir(adn As String, ByRef adn1 As String, ByRef adn2 As String)
Dim col As Integer
adn1 = "" : adn2 = ""
For col = 0 To Len(adn) - 1
If (col Mod 2 = 0) Then
adn1 = adn1 + adn(col)
Else
adn2 = adn2 + adn(col)
End If
Next
End Sub
Sub IniciarMatriz(A(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
' A(fila, col) = Str(fila) + ":" + Str(col)
A(fila, col) = ""
Next
Next
End Sub
Sub ImprimirMatriz(A(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write(" {0} {1} ", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
Secuencia ADN
Realizar la siguiente secuencia
Secuencia Origen Produce
1 A H
2 B M
secuencia AB aleatoria de acuerdo a
3 HM una tas
Secuencia AB aletoria a la mitad de
4 MH la tasa
5 H X
6 M Y
7 X Muere
8 Y Muere
Module Module1
Public cadena As String
Dim ng As Integer = 20
Dim nletras As Integer = 8
Dim tnat As Integer = 10
Sub Main()
Randomize()
Dim fila As Integer
cadena = "ABBA"
cadena = generar(nletras)
cadena = cadena + " "
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -889-
Console.WriteLine("Cadena Original es {0} ", cadena)
For fila = 1 To ng
cadena = reemplazar(cadena) + " "
Console.WriteLine(" fila {0,2} cadena es {1} ", fila, cadena)
Next
Console.ReadLine()
End Sub
Function reemplazar(cadena As String) As String
Dim pos As Integer
Dim r As Integer
Dim Cadtemporal As String = ""
pos = 0
Do While (pos < Len(cadena) - 1)
If cadena(pos) = "H" And cadena(pos + 1) = "M" Then
r = Int(Rnd() * tnat)
Cadtemporal = Cadtemporal + generarAB(r)
pos = pos + 2
Else
If cadena(pos) = "M" And cadena(pos + 1) = "H" Then
r = Int(Rnd() * tnat / 2)
Cadtemporal = Cadtemporal + generarAB(r)
pos = pos + 2
Else
If cadena(pos) = "A" Then
Cadtemporal = Cadtemporal + "H"
pos = pos + 1
Else
If cadena(pos) = "B" Then
Cadtemporal = Cadtemporal + "M"
pos = pos + 1
Else
If cadena(pos) = "H" Then
Cadtemporal = Cadtemporal + "X"
pos = pos + 1
Else
If cadena(pos) = "M" Then
Cadtemporal = Cadtemporal + "Y"
pos = pos + 1
Else
If cadena(pos) = "X" Then
Cadtemporal = Cadtemporal + ""
pos = pos + 1
Else
If cadena(pos) = "Y" Then
Cadtemporal = Cadtemporal + ""
pos = pos + 1
Else
Cadtemporal = Cadtemporal + cadena(pos)
pos = pos + 1
End If
End If
End If
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -890-
End If
End If
End If
End If
End If
Loop
Return Cadtemporal
End Function
Function generar(ne As Integer) As String
Dim fila As Integer
Dim r As Integer
Dim cadena As String = ""
For fila = 0 To ne
r = 1 + Int(Rnd() * 6)
Select Case r
Case 1 : cadena = cadena + "A"
Case 2 : cadena = cadena + "B"
Case 3 : cadena = cadena + "H"
Case 4 : cadena = cadena + "M"
Case 5 : cadena = cadena + "X"
Case 6 : cadena = cadena + "Y"
End Select
Next
Return cadena
End Function
Function generarAB(ne As Integer) As String
Dim fila As Integer
Dim r As Integer
Dim cadena As String = ""
For fila = 0 To ne - 1
r = 1 + Int(Rnd() * 100)
If r < 50 Then
cadena = cadena + "A"
Else
cadena = cadena + "B"
End If
Next
Return cadena
End Function
End Module
Module Module1
Public Const maxfilas As Integer = 1000
Public cadenas(maxfilas) As String
Public grafico As Graphics
Public cadena As String
Public nletras As Integer = 20
Public tnat As Integer = 10
Public ngen As Integer = 50
Function reemplazar(cadena As String) As String
Dim pos As Integer
Dim r As Integer
Dim Cadtemporal As String = ""
pos = 0
Do While (pos < Len(cadena) - 1)
If cadena(pos) = "H" And cadena(pos + 1) = "M" Then
r = Int(Rnd() * tnat)
Cadtemporal = Cadtemporal + "X" + generarAB(r) + "Y"
pos = pos + 2
Else
If cadena(pos) = "M" And cadena(pos + 1) = "H" Then
r = Int(Rnd() * tnat * 0.5)
Cadtemporal = Cadtemporal + "Y" + generarAB(r) + "X"
pos = pos + 2
Else
If cadena(pos) = "A" Then
Cadtemporal = Cadtemporal + "H"
pos = pos + 1
Else
If cadena(pos) = "B" Then
Cadtemporal = Cadtemporal + "M"
pos = pos + 1
Else
If cadena(pos) = "H" Then
Cadtemporal = Cadtemporal + "X"
pos = pos + 1
Else
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -892-
If cadena(pos) = "M" Then
Cadtemporal = Cadtemporal + "Y"
pos = pos + 1
Else
If cadena(pos) = "X" Then
Cadtemporal = Cadtemporal + ""
pos = pos + 1
Else
If cadena(pos) = "Y" Then
Cadtemporal = Cadtemporal + ""
pos = pos + 1
Else
Cadtemporal = Cadtemporal + cadena(pos)
pos = pos + 1
End If
End If
End If
End If
End If
End If
End If
End If
Loop
Return Cadtemporal
End Function
Function generar(ne As Integer) As String
Dim fila As Integer
Dim r As Integer
Dim cadena As String = ""
For fila = 0 To ne
r = 1 + Int(Rnd() * 6)
Select Case r
Case 1 : cadena = cadena + "A"
Case 2 : cadena = cadena + "B"
Case 3 : cadena = cadena + "H"
Case 4 : cadena = cadena + "M"
Case 5 : cadena = cadena + "X"
Case 6 : cadena = cadena + "Y"
End Select
Next
Return cadena
End Function
Function generarAB(ne As Integer) As String
Dim fila As Integer
Dim r As Integer
Dim cadena As String = ""
For fila = 0 To ne - 1
r = 1 + Int(Rnd() * 100)
If r < 50 Then
cadena = cadena + "A"
Else
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -893-
cadena = cadena + "B"
End If
Next
Return cadena
End Function
End Module
Imports System.Drawing
Module Module2
Public filacadena As Integer = 0
Public filagrafico As Integer = 0
Public total As Integer = te1 + te2 + te3
Public AnchoGrafico As Integer = 600
Public Altografico As Integer = 400
Public sepax As Integer = 80
Public sepay As Integer = 16
Public grafico As Graphics
Public pen As Pen
Public brocha As SolidBrush
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -896-
Public nf As Integer = 0
Public te1 As Integer = 2 '(1, 2)
Public te2 As Integer = 4 '(2, 3, 4)
Public te3 As Integer = 3 '(2, 3)
Public NroProductos As Integer = 2
Public cadenas(50) As String
Public ex As Integer = 1
Public ey As Integer = 1
Public cx As Integer = 10
Public cy As Integer = 20
Public cont As Integer = 0
Function CadenaProducto(NroProductos As Integer, te1 As Integer, te2 As Integer,
te3 As Integer, ByRef nf As Integer) As String()
Randomize()
Dim cadena1 As String = ""
Dim cadena2 As String = ""
Dim cadena3 As String = ""
Dim rte1, rte2, rte3 As Integer
Dim fila, k As Integer
Dim faltante As Integer
Dim cadtotal As String = ""
Dim letra As String
Dim largo1, largo2, largo3 As Integer
For k = 0 To NroProductos - 1
'rte1 = 1 + Int(Rnd() * te1)
rte1 = te1
For fila = 0 To rte1 - 1
If fila < 10 Then
letra = Chr(65 + k) & "0" + Str(fila) & "1"
Else
letra = Chr(65 + k) + Str(fila) & "1"
End If
cadena1 = cadena1 + letra
Next
cadena1 = QuitarEspacios(cadena1)
largo1 = largoCadena(cadena1)
largo2 = largoCadena(cadena2)
faltante = largo1 - largo2
If faltante > 0 Then
' completa la cadena 2 al mismo largo que la cadena 1
For fila = 0 To faltante - 1
letra = "F000"
cadena2 = cadena2 + letra
Next
End If
' aumenta a la cadena 2
'rte2 = 2 + Int(Rnd() * te2)
rte2 = te2
For fila = 0 To rte2 - 1
If fila < 10 Then
letra = Chr(65 + k) & "0" + Str(fila + rte1) & "2"
Else
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -897-
letra = Chr(65 + k) + Str(fila) & "2"
End If
cadena2 = cadena2 + letra
Next
cadena2 = QuitarEspacios(cadena2)
' compara la cadena 2 con la cadena 3
largo2 = largoCadena(cadena2)
largo3 = largoCadena(cadena3)
faltante = largo2 - largo3
If faltante > 0 Then
' completa la cadena 3 al mismo largo que la cadena 1
For fila = 0 To faltante - 1
letra = "F000"
cadena3 = cadena3 + letra
Next
End If
' aumenta a la cadena 3
'rte3 = 2 + Int(Rnd() * te3)
rte3 = te3
For fila = 0 To rte3 - 1
If fila < 10 Then
letra = Chr(65 + k) & "0" + Str(fila + rte1 + te2) & "3"
Else
letra = Chr(65 + k) + Str(fila) & "3"
End If
cadena3 = cadena3 + letra
Next
cadena3 = QuitarEspacios(cadena3)
Next
largo1 = largoCadena(cadena1)
largo2 = largoCadena(cadena2)
largo3 = largoCadena(cadena3)
' igualar los largos
faltante = largo3 - largo1
If faltante > 0 Then
' completa la cadena 2 al mismo largo que la cadena 1
For fila = 0 To faltante - 1
letra = "F000"
cadena1 = cadena1 + letra
Next
End If
faltante = largo3 - largo2
If faltante > 0 Then
' completa la cadena 2 al mismo largo que la cadena 1
For fila = 0 To faltante - 1
letra = "F000"
cadena2 = cadena2 + letra
Next
End If
cadtotal = cadenafinal(cadena1, cadena2, cadena3, largo3)
' obtener un vector de cadenas or fila
For fila = 0 To largo3 - 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -898-
cadenas(fila) = Extrae(cadtotal, fila * 12, fila * 12 + 11)
Next
nf = largo3
Return cadenas
End Function
Function QuitarEspacios(ByRef cadena As String) As String
Dim col As Integer
Dim cad As String = ""
For col = 0 To Len(cadena) - 1
If cadena(col) <> " " Then cad = cad + cadena(col)
Next
Return cad
End Function
Function largoCadena(cadena As String) As Integer
Return Len(cadena) / 4
End Function
Sub Imprimircadena(cadena As String, nf As Integer)
Dim fila As Integer
Dim Cadena1 As String
For fila = 0 To nf - 1
Cadena1 = Extrae(cadena, fila * 4, fila * 4 + 3)
Console.WriteLine("{0}", Cadena1)
Next
End Sub
Function Extrae(cadena As String, pos1 As Integer, pos2 As Integer) As String
Dim subcadena As String = ""
Dim fila As Integer
Dim cont As Integer = 0
For fila = pos1 To pos2
subcadena = subcadena + cadena(fila)
Next
Return subcadena
End Function
Imports System.IO
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -899-
Imports System.Drawing
Public Class Form1
Sub imprimirVcadenas(cadenas() As String, nfilas As Integer)
Dim fila As Integer
ListBox1.Items.Clear()
For fila = 0 To nfilas - 1
ListBox1.Items.Add(fila & " " & cadenas(fila))
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
btnProcesar.Click
Dim fila As Integer
Dim cadena1 As String = ""
For fila = 0 To nf - 1
cadena1 = cadenas(fila)
DataGridView1.Rows(fila).Cells(0).Value = fila
DataGridView1.Rows(fila).Cells(1).Value = Extrae(cadena1, 0, 3)
DataGridView1.Rows(fila).Cells(2).Value = Extrae(cadena1, 4, 7)
DataGridView1.Rows(fila).Cells(3).Value = Extrae(cadena1, 8, 11)
Next
End Sub
DataGridView2.Columns(0).Width = 30
DataGridView2.Columns(1).Width = 30
DataGridView2.Columns(2).Width = 30
DataGridView2.Rows(0).Cells(0).Value = 2
DataGridView2.Rows(0).Cells(1).Value = 4
DataGridView2.Rows(0).Cells(2).Value = 3
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -900-
DataGridView2.Rows(1).Cells(0).Value = 10
DataGridView2.Rows(1).Cells(1).Value = 0
DataGridView2.Rows(1).Cells(2).Value = 0
DataGridView2.Rows(2).Cells(0).Value = 20
End Sub
Imports System.IO
Module Module2
Public velocidad As Integer = 100
Public dir As Integer = 1
Public camino As Integer = 0
Public valor As Integer = 0
Public x1 As Integer = 0
Public y1 As Integer = 0
Public pmx, pmy As Integer
Public ancho1 As Integer = 20 '90
Public alto1 As Integer = 10 '90
Public AnchoTotal = 40
Public AltoTotal = 20
Public ex1 As Single = 32, ey1 As Single = 32
Public ex2 As Single = 4, ey2 As Single = 4
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -903-
Public vel As Integer = 100
Public Posx As Integer = 11 ' col de partida
Public Posy As Integer = 13 ' fila de partida
' ***************************
Public Const maxfilas As Integer = 42, maxcol As Integer = 42 '700 ' 590
Public A(maxfilas, maxcol) As Integer
Public B(maxfilas, maxcol) As Integer
Option Explicit On
Imports System.IO
Public Class Form1
Dim Pen1 As Pen
Dim Grafico1 As Graphics
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -904-
Dim brocha1 As SolidBrush
Dim Pen2 As Pen
Dim Grafico2 As Graphics
Dim brocha2 As SolidBrush
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.Left = 0
PictureBox1.Top = 0
PictureBox1.Width = 800
PictureBox1.Height = 350
Grafico1 = PictureBox1.CreateGraphics
Pen1 = New Pen(Color.Red, 2)
brocha1 = New SolidBrush(Color.FromArgb(255, 255, 0))
Grafico2 = PictureBox2.CreateGraphics
Pen2 = New Pen(Color.Red, 1)
brocha2 = New SolidBrush(Color.FromArgb(255, 255, 0))
txtPx.Text = Posx
txtPy.Text = Posy
valor = A(Posy, Posx)
txtValor.Text = valor
txtVel.Text = velocidad
End Sub
Module Module1
Public nultimos As Integer = 0
Public ultimos As Integer = 100
Public paso As Integer = 20
Public menor As Integer
Public Const largo As Integer = 4000
Public li As Integer = 0
Public alcance As Integer = 10
Public Cont As Integer = 0
Public contMalos As Integer = 0
Public Nvecinos As Integer = 0
Public Ndir(4) As Integer ' vector de direcciones
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -909-
Public RutaX(largo) As Integer ' vector de direcciones
Public RutaY(largo) As Integer ' vector de direcciones
Public RutaXMala(largo) As Integer ' vector de direcciones
Public RutaYMala(largo) As Integer ' vector de direcciones
Public Dirfac(4) As Integer ' 0 no ses factible
Public Sdir(4) As Integer ' vector de suma de direccionesA
Public limiteColor As Integer = 50
Public PosXAuto As Integer
Public PosYAuto As Integer
Public Ex1 As Integer = 1
Public Ey1 As Integer = 1
Public Ex As Integer = 10
Public Ey As Integer = 10
Public AutoX(1) As Integer
Public AutoY(1) As Integer
Public AnchoImagen As Integer
Public AltoImagen As Integer
Public BrochaSólida As SolidBrush
Public Color1 As Color
Public tam As Integer = 20
Public camino As Integer = 0
Public dir As Integer = 1
Public velocidad As Integer = 10
Public Grafico1 As Graphics
Public grafico2 As Graphics
Public Grafico3 As Graphics
Public imagen As Bitmap
Public fuente1 As RectangleF
Public destino1 As RectangleF
Public fuente2 As RectangleF
Public destino2 As RectangleF
Public fuente3 As RectangleF
Public destino3 As RectangleF
Public rojo, verde, azul As Integer
Sub IniciarVectores()
Dim col As Integer
For col = 0 To 3
Ndir(col) = col + 1
Sdir(col) = 0
Next
For col = 0 To largo
RutaX(0) = 0
RutaY(0) = 0
Next
End Sub
Function buscar(ByVal Cx As Integer, ByVal cy As Integer, ByVal li As Integer, ByVal
ls As Integer) As Boolean
Dim fila As Integer
Dim encontrado As Boolean = False
For fila = li To ls
If Cx = RutaX(fila) And cy = RutaY(fila) Then
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -910-
encontrado = True
Exit For
End If
Next
Return encontrado
End Function
Function Contavecinos(ByVal Cx As Integer, ByVal cy As Integer, ByVal li As Integer,
ByVal ls As Integer)
Dim fila, col As Integer, nvecinos = 0
For fila = cy - paso To cy + paso
For col = Cx - paso To Cx + paso
If buscar(col, fila, li, ls) = True Then nvecinos = nvecinos + 1
Next
Next
Return nvecinos
End Function
End Module
Imports System.Drawing
Public Class Form1
Function ProbarRuta(ByVal Cx As Integer, ByVal Cy As Integer, ByVal AutoX() As
Integer, ByVal Autoy() As Integer) As Boolean
Dim f1 As Boolean = True
Dim f2 As Boolean = True
Dim f3 As Boolean = True
Dim f4 As Boolean = True
'' probar si esta en la colas
If (Cx = AutoX(1) And Cy = Autoy(1)) Then f1 = False
' probar si estan en los ultimos
For fila = li To Cont + 1
If (Cx = RutaX(fila) And Cy = RutaY(fila)) Then
f2 = False
Exit For
End If
Next
Color1 = imagen.GetPixel(Cx, Cy)
azul = Color1.B
If (azul >= limiteColor) Then f3 = False 'tiene que se todos los poner colores con
rojo
' probar si la ruta ha sido y habia retrocidido
For fila = 0 To contMalos
If (Cx = RutaXMala(fila) And Cy = RutaYMala(fila)) Then
f4 = False
Exit For
End If
Next
If f1 = True And f2 = True And f3 = True And f4 = True Then
Return True
Else
Return False
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -911-
End If
End Function
'probar si no es camino
Color1 = imagen.GetPixel(Cx, Cy)
azul = Color1.B
If (azul >= limiteColor) Then f2 = False 'tiene que se todos los colores poner
colores con rojo
' probar si al menos tiene un vecino
Nvecinos = 0
' saber nro de vecinos
For fila = Cy - 1 To Cy + 1
For col = Cx - 1 To Cx + 1
If fila = col Then Continue For
Color1 = imagen.GetPixel(col, fila)
If (Color1.B > limiteColor) Then Nvecinos = Nvecinos + 1
Next
Next
If (Nvecinos <= 0) Then f3 = False
For fila = 0 To contMalos
If (Cx = RutaXMala(fila) And Cy = RutaYMala(fila)) Then
f5 = False
Exit For
End If
Next
nultimos = 0
If Cont > ultimos Then
For fila = Cont - ultimos To Cont
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -912-
If (Cx = RutaX(fila) And Cy = RutaY(fila)) Then nultimos = nultimos + 1
Next
If nultimos > ultimos / 2 Then f6 = False
End If
If f1 = True And f2 = True And f3 = True And f4 = True And f5 = True And f6 = True
Then
Return True
Else
Return False
End If
End Function
Sub traslados()
Dim valor1 As Integer = tam / 2
' se traslada el auto
grafico2.DrawRectangle(Pens.Yellow, AutoX(0), AutoY(0), tam, tam)
' gragficara todo el rastro
txtPosX.Text = AutoX(0)
TxtPosy.Text = AutoY(0)
fuente3.Width = tam * 2
fuente3.Height = tam * 2
fuente3.X = AutoX(0) - tam
fuente3.Y = AutoY(0) - tam
destino3.Width = tam * 2 * Ex
destino3.Height = tam * 2 * Ey
destino3.X = 0
destino3.Y = 0
Grafico3.DrawImage(imagen, destino3, fuente3, GraphicsUnit.Pixel)
Grafico1.DrawRectangle(Pens.Blue, AutoX(0) - tam, AutoY(0) - tam, tam * 2, tam * 2)
Grafico1.DrawRectangle(Pens.Blue, AutoX(0) - 1, AutoY(0) - 1, 2, 2)
grafico2.DrawRectangle(Pens.Blue, AutoX(0) - tam, AutoY(0) - tam, tam * 2, tam * 2)
valor1 = Ex / 2
Grafico3.FillRectangle(Brushes.Yellow, tam * Ex - valor1, tam * Ey - valor1, Ex, Ey)
End Sub
Imports System.IO
Module Module2
Public x1, x2 As Integer
Public ancho As Integer = 90
Public ex As Single = 30, ey As Single = 30
Public cadena As String = "AREQUIPA, 17 DE MAYO DEL 2010"
Public CadenaBusca As String
Public ASCII, indice As Integer
Public vel As Integer
' ***************************
Public NroLetras As Integer = 0
Public Const maxfilas As Integer = 12, maxcol As Integer = 700 ' 590
Public Const maxfilas1 As Integer = 12, maxcol1 As Integer = 100
Public nf As Integer = 10, nc As Integer = 590
Public nf1 As Integer = 10, nc1 As Integer = 100
Public nf2 As Integer = 10, nc2 As Integer = 90 ' se va copiar esa cantidad
Public Cx1 As Integer = 0, Cy1 As Integer = 0 ' lugar de donde se va a copiar
Public Cx2 As Integer = 60, Cy2 As Integer = 1 ' lugar a pegar en la matriz A
Public Cx3 As Integer = 1, Cy3 As Integer = 1 ' lugar a mostrar la matriz B
Public separa As Integer = 10
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -919-
Public A(maxfilas, maxcol) As String
Public B(maxfilas1, maxcol1) As String
Public MA(maxfilas, maxcol) As String
Public MB(maxfilas, maxcol) As String
Public cont As Integer = 0
Imports System.Drawing
Public Class Form1
Dim Grafico1 As Graphics
Dim Grafico2 As Graphics
Dim Grafico3 As Graphics
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -922-
Dim Grafico4 As Graphics
Dim Grafico5 As Graphics
Dim Grafico6 As Graphics
Dim Grafico7 As Graphics
PictureBox4.Width = ancho + cx
PictureBox4.Height = alto + cy
PictureBox5.Width = ancho + cx
PictureBox5.Height = alto + cy
PictureBox6.Width = ancho + cx
PictureBox6.Height = alto + cy
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -924-
PictureBox7.Width = ancho + cx
PictureBox7.Height = alto + cy
Cuadro.Width = ancho * 2 + cx
Cuadro.Height = alto * 2 + cy
Pict1 = New Bitmap("e:\datos2\platano1.bmp")
Pict2 = New Bitmap("e:\datos2\platano2.bmp")
Pict3 = New Bitmap("e:\datos2\platano3.bmp")
Pict4 = New Bitmap("e:\datos2\platano4.bmp")
Pict5 = New Bitmap("e:\datos2\platano5.bmp")
Pict6 = New Bitmap("e:\datos2\platano6.bmp")
Pict7 = New Bitmap("e:\datos2\platano7.bmp")
Grafico1 = PictureBox1.CreateGraphics
Grafico2 = PictureBox2.CreateGraphics
Grafico3 = PictureBox3.CreateGraphics
Grafico4 = PictureBox4.CreateGraphics
Grafico5 = PictureBox5.CreateGraphics
Grafico6 = PictureBox6.CreateGraphics
Grafico7 = PictureBox7.CreateGraphics
GraficoCombinado = Cuadro.CreateGraphics
End Sub
http://www.paisdelosjuegos.pe/juegos/pacman
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fila, col As Integer
DataGridView1.RowCount = nf
DataGridView1.ColumnCount = nc
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 24
DataGridView1.Columns(col).HeaderText = col
Next
For fila = 0 To nf - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -929-
Matriz(pmy, pmx) = 3
MostrarMatriz(Matriz, nf, nc)
txtPorcentaje.Text = contar(Matriz, nf, nc) * 100
DataGridView1.Focus()
End Sub
Private Sub BtnRecuperar_Click(sender As Object, e As EventArgs) Handles
BtnRecuperar.Click
RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
End Sub
Private Sub BtnMostrar_Click(sender As Object, e As EventArgs) Handles
BtnMostrar.Click
MostrarMatriz(Matriz, nf, nc)
End Sub
Private Sub DataGridView1_CellEnter(sender As Object, e As
DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
col = DataGridView1.CurrentCellAddress.X
fila = DataGridView1.CurrentCellAddress.Y
'DataGridView1.CurrentCell.Style.BackColor = Color.FromArgb(255, 0, 0)
TextBox1.Text = "F " & fila & "C" & col
ValorActual = DataGridView1.CurrentCell.Value
txtAnterior.Text = ValorAnterior
txtActual.Text = ValorActual
TextBox2.Text = cont
Select Case ValorActual
Case camino ' entre a la celda de color blanco
If ValorAnterior = relleno Then ' la celda anterior era verde
cont = 0 ' comienza a llenar al vector
' encuentra la fila columna inicial
X(cont) = col
Y(cont) = fila
xini = col
yini = fila
ListBox1.Items.Clear()
ListBox1.Items.Add("Xini " & xini & " Yini " & yini)
ListBox1.Items.Add("Yfin " & xfin & " Yfin " & yfin)
DataGridView1.CurrentCell.Value = relleno ' ahora la celda es de color verde
Matriz(fila, col) = relleno
Else ' la celda anterior no era verde sigue incrementando contador
cont = cont + 1
X(cont) = col
Y(cont) = fila
DataGridView1.CurrentCell.Value = relleno ' ahora la celda es de color verde
Matriz(fila, col) = relleno
End If
Case relleno ' entre a la celda de color verde
If ValorAnterior = relleno Then ' la celda anterior era verde
' no hace nada
Else ' la celda anterior era blanco ' termina la salida
xfin = col
yfin = fila
Y(cont) = fila
X(cont) = col
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -930-
ListBox1.Items.Clear()
ListBox1.Items.Add("Xini " & xini & " Yini " & yini)
ListBox1.Items.Add("Yfin " & xfin & " Yfin " & yfin)
If cont > 2 Then
nelem = cont
cx = (xini + xfin) / 2
cy = (yini + yfin) / 2
' MostrarMatriz(Matriz, nf, nc)
Centroide(X, Y, nelem, centrox, centroy)
'DataGridView1.Rows(cy).Cells(cx).Value = 3
'DataGridView1.Rows(centroy).Cells(centrox).Value = 4
' CENTRO PROMEDIO
If Matriz(cy, cx) = camino Then
Rellenar(cx, cy)
End If
If Matriz(centroy, centrox) = camino Then
Rellenar(centrox, centroy)
End If
MostrarMatriz(Matriz, nf, nc)
txtPorcentaje.Text = contar(Matriz, nf, nc) * 100
End If
End If
End Select
ValorAnterior = ValorActual
End Sub
Private Sub btnVector_Click(sender As Object, e As EventArgs) Handles
btnVector.Click
nelem = cont
MostrarVector(X, Y, nelem)
End Sub
Private Sub btnRellenar_Click(sender As Object, e As EventArgs) Handles
btnRellenar.Click
Rellenar(cx, cy)
End Sub
Private Sub BtnIniciar_Click(sender As Object, e As EventArgs) Handles
BtnIniciar.Click
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = 0
Matriz(fila, col) = 0
Next
Next
End Sub
Sub jugar()
Dim pmx1 As Single = pmx
Dim pmy1 As Single = pmy
Dim dist, distmenor
dist = distancia(col, fila, pmx, pmy)
distmenor = dist
Matriz(pmy, pmx) = camino
pmx1 = pmx
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -931-
pmy1 = pmy
dist = distancia(col, fila, pmx + 1, pmy)
If dist < distmenor And Matriz(pmy, pmx + 1) = camino Then
distmenor = dist
pmx1 = pmx + 1
End If
dist = distancia(col, fila, pmx - 1, pmy)
If dist < distmenor And Matriz(pmy, pmx - 1) = camino Then
distmenor = dist
pmx1 = pmx - 1
End If
dist = distancia(col, fila, pmx, pmy + 1)
If dist < distmenor And Matriz(pmy + 1, pmx) = camino Then
distmenor = dist
pmy1 = pmy + 1
End If
dist = distancia(col, fila, pmx, pmy - 1)
If dist < distmenor And Matriz(pmy - 1, pmx) = camino Then
distmenor = dist
pmy1 = pmy - 1
End If
If pmx1 = pmx And pmy1 = pmy Then
While (1)
pmx = Int(Rnd() * nc)
pmy = Int(Rnd() * nf)
If (Matriz(pmy, pmx) = camino) Then Exit While
End While
Else
pmy = pmy1
pmx = pmx1
End If
vecinos = Contavecinos(Matriz, nf, nc, col, fila)
Matriz(pmy, pmx) = 3
MostrarMatriz(Matriz, nf, nc)
If distmenor < 2 Then
If vecinos < 4 Then
txtvecinos.Text = " muerto"
Timer1.Enabled = False
Else
txtvecinos.Text = " VIVO"
End If
Exit Sub
End If
txtdistancia.Text = distmenor
txtvecinos.Text = vecinos
DataGridView1.Focus()
End Sub
Private Sub btnJugar_Click(sender As Object, e As EventArgs) Handles
btnJugar.Click
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -932-
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
jugar()
End Sub
End Class
Imports System.IO
Module module2
'/*** declaraciones
Public NombreArchivo As String = "E:\DATOS\MATRIZ20X20.txt"
Public Const maxfilas As Integer = 20, maxcol As Integer = 20
Public Matriz(maxfilas, maxcol) As Integer
Public maxelem As Integer = 1000
Public X(maxelem) As Integer ' vector de coordenadas x
Public Y(maxelem) As Integer ' vector de coordenadas y
Public cont As Integer = 0
Public nf As Integer = 20
Public nc As Integer = 20
Public px As Integer = 2 ' objeto identifico
Public py As Integer = 2
Public ser As Integer = 1
Public relleno As Integer = 2
Public camino As Integer = 0
Public nelem As Integer
Public cx As Integer = 0 ' centro dela figura
Public cy As Integer = 0
Public ValorAnterior As Integer = 2 ' verde
Public ValorActual As Integer = 0
Public xini As Integer = 0
Public yini As Integer = 0
Public xfin As Integer = 0
Public yfin As Integer = 0
Public centrox As Integer
Public centroy As Integer
Public cpromx As Integer
Public cpromY As Integer
Public pmx As Integer = 10
Public pmy As Integer = 10
Public pacman As Integer = 3
Public fila As Integer ' fila del pacman
Public col As Integer
Public vecinos As Integer = 0
, , ,
En este caso las salidas toman valores bipolares de 1 o –1, por lo tanto la función de
transferencia a utilizar será hardlims. Según la dimensiones de los patrones de
entrenamiento la red debe contener dos entradas y una salida.
Para decidir si una red tipo Perceptrón puede aplicarse al problema de interés, se debe
comprobar si el problema es linealmente separable, esto puede determinarse
gráficamente de la figura 2.1.9, en donde se observa que existe un gran número de
líneas rectas que pueden separar los patrones de una categoría de los patrones de la
otra, el siguiente paso es asumir arbitrariamente los valores para los pesos y ganancias
iniciales de entrada a la red; el proceso terminará cuando se hayan obtenido los pesos
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -936-
y ganancias finales que permitan a la red clasificar correctamente todos los patrones
presentados.
REM ************module 1
Imports System.IO
Module Module1
Sub Escalar(ByVal a(,) As Single, b(,) As Single, e As Single, nc As Integer)
Dim col As Integer
For col = 0 To nc - 1
b(0, col) = e * a(0, col)
Next
End Sub
Sub CalcularLinea(W(,) As Single, B(,) As Single, n As Single)
xa = 0
ya = -B(0, 0) / W(0, 1)
yb = 0
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -938-
xb = -B(0, 0) / W(0, 0)
Console.WriteLine(" valores de x1 {0} y1 {1}", xa, ya)
Console.WriteLine(" valores de x2 {0} y2 {1}", xb, yb)
End Sub
Sub MatrizTranspuesta(ByVal a(,) As Single, ByVal b(,) As Single, ByVal nf As
Integer, ByVal nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
b(col, fila) = a(fila, col)
Next
Next
End Sub
Sub MultiplicarMatriz(ByVal a(,) As Single, ByVal b(,) As Single, ByRef c(,) As Single, _
ByVal p As Integer, ByVal q As Integer, ByVal r As Integer)
Dim i, j, k As Integer
Dim aux As Single
For i = 0 To p - 1
For k = 0 To r - 1
aux = 0
For j = 0 To q - 1
aux = aux + a(i, j) * b(j, k)
Next
c(i, k) = aux
Next
Next
End Sub
ENTRADA1 ENTRADA 2 OR
-1 -1 -1
-1 1 1
1 -1 1
1 1 1
TEMPERATURAS
CATEGORIA Valor Min Valor Medio Valor Maximo
FRIO 0 15 30
TEMPLADO 15 30 45
CALIENTE 25 42 60
MU CALIENTE 50 70 100
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -945-
CLASE CATEGORIA
Option Explicit On
Public Class Form1
Dim Nfilas, Ncol, fila, col As Integer
Function randomnum(maxval As Integer) As Single
'// genera numero aletorio devolverá un entero a maxval
Randomize()
Return Rnd() * maxval
End Function
DataGridView1.Rows(0).Cells(2).Value = "0"
DataGridView1.Rows(1).Cells(2).Value = "15"
DataGridView1.Rows(2).Cells(2).Value = "25"
DataGridView1.Rows(3).Cells(2).Value = "50"
DataGridView1.Rows(0).Cells(3).Value = "15"
DataGridView1.Rows(1).Cells(3).Value = "30"
DataGridView1.Rows(2).Cells(3).Value = "42"
DataGridView1.Rows(3).Cells(3).Value = "70"
DataGridView1.Rows(0).Cells(4).Value = "30"
DataGridView1.Rows(1).Cells(4).Value = "45"
DataGridView1.Rows(2).Cells(4).Value = "60"
DataGridView1.Rows(3).Cells(4).Value = "100"
'// Valores de la cuadricula 2
DataGridView2.ColumnCount = 3 REM //numero de columnas
DataGridView2.RowCount = Nfilas + 1 REM //numero de filas
El programa permite
Ingresar los datos escoger la opción de maximización y minimización
Permite formar las matrices de variables de holgura exceso y artificiales
Permite mostrar las iteraciones paso a paso a colores
Y grabar los datos y los resultados para poder analizar en Excel
Esta en proceso el método grafico y el análisis de senisiblidad
El programa ejecutable no necesita del visual estudio para su ejecución
El programa también realiza análisis de sensibilidad
CJ
CK
Cj-ZJ
zj
Cj-ZJ
zj
Cj-ZJ
Programa simplex2
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -950-
CJ 200 150 0 0
CK XK B X1 X2 U1 U2 Φ
0 U1 500 3 2 1 0 166,666667
0 U2 400 1 2 0 1 400
0 0 0 0 0
Cj-ZJ 200 150 0 0
200 X1 166,666667 1 0,66666667 0,33333333 0 250
0 U2 233,333333 0 1,33333333 -0,33333333 1 175
zj 33333,3333 200 133,333333 66,6666667 0
Cj-ZJ 0 16,6666667 -66,6666667 0
200 X1 50 1 0 0,5 -0,5
150 X2 175 0 1 -0,25 0,75
zj 36250 200 150 62,5 12,5
Cj-ZJ 0 0 -62,5 -12,5
VARIABLE BASICA
x1 ck Cj-Zj aij ΔCK
max 200 -12,5 -0,5 25 225
min 200 -62,5 0,5 125 75
x2 ck Cj-Zj aij ΔCK
max 150 -62,5 -0,25 250 400
min 150 12,5 0,75 16,6666667 133,333333
restriciones sin dual
u1 max 500 175 -0,25 700 1200
min 500 50 0,5 100 400
u2 max 400 50 -0,5 100 500
min 400 175 0,75 233,333333 166,666667
Las opciones del menú son las siguientes
Utilizacion
Descripcion del software
Escoja iteraciones
Escoja análisis de sensibilidad
Elija el archivo a procesar
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -951-
CODIGO FUENTE
End Function
Sub copiar(A(,) As Single, A1(,) As Single, B() As Single, B1() As Single, nfrest As
Integer, ncovar As Integer)
Dim fila, col As Integer
For fila = 0 To nfrest - 1
B1(fila) = B(fila)
For col = 0 To NcVar - 1
A1(fila, col) = A(fila, col)
Next
Next
End Sub
Sub LeerArchivo(Nombre As String, A() As String, ByRef nf As Integer)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -953-
Dim srLector As StreamReader = New StreamReader(Nombre)
Dim cont As Integer = 0
Dim Linea As String
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
A(cont) = Linea
cont = cont + 1
Linea = srLector.ReadLine()
Loop
srLector.Close()
nf = cont
End Sub
Sub FormaStandar(A() As String, nf As Integer, CRJ() As Single, XRJ() As String, _
ByRef NroVholgura As Integer, ByRef nVartificial As Integer, ByRef Ncvar
As Integer)
Dim pos, fila As Integer
Dim cont As Integer = 0
Dim CadRempla As String
Dim CantVa As Integer
For fila = 2 To nf - 1
pos = InStr(A(fila), "<=")
If pos > 0 Then
CRJ(cont) = B(cont)
XRJ(cont) = "U" + CStr(cont + 1)
cont = cont + 1
A(fila) = Replace(A(fila), "<=", "+1U" & CStr(cont) + " = ")
A(0) = A(0) + "+0U" + CStr(cont) + " "
Else
pos = InStr(A(fila), ">=")
If pos > 0 Then
CRJ(cont) = B(cont)
XRJ(cont) = "E" + CStr(cont + 1)
cont = cont + 1
CadRempla = "-1E" & CStr(cont) & "+1Q" & CStr(cont) + " = "
A(fila) = Replace(A(fila), ">=", CadRempla)
A(0) = A(0) + "-0E" + CStr(cont) + " "
CantVa = CantVa + 1
End If
End If
Next
For fila = 0 To CantVa - 1
A(0) = A(0) + "+" + CStr(M) + "Q" + CStr(fila + 1) + " "
Next
NroVholgura = cont
Ncvar = cont + NroVholgura + CantVa
nVartificial = CantVa
End Sub
Sub ImprimirVectorNumero(A() As Single, ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine("{0} {1}", A(fila), vbTab)
Next
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -954-
End Sub
Sub GrabarMatrizcadena(Nombre As String, A(,) As String, nf As Integer, nc As
Integer)
Dim Archivo As StreamWriter
Archivo = New StreamWriter(NombreArchivoGrabado)
Dim fila As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Archivo.Write("{0} {1}", A(fila, col), vbTab)
Next
Archivo.WriteLine()
Next
Archivo.Close()
End Sub
Sub ImprimirMatrizNumero(A(,) As Single, nf As Integer, nc As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
Sub ImprimirMatrizCadena(A(,) As String, nf As Integer, nc As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
Sub IniciarMatrizCadenas(A(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = "0"
Next
Next
End Sub
Sub ImprimirVectorCadena(A() As String, ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
Console.WriteLine("{0} {1}", A(fila), vbTab)
Next
End Sub
Sub ObtenerVectores(inicio As Integer, bCadena As String, CJ() As Single, XJ() As
String, ByRef ne As Integer)
largo = Len(cadena)
Dim posletra As Integer
Console.WriteLine(cadena)
Dim cont As Integer = 0
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -955-
Do
' pos = InStr(inicio + 1, cadena, "+")
pos = PosMasmenos(cadena, inicio)
cadena2 = Mid(cadena, inicio, pos - inicio)
posletra = PrimeraLetra(cadena2) + 1
Cadentero = Mid(cadena2, 1, posletra - 1)
CJ(cont) = Val(Cadentero)
cadletra = Mid(cadena2, posletra, Len(cadena2) - posletra + 1)
XJ(cont) = cadletra
cont = cont + 1
inicio = pos
Loop Until pos > (largo - 1)
ne = cont
End Sub
Function PrimeraLetra(Cadena As String) As Integer
Dim fila As Integer, lug As Integer = 0
For fila = 1 To Len(Cadena)
If Not IsNumeric(Cadena(fila)) Then
lug = fila
Exit For
End If
Next
Return lug
End Function
Function EncontrarPosletra(cadena As String, pos As Integer) As Integer
Dim lugar As Integer
For col = pos - 1 To 0 Step -1
If cadena(col) = "+" Or cadena(col) = "-" Then
lugar = col
Exit For
End If
Next
Return lugar
End Function
Function PosMasmenos(cadena As String, inicio As Integer) As Integer
Dim col, resultado As Integer
resultado = -1
For col = inicio To Len(cadena) - 1
If cadena(col) = "+" Or cadena(col) = "-" Then
resultado = col + 1
Exit For
End If
Next
Return resultado
End Function
Sub ObtencionDeValores(ListadoSimplex() As String, A(,) As Single, B() As Single,
CRJ() As Single, Ncvar As Integer, nfres As Integer)
Dim fila, col As Integer
Dim cadena As String = "+3X2 +2X2 <=500"
Dim cadena1 As String = XJ(0)
Dim Cadena3 As String
Dim lugar As Integer
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -956-
Dim valor As Single
For fila = 0 To NfRest - 1
cadena = Trim(ListadoSimplex(fila + 2)) + "+"
'*******************
pos = InStr(cadena, "=")
lugar = PosMasmenos(cadena, pos)
cadena2 = Mid(cadena, pos + 1, lugar - pos)
B(fila) = Val(cadena2)
CRJ(fila) = B(fila)
For col = 0 To Ncvar - 1
cadena1 = Trim(XJ(col))
pos = InStr(1, cadena, cadena1)
If pos > 0 Then
lugar = EncontrarPosletra(cadena, pos) + 1
Cadena3 = Mid(cadena, lugar, pos - lugar)
valor = Val(Cadena3)
Else
valor = 0
End If
A(fila, col) = valor
Next
Next
End Sub
Sub VectoresUnitarios(CK() As Single, XK() As String)
Dim fila, col, k, filanro As Integer
Dim cont1 As Integer = 0
Dim cont0 As Integer = 0
For col = 0 To NcVar - 1
cont1 = 0
cont0 = 0
For fila = 0 To NfRest - 1
If A(fila, col) = 1 Then cont1 = cont1 + 1
If A(fila, col) = 0 Then cont0 = cont0 + 1
Next
' Console.WriteLine(" col {0} cont1 {1} cont0 {2} ", col, cont1, cont0)
If (cont1 = 1 And cont0 = NfRest - 1) Then
' en que fila esta el 1
For k = 0 To NfRest - 1
If A(k, col) = 1 Then
filanro = k
Exit For
End If
Next
' Console.WriteLine("VECTOR UNITARIO en col={0} =fila {1}", col, filanro)
CK(filanro) = CJ(col)
XK(filanro) = XJ(col)
Else
' Console.WriteLine(" no es vector unitario")
End If
Next
End Sub
Function obtenerZ(CK() As Single, B() As Single, nfrest As Integer) As Single
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -957-
Dim fila As Integer
Dim valor As Single = 0
For fila = 0 To nfrest - 1
valor = valor + CK(fila) * B(fila)
Next
Return valor
End Function
Function obtenerZJB(CK() As Single, B() As Single, ZJ() As Single, nfrest As Integer,
ncvar As Integer) As Single
Dim suma As Single
Dim fila As Integer
For fila = 0 To nfrest - 1
suma = suma + CK(fila) * B(fila)
Next
Return suma
End Function
MODULE 2
Sub Iniciar1()
Dim fila As Integer
Dim inicio As Integer = 0
'LeerArchivo(NombreArchivo, ListadoSimplex, nf)
Console.WriteLine(" FORMA NORMAL")
ImprimirVectorCadena(ListadoSimplex, nf)
tipo = ObtenerTipo(ListadoSimplex(0))
FormaStandar(ListadoSimplex, nf, CRJ, XRJ, NvHolgura, nVartificial, NcVar)
NfRest = nf - 2 '
Console.WriteLine(" FORMA estandar")
ImprimirVectorCadena(ListadoSimplex, nf)
cadena = "+" + ListadoSimplex(0) + "+"
' inicio =PO InStr(4, cadena, "+")
inicio = PosMasmenos(cadena, 4)
End Sub
Sub Armado(ByRef filaNro As Integer)
Dim col As Integer
For fila = 0 To NfRest - 1
TablaSimplex(filaNro + fila, 0) = CK(fila)
TablaSimplex(filaNro + fila, 1) = XK(fila)
TablaSimplex(filaNro + fila, 2) = B(fila)
For col = 0 To NcVar - 1
TablaSimplex(filaNro + fila, 3 + col) = A(fila, col)
Next
Next
filaNro = filaNro + NfRest ' ver despues?
TablaSimplex(filaNro, 0) = "ZJ"
TablaSimplex(filaNro, 2) = obtenerZ(CK, B, NfRest)
Console.WriteLine(" tabla simplex")
TablaSimplex(filaNro, 2) = obtenerZJB(CK, B, ZJ, NfRest, NcVar)
obtenerZJA(CK, A, ZJ, NfRest, NcVar)
For col = 0 To NcVar - 1
TablaSimplex(filaNro, col + 3) = ZJ(col)
Next
obtenerCJ_ZJ(CJ, ZJ, CJ_ZJ, NcVar)
filaNro = filaNro + 1 ' era ilanro+1
TablaSimplex(filaNro, 0) = "CJ-ZJ"
For col = 0 To NcVar - 1
TablaSimplex(filaNro, col + 3) = CJ_ZJ(col)
Next
filaNro = filaNro + 1
End Sub
Sub pivotear(colPivote As Integer, A(,) As Single, B() As Single, A2(,) As Single, B2()
As Single, _
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -960-
nfrest As Integer, ncvar As Integer)
For fila = 0 To nfrest - 1
Theta(fila) = B(fila) / A(fila, colPivote)
Next
filaPivote = SolucionFila(Theta, nfrest)
Console.WriteLine("fila escogida {0} ", filaPivote)
pivote = A(filaPivote, colPivote)
Console.WriteLine("pivote {0} ", pivote)
' comenzamos a pivotear incluyendo B
For fila = 0 To nfrest - 1
If fila = filaPivote Then
For col = 0 To ncvar - 1
A2(fila, col) = A(fila, col) / pivote
B2(fila) = B(fila) / pivote
Next
Else
semipivote = A(fila, colPivote)
B2(fila) = B(fila) - B(filaPivote) * semipivote / pivote
For col = 0 To ncvar - 1
A2(fila, col) = A(fila, col) - A(filaPivote, col) * semipivote / pivote
Next
End If
Next
End Sub
Function MayorAIJ(XK() As String, A(,) As Single, filaNro As Integer, ncNVar As
Integer) As Integer
Dim col, pos As Integer
Dim mayor As Single = -1000
For col = 0 To ncNVar - 1
If XK(col) <> XK(filaNro) Then
If A(filaNro, col) > mayor Then
mayor = A(filaNro, col)
pos = col
End If
End If
Next
Return pos
End Function
Function MenorAIJ(XK() As String, A(,) As Single, filaNro As Integer, ncNVar As
Integer) As Integer
Dim col, pos As Integer
Dim menor As Single = 1000
For col = 0 To ncNVar - 1
If XJ(col) <> XK(filaNro) Then
If A(filaNro, col) < menor Then
menor = A(filaNro, col)
pos = col
End If
End If
Next
Return pos
End Function
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -961-
Function MenorAIJCol(RXJ() As String, A(,) As Single, colnro As Integer, nfRest As
Integer) As Integer
Dim fila, pos As Integer
Dim menor As Single = 1000
For fila = 0 To nfRest - 1
If A(fila, colnro) < menor Then
menor = A(fila, colnro)
pos = fila
End If
Next
Return pos
End Function
Function MayorAIJCol(RXJ() As String, A(,) As Single, colnro As Integer, nfRest As
Integer) As Integer
Dim fila, pos As Integer
Dim mayor As Single = -1000
For fila = 0 To nfRest - 1
If A(fila, colnro) > mayor Then
mayor = A(fila, colnro)
pos = fila
End If
Next
Return pos
End Function
Sub AnalisisSensibilidadVariables(CK() As Single, Creducido() As Single, cklmin() As
Single, _
cklmax() As Single, nfres As Integer, tipo As Integer)
Dim fila, Posmenor, PosVar, PosMayor As Integer
Dim AijMenor, Deltazj, AijMayor, Costoreducido As Single
Select Case tipo
Case 1
For fila = 0 To nfres - 1
PosVar = EncontrarLugarEnVector(XJ, XK(fila), NcVar - nVartificial)
Posmenor = MenorAIJ(XK, A, fila, NcVar - nVartificial)
AijMenor = A(fila, Posmenor)
Deltazj = Math.Abs(CJ_ZJ(Posmenor) / AijMenor)
cklmax(fila) = CK(fila) + Deltazj
' *************
PosMayor = MayorAIJ(XK, A, fila, NcVar - nVartificial)
AijMayor = A(fila, PosMayor)
Deltazj = Math.Abs(CJ_ZJ(PosMayor) / AijMayor)
cklmin(fila) = CK(fila) - Deltazj
Costoreducido = CJ_ZJ(PosVar)
Next
Case 2
For fila = 0 To nfres - 1
End Select
End Sub
Sub AnalisisSensibilidadRecursos(CRJ() As Single, Psombra() As Single, CrjMin() As
Single, CrjMax() As Single, _
nfres As Integer, tipo As Integer)
Dim PosCol1, PosCol2 As Integer
Dim nrecurso As String = XJ(0)
Dim Posmenor As Integer
Dim AijMenor As Single
Dim Deltazj As Single
Dim Posmayor As Integer
Dim AijMayor As Single
Select Case tipo
Case 1
For col = 0 To NvHolgura - 1
nrecurso = XRJ(col)
PosCol1 = EncontrarLugarEnVector(XJ, nrecurso, NcVar - nVartificial) ' pos
PosCol2 = EncontrarLugarEnVector(XRJ, nrecurso, NcVar - nVartificial) '
pos
Psombra(PosCol2) = -CJ_ZJ(PosCol1)
If PosCol1 >= 0 Then ' solo se no encuentra
Posmenor = MenorAIJCol(XRJ, A, PosCol1, NfRest)
AijMenor = A(Posmenor, PosCol1)
Deltazj = Math.Abs(B(Posmenor) / AijMenor)
CrjMax(col) = CRJ(col) + Deltazj
End If
Next
For col = 0 To NvHolgura - 1
nrecurso = XRJ(col)
PosCol1 = EncontrarLugarEnVector(XJ, nrecurso, NcVar - nVartificial) ' pos
If PosCol1 >= 0 Then ' solo se no encuentra
Posmayor = MayorAIJCol(XRJ, A, PosCol1, NfRest)
AijMayor = A(Posmayor, PosCol1)
Deltazj = Math.Abs(B(Posmayor) / AijMayor)
CrjMin(col) = CRJ(col) - Deltazj
End If
Next
Case 2
For col = 0 To NvHolgura - 1
nrecurso = XRJ(col)
PosCol1 = EncontrarLugarEnVector(XJ, nrecurso, NcVar - nVartificial) ' pos
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -963-
PosCol2 = EncontrarLugarEnVector(XRJ, nrecurso, NcVar - nVartificial) '
pos
Psombra(PosCol2) = -CJ_ZJ(PosCol1)
If PosCol1 >= 0 Then ' solo se encuentra
Posmayor = MayorAIJCol(XRJ, A, PosCol1, NfRest)
AijMayor = A(Posmayor, PosCol1)
Deltazj = Math.Abs(B(Posmayor) / AijMayor)
CrjMax(col) = CRJ(col) + Deltazj
End If
Next
For col = 0 To NvHolgura - 1
nrecurso = XRJ(col)
PosCol1 = EncontrarLugarEnVector(XJ, nrecurso, NcVar - nVartificial) ' pos
If PosCol1 >= 0 Then ' solo se no encuentra
Posmenor = MenorAIJCol(XRJ, A, PosCol1, NfRest)
AijMenor = A(Posmenor, PosCol1)
Deltazj = Math.Abs(B(Posmenor) / AijMenor)
CrjMin(col) = CRJ(col) - Deltazj
End If
Next
End Select
End Sub
End Module
End Module
End Sub
Private Sub MnuaAbrir_Click(sender As Object, e As EventArgs) Handles
MnuAbrir.Click
AbrirArchivo()
End Sub
Private Sub MnuFormaStandar_Click_1(sender As Object, e As EventArgs)
End Sub
End Sub
Sub MostrarMatrizCadena(A(,) As String, nf As Integer, nc As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
End Sub
Private Sub btnIteraciones_Click(sender As Object, e As EventArgs)
End Sub
Sub MostrarASensibilidad(NroFila As Integer, XK() As String, B() As Single, CK() As
Single, Creducido() As Single, _
cklmin() As Single, cklmax() As Single, nfres As Integer)
Dim fila As Integer
For fila = 0 To nfres - 1
DataGridView2.Rows(NroFila + fila).Cells(0).Value = XK(fila)
DataGridView2.Rows(NroFila + fila).Cells(1).Value = B(fila)
DataGridView2.Rows(NroFila + fila).Cells(2).Value = Creducido(fila)
DataGridView2.Rows(NroFila + fila).Cells(3).Value = CK(fila)
DataGridView2.Rows(NroFila + fila).Cells(4).Value = cklmin(fila)
DataGridView2.Rows(NroFila + fila).Cells(5).Value = cklmax(fila)
Next
End Sub
TodoProceso()
End Sub
End Sub
End Class
Problema de confecciones
Variable x1 x2
Productos Pan queso
Cantidad 1 1 Costo
Costo 4 12 16
Restricciones Usado Requerido ld Exceso
Calorías 2500 5000 7500 7000 >= -500
Proteínas 50 200 250 250 >= 0
Forma original
Min (z) = 4x1+12x2
s.a 2500x1+5000x2 >=7000 ( calorias)
50x1+200x2≥ 250 (proteinas)
X1,X2 ≥0
El Modelo es
La siguiente aplicación permite resolver los problemas por el método grafico con n
restricciones y muestra la solución se puede cambiar las escalas
Problema de minimización
Module Module2
Public mayor As Single
Public rUnidadX As Single
Public UnidadX As Single
Public UnidadY As Single
Public ValorMaximoX As Single
Public ValorMaximoY As Single
Public tipofo As Integer ' es maximizacion o miminimizacion
Public dx As Single ' nro de decimales
Public Zmaximo As Single
Public maxx1 As Single, maxx2 As Single
Public Const paso As Integer = 30
Public Const maxfilas As Integer = 5
Public M1(maxfilas, 2) As Single ' matriz de los coefecientes
Public CJ(2) As Single ' coefecientes de la funcion objetiva
Public B(maxfilas) As Single ' coefecientes de los recursos
Public col As Integer
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -971-
Public fila As Integer
Public filaIni As Integer = 1
Public numerador As Single
Public denominador As Single
Public dato As Single
Public Grafico As Graphics
Public ColorFondo As Color = Color.FromArgb(255, 255, 255)
Public pen As Pen
Public brocha As Brush
Public ancho = 600, alto = 400
Public Cx As Integer = paso
Public Cy As Integer = alto
Public ex As Single = 2
Public ey As Single = -2
Public r1 As Single, r2 As Single
Public x1 As Single, x2 As Single, x1a As Single, x2a As Single, z As Single
Public r(maxfilas) As Single, menor As Single
Public resultado As String
Public k As Integer
End Module
Module Module1
Public nrestric As Integer
Public nva As Integer ' nro de variables artificiales
Public nvar As Integer
Function probarlineaMax(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As
Single, ByVal y2 As Single _
, ByVal valor As Single, ByVal C() As Single, ByVal B() As Single, ByRef x
As Single, ByRef y As Single)
Dim xx As Single, yy As Single
Dim factible As Integer = 0
Dim menor As Single = Zmaximo
Dim fila1 As Integer
xx = x1
yy = (valor - C(0) * xx) / C(1)
While yy >= 0
menor = Zmaximo
For fila1 = 0 To nrestric - 1
r(fila1) = B(fila1) - (xx * M1(fila1, 0) + yy * M1(fila1, 1))
If r(fila1) < menor Then
menor = r(fila1)
End If
Next
If menor >= 0 Then
factible = 1
x = xx
y = yy
Exit While
Else
xx = xx + dx
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -972-
yy = (valor - C(0) * xx) / C(1)
End If
End While
probarlineaMax = factible
End Function
Option Explicit On
Imports System.Drawing
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
tipofo = 1 ' maximizacion
nrestric = 3
nvar = 2
Grafico = PictureBox1.CreateGraphics
PictureBox1.Width = ancho + paso
PictureBox1.Height = alto + paso
PictureBox1.BackColor = ColorFondo
pen = New Pen(Color.Blue, 2)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -973-
dx = 0.1
End Sub
Module Module1
Public Structure Puntos
Public nro As Integer
Public X As Single
Public Y As Single
Public Z As Single
Public Rela As Integer
End Structure
Imports System.IO
Public Class Form1
Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles
btnIniciar.Click
DataGridView1.RowCount = 8
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "X (min)"
DataGridView1.Columns(2).HeaderText = "Y (Max)"
DataGridView1.Columns(3).HeaderText = "Z"
DataGridView1.Columns(0).Width = 100
DataGridView1.Columns(1).Width = 40
DataGridView1.Columns(2).Width = 40
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -982-
DataGridView1.Columns(3).Width = 40
Cx = DataGridView1.Rows(3).Cells(1).Value
Cy = DataGridView1.Rows(3).Cells(2).Value
Cz = DataGridView1.Rows(3).Cells(3).Value
Ex = DataGridView1.Rows(4).Cells(1).Value
Ey = DataGridView1.Rows(4).Cells(2).Value
Ez = DataGridView1.Rows(4).Cells(3).Value
Gradosx = DataGridView1.Rows(5).Cells(1).Value
Gradosy = DataGridView1.Rows(5).Cells(2).Value
Gradosz = DataGridView1.Rows(5).Cells(3).Value
GPencil = DataGridView1.Rows(6).Cells(1).Value
Indice = DataGridView1.Rows(6).Cells(2).Value
modo = DataGridView1.Rows(6).Cells(3).Value
dx = (lsx - lix) / nc
dy = (lsy - liy) / nf
DataGridView1.Rows(7).Cells(1).Value = dx
DataGridView1.Rows(7).Cells(2).Value = dy
dx = DataGridView1.Rows(7).Cells(1).Value
dy = DataGridView1.Rows(7).Cells(2).Value
vel = DataGridView1.Rows(7).Cells(3).Value
DataGridView2.RowCount = nf + 1
DataGridView2.ColumnCount = 2
DataGridView2.Columns(0).Width = 40
DataGridView2.Columns(1).Width = 50
DataGridView2.Columns(0).HeaderText = "X"
DataGridView2.Columns(1).HeaderText = "Y"
For fila = 0 To DataGridView2.RowCount - 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -984-
DataGridView2.Rows(fila).HeaderCell.Value = fila.ToString
Next
GenerarGrabar(sender, e)
escalar(Ex, Ey, Ez)
rotar(Gradosx, Gradosy, Gradosz)
grafico3d()
End Sub
Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles
btnGraficar.Click
Dim x1, y1, x2, y2 As Single
Pen.Width = GPencil
With DataGridView2
For col = 0 To nc - 2
x1 = CSng(.Rows(col).Cells(0).Value)
y1 = CSng(.Rows(col).Cells(1).Value)
x2 = CSng(.Rows(col + 1).Cells(0).Value)
y2 = CSng(.Rows(col + 1).Cells(1).Value)
Grafico.DrawLine(Pen, Cx + x1 * Ex, Cy + y1 * Ey, Cx + x2 * Ex, Cy + y2 * Ey)
Next
End With
End Sub
Private Sub BtnBorrar_Click(sender As Object, e As EventArgs) Handles
BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
' rotacion z
Az = gradosz * Math.PI / 180
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = MP1(fila, col).X
y1 = MP1(fila, col).Y
z1 = MP1(fila, col).Z
x2 = x1 * Math.Cos(Az) - y1 * Math.Sin(Az)
y2 = x1 * Math.Sin(Az) + y1 * Math.Cos(Az)
z2 = z1
MP1(fila, col).X = x2
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -988-
MP1(fila, col).Y = y2
MP1(fila, col).Z = z2
Next
Next
End Sub
Private Sub btnVerDatos_Click(sender As Object, e As EventArgs) Handles
btnVerosDatos.Click
Form2.DataGridView1.ColumnCount = nc + 1
Form2.DataGridView1.RowCount = nf + 1
For col = 0 To nc
Form2.DataGridView1.Columns(col).Width = 70
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
Form2.DataGridView1.Rows(fila).Cells(col).Value = MP1(fila, col).Z
Next
Next
Form2.Show()
End Sub
Private Sub TextBox1_KeyDown_1(sender As Object, e As KeyEventArgs) Handles
TextBox1.KeyDown
Select Case e.KeyCode
Case Keys.Left
Gradosx = Gradosx - 1
Case Keys.Right
Gradosx = Gradosx + 1
Case Keys.Up
Gradosy = Gradosy - 1
Case Keys.Down
Gradosy = Gradosy + 1
Case 90 'Z
Gradosz = Gradosz + 1
Case 87 'W
Gradosz = Gradosz - 1
End Select
DataGridView1.Rows(5).Cells(1).Value = Gradosx
DataGridView1.Rows(5).Cells(2).Value = Gradosy
DataGridView1.Rows(5).Cells(3).Value = Gradosz
BtnBorrar_Click(sender, e)
BtnIniciarTodo_Click(sender, e)
TextBox1.Text = ""
End Sub
End Class
Imports System.IO
Module Module1
Public Structure Puntos
Public nro As Integer
Public X As Single
Public Y As Single
Public Z As Single
Public Rela As Integer
End Structure
Public Nvecinos1 As Integer = 3
Public altura As Single = 10
Public niter As Integer = 100
Public Vinicial As Single = 0
Public vargx As Single = 0
Public vargy As Single = 0
Public vargz As Single = 0
Public aumento As Single = 10
Public modo As Integer = 0
Public Gradosx As Single = 0
Public Gradosy As Single = 0
Public Gradosz As Single = 0
Public MP(maxfilas, maxcol) As Puntos
Public MP1(maxfilas, maxcol) As Puntos
Public brocha As SolidBrush
Public Const maxcol As Integer = 1000
Public Const maxfilas As Integer = 1000
Public Const maximo As Integer = 8000
Public cont As Integer = 0
Public Cx As Single = 200
Public Cy As Single = 200
Public Cz As Single = 0
Public D As Single = 200
Public dx As Single
Public dy As Single
Public Ex As Single = 20
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -990-
Public Ey As Single = -20
Public Ez As Single = 20
Public GPencil As Integer = 1
Public Grafico As Graphics
Public Indice As Integer = 1
Public lix As Single = -5
Public liy As Single = -5
Public lsx As Single = 5
Public lsy As Single = 5
Public nc As Integer = 20
Public nf As Integer = 20
Public np As Integer = 1000
Public Pen As Pen
Public vel As Integer = 1
Public Sub Copiar(MP(,) As Puntos, ByRef MP1(,) As Puntos, nf As Integer, nc As
Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For COL = 0 To nc - 1
MP1(fila, COL).X = MP(fila, COL).X
MP1(fila, COL).Y = MP(fila, COL).Y
MP1(fila, COL).Z = MP(fila, COL).Z
Next
Next
End Sub
Public Sub escalar(Ex As Single, ey As Single, ez As Single)
For fila = 0 To nf - 1
For COL = 0 To nc - 1
MP1(fila, COL).X = MP1(fila, COL).X * Ex
MP1(fila, COL).Y = MP1(fila, COL).Y * ey
MP1(fila, COL).Z = MP1(fila, COL).Z * ez
Next
Next
End Sub
' rotacion z
Az = gradosz * Math.PI / 180
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = MP1(fila, col).X
y1 = MP1(fila, col).Y
z1 = MP1(fila, col).Z
x2 = x1 * Math.Cos(Az) - y1 * Math.Sin(Az)
y2 = x1 * Math.Sin(Az) + y1 * Math.Cos(Az)
z2 = z1
MP1(fila, col).X = x2
MP1(fila, col).Y = y2
MP1(fila, col).Z = z2
Next
Next
End Sub
Sub Iniciar()
Dim x, y, z1 As Single
Dim fila, col As Integer
Pen.Width = GPencil
dx = (lsx - lix) / nc
dy = (lsy - liy) / nf
cont = 0
'generamos los puntos
y = liy
For fila = 0 To nf - 1
x = lix
For col = 0 To nc - 1
REM z1 = f3d(x, y)
MP(fila, col).nro = cont
MP(fila, col).X = x
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -992-
MP(fila, col).Y = y
MP(fila, col).Z = Vinicial
x = x + dx
cont = cont + 1
Next
y = y + dy
Next
np = cont
Copiar(MP, MP1, nf, nc)
End Sub
Sub grabar()
Dim archivo As StreamWriter
archivo = New StreamWriter("E:\datos\Mp20x20.txt")
' grabamos los puntos de la matriz y mostramos
For fila = 0 To nf - 1
For col = 0 To nc - 1
archivo.Write("{0}{1}", MP1(fila, col).Z, Chr(9))
Next
archivo.WriteLine()
Next
archivo.Close()
End Sub
End Module
DataGridView1.Rows(9).Cells(0).Value = "Nvecinos"
DataGridView1.Rows(9).Cells(1).Value = Nvecinos1
Cx = DataGridView1.Rows(3).Cells(1).Value
Cy = DataGridView1.Rows(3).Cells(2).Value
Cz = DataGridView1.Rows(3).Cells(3).Value
Ex = DataGridView1.Rows(4).Cells(1).Value
Ey = DataGridView1.Rows(4).Cells(2).Value
Ez = DataGridView1.Rows(4).Cells(3).Value
Gradosx = DataGridView1.Rows(5).Cells(1).Value
Gradosy = DataGridView1.Rows(5).Cells(2).Value
Gradosz = DataGridView1.Rows(5).Cells(3).Value
GPencil = DataGridView1.Rows(6).Cells(1).Value
Indice = DataGridView1.Rows(6).Cells(2).Value
modo = DataGridView1.Rows(6).Cells(3).Value
niter = DataGridView1.Rows(8).Cells(1).Value
Vinicial = DataGridView1.Rows(8).Cells(2).Value
aumento = DataGridView1.Rows(8).Cells(3).Value
Nvecinos1 = DataGridView1.Rows(9).Cells(1).Value
dx = (lsx - lix) / nc
dy = (lsy - liy) / nf
DataGridView1.Rows(7).Cells(1).Value = dx
DataGridView1.Rows(7).Cells(2).Value = dy
dx = DataGridView1.Rows(7).Cells(1).Value
dy = DataGridView1.Rows(7).Cells(2).Value
vel = DataGridView1.Rows(7).Cells(3).Value
Iniciar()
escalar(Ex, Ey, Ez)
rotar(Gradosx, Gradosy, Gradosz)
grafico3d()
verdatos()
End Sub
Private Sub BtnBorrar_Click(sender As Object, e As EventArgs) Handles
BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub Coordenadas(sender As Object, e As EventArgs) Handles
btnCoordenadas.Click
Pen.Color = Color.Blue
Grafico.DrawLine(Pen, 0, Cy, PictureBox1.Width, Cy)
Grafico.DrawLine(Pen, Cx, 0, Cx, PictureBox1.Height)
Pen.Color = Color.Red
End Sub
Sub grafico3d()
Dim Color1 As Integer
Dim AX As Single, Ay As Single, Az As Single, Bx As Single, By As Single, Bz As
Single
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -995-
Dim NX As Single, Ny As Single, Nz As Single, Nx1 As Single, Ny1 As Single, Nz1
As Single
Dim R As Single
Dim Pe As Single
Dim x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4 As Single
Dim px1, py1, px2, py2, px3, py3, px4, py4 As Single
Dim fila, col As Integer
Dim Puntos(3) As Point
For fila = 0 To nf - 3
For col = 0 To nc - 3
x1 = MP1(fila, col).X
y1 = MP1(fila, col).Y
z1 = MP1(fila, col).Z
x2 = MP1(fila, col + 1).X
y2 = MP1(fila, col + 1).Y
z2 = MP1(fila, col + 1).Z
x4 = MP1(fila + 1, col).X
y4 = MP1(fila + 1, col).Y
z4 = MP1(fila + 1, col).Z
'*******************
px1 = Cx + (x1 * D) / (D + z1)
py1 = Cy + (y1 * D) / (D + z1)
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1001-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "COM12" ' Cambia el Puerto
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub
Private Sub PrenderLed(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnPrender.Click
SerialPort1.Open()
SerialPort1.Write("1")
SerialPort1.Close()
PicFoco.Image = PictureBox1.Image
End Sub
void loop(){
while (Serial.available() == 0);
int val = Serial.read() - '0';
if (val == 1) {
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
}
else if (val == 0)
{
Serial.println("LED OFF");
digitalWrite(ledPin, LOW);
}
else
{
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1002-
//val = val;
}
Serial.println(val);
Serial.flush();
}
Indicaciones
1. Abra la imagen menor a 500x500 por ejmplo unsa.bmp
2. Dibujar . dibuja la imagen
3. Automatico . rota la imagen
Puede ver todos los efectos que se puede realizar con la imagen
Se puede aumentar y desminuir color
Module Module1
Public Az As Single = 0 ' rotacion al rededor del eje z
Public dex As Single = 0.1
Public dey As Single = 0.1
Public Cx As Integer = 200
Public Cy As Integer = 200
Public drojo As Integer = 10
Public dverde As Integer = 10
Public dazul As Integer
Public tipo As Integer = 0 ' es tipo normal 1.
Public MBN(maxfilas, maxcol) As Byte
Public grafico2 As Graphics
Const maxcol As Integer = 550
Const maxfilas As Integer = 400
Public nf As Integer = 100
Public nc As Integer = 100
Public Rojos(maxfilas, maxcol) As Integer
Public Verdes(maxfilas, maxcol) As Integer
Public Azules(maxfilas, maxcol) As Integer
Public grafico As Graphics
Public imagen As Bitmap
Public nfilas As Integer = 7
Public ex As Single = 1
Public ey As Single = 1
Public velocidad As Integer = 10
Public projo As Single = 1
Public pverde As Single = 1
Public pazul As Single = 1
Public vrojo As Single
Public vverde As Single
Public vazul As Single
End Module
DataGridView1.Rows(1).Cells(0).Value = "Escala"
DataGridView1.Rows(1).Cells(1).Value = ex
DataGridView1.Rows(1).Cells(2).Value = ey
DataGridView1.Rows(2).Cells(0).Value = "%Color"
DataGridView1.Rows(2).Cells(1).Value = projo
DataGridView1.Rows(2).Cells(2).Value = pverde
DataGridView1.Rows(2).Cells(3).Value = pazul
DataGridView1.Rows(3).Cells(0).Value = "Var Color"
DataGridView1.Rows(3).Cells(1).Value = vrojo
DataGridView1.Rows(3).Cells(2).Value = vverde
DataGridView1.Rows(3).Cells(3).Value = vazul
DataGridView1.Rows(4).Cells(0).Value = "Incremento"
DataGridView1.Rows(4).Cells(1).Value = drojo
DataGridView1.Rows(4).Cells(2).Value = dverde
DataGridView1.Rows(4).Cells(3).Value = dazul
projo = DataGridView1.Rows(2).Cells(1).Value
pverde = DataGridView1.Rows(2).Cells(2).Value
pazul = DataGridView1.Rows(2).Cells(3).Value
vrojo = DataGridView1.Rows(3).Cells(1).Value
vverde = DataGridView1.Rows(3).Cells(2).Value
vazul = DataGridView1.Rows(3).Cells(3).Value
drojo = DataGridView1.Rows(4).Cells(1).Value
dverde = DataGridView1.Rows(4).Cells(2).Value
dazul = DataGridView1.Rows(4).Cells(3).Value
Cx = DataGridView1.Rows(5).Cells(1).Value
Cy = DataGridView1.Rows(5).Cells(2).Value
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1007-
Az = DataGridView1.Rows(6).Cells(1).Value
End Sub
Sub DibujarNormal()
Dim fila, col As Integer
Dim rojo, verde, azul As Integer
Dim brocha As SolidBrush
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1009-
brocha = New SolidBrush(Color.Aqua)
For fila = 1 To nf - 2
For col = 1 To nc - 2
rojo = Rojos(fila, col) * projo
If (rojo + vrojo >= 0 And rojo + vrojo <= 255) Then
rojo = Rojos(fila, col) * projo + vrojo
Else
If (rojo + vrojo < 0) Then rojo = 0
If (rojo + vrojo > 255) Then rojo = 255
End If
verde = Verdes(fila, col) * pverde
If (verde + vverde >= 0 And verde + vverde <= 255) Then
verde = Verdes(fila, col) * pverde + vverde
Else
If (verde + vverde < 0) Then verde = 0
If (verde + vverde > 255) Then verde = 255
End If
azul = Azules(fila, col) * pverde
If (azul + vazul >= 0 And azul + vazul <= 255) Then
azul = Azules(fila, col) * pazul + vazul
Else
If (azul + vazul < 0) Then azul = 0
If (azul + vazul > 255) Then azul = 255
End If
brocha.Color = Color.FromArgb(rojo, verde, azul)
grafico2.FillRectangle(brocha, Cx + col * ex, Cy + fila * ey, Math.Abs(ex),
Math.Abs(ey))
Next
Next
End Sub
Case 68 'Dex
If ex > -10 Then
ex = ex - dex
Else
ex = -10
End If
If ey > -10 Then
ey = ey - dey
Else
ey = -10
End If
End Select
DataGridView1.Rows(1).Cells(1).Value = ex
DataGridView1.Rows(1).Cells(2).Value = ey
MnuObtenerValores_Click(sender, e)
txtVarColor.Text = ""
DibujarNormal()
End Sub
Private Sub BtnAutomatico_Click(sender As Object, e As EventArgs) Handles
BtnAutomatico.Click
Timer1.Interval = velocidad
Timer1.Enabled = True
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1014-
Private Sub BtnDetener_Click(sender As Object, e As EventArgs) Handles
BtnDetener.Click
Timer1.Enabled = False
End Sub
PictureBox3.Width = Ancho1
PictureBox3.Height = Alto1
grafico1 = PictureBox1.CreateGraphics
grafico2 = PictureBox2.CreateGraphics
grafico3 = PictureBox3.CreateGraphics
Bitmap1 = New Bitmap("E:\FOTOSBMP\gato333x305.bmp")
Bitmap2 = New Bitmap("E:\FOTOSBMP\perrita333X304.bmp")
Bitmap3 = New Bitmap("E:\FOTOSBMP\gato333x305.bmp")
Ancho1 = Bitmap1.Width
Alto1 = Bitmap1.Height
End Sub
Private Sub BtnValores_Click(sender As Object, e As EventArgs) Handles
BtnValores.Click
p1 = DataGridView1.Rows(0).Cells(1).Value
p2 = 1 - p1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1018-
DataGridView1.Rows(0).Cells(2).Value = p2
Ancho1 = DataGridView1.Rows(1).Cells(1).Value
Alto1 = DataGridView1.Rows(1).Cells(2).Value
velocidad = DataGridView1.Rows(4).Cells(1).Value
paso = DataGridView1.Rows(4).Cells(2).Value
End Sub
Anchod2 = DataGridView1.Rows(3).Cells(1).Value
Altod2 = DataGridView1.Rows(3).Cells(2).Value
Cx3 = DataGridView1.Rows(4).Cells(1).Value
Cy3 = DataGridView1.Rows(4).Cells(2).Value
Anchod3 = DataGridView1.Rows(5).Cells(1).Value
Altod3 = DataGridView1.Rows(5).Cells(2).Value
End Sub
Option Explicit On
Option Strict On
Imports System.IO
Module module1
Public nombre As String
Public backColor As Color
Public Grafico1 As Graphics
Public MyBitmap1 As Bitmap
Public Ancho1 As Integer
Public Alto1 As Integer
Public Grafico2 As Graphics
Public MyBitmap2 As Bitmap
Public Ancho2 As Integer
Public Alto2 As Integer
Public Cx As Integer = 0
Public Cy As Integer = 120
Public Cx2 As Integer = 400
Public Cy2 As Integer = 200
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1028-
Public Velocidad As Integer = 20
End Module
Imports System.IO
Module Module2
Public cont1 As Integer = 0
Public valor1, valor2 As Integer
Public lector As StreamReader
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1030-
Public contador As Integer = 0
Public NombreArchivo = "E:\DATOS\PUNTOS80.TXT"
Public Maxfilas As Integer = 1000
Public X(Maxfilas) As Integer
Public Y(Maxfilas) As Integer
Public nelem As Integer = 120
Public ex As Integer = 1
Public ey As Integer = 1
Public cx As Integer = 12
Public cy As Integer = 12
Public XX(Maxfilas) As Integer
Public YY(Maxfilas) As Integer
Module Module1
Sub Main()
RecuperarPuntos(NombreArchivo, X, Y, nelem)
Console.WriteLine(" puntos recuperados")
mostrarPuntos(X, Y, nelem)
Console.Clear()
VerPuntos(cx, cy, X, Y, nelem)
contador = 0
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1032-
Console.ForegroundColor = 12
cont1 = 0
RellenarBorde(cont1, X, Y, nelem, 2, 2)
Console.SetCursorPosition(60, 24)
Console.Write("cont {0} ", contador)
Console.ReadLine()
End Sub
End Module
Este programa permite trabajar con bitmaps, rellena una figura , obtiene el borde ,
hace transformaciones de un objeto a otro ( modificar el programa para 3d
Imports System.IO
Module Module2
Public relleno As Integer = 0
Public cont1 As Integer = 0
Public Const maximo As Integer = 800
Public XX(4000) As Integer
Public YY(4000) As Integer
Public txmin As Integer = 0
Public txmax As Integer = 0
Public resn As Integer = 0
Public alfa1 As Single = 1
Public alfa2 As Single = 0
Public alto As Integer = 120
Public ancho As Integer = 120
Public Azules(maxfilas, maxcol) As Integer
Public borde1 As Integer = 1
Public brocha As SolidBrush
Public lector As StreamReader
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1033-
Public escritor As StreamWriter
Public camino As Integer = 0
Public Color As Color
Public Const maxfilas As Integer = 400, maxcol As Integer = 400
Public contador As Integer = 0
Public CX As Integer = 0 ' posicion de la figura
Public CY As Integer = 0 ' posicion de la figura
Public ex As Integer = 4
Public ey As Integer = 4
Public graficodestino As Graphics
Public graficofuente As Graphics
Public nc As Integer = 100
Public ne1 As Integer ' nro de elementos del vector1
Public ne2 As Integer ' nro de elementos del vector 2
Public ne3 As Integer ' dimension del vector conbinado
Public nelem As Integer = 400
Public nf As Integer = 100
Public NombreArchivo As String
Public NombreBitmaps As String
Public Pazul As Bitmap
Public Pict1 As Bitmap
Public pincel As Pen
Public px As Integer = 10
Public px1 As Integer = 1
Public py As Integer ' centro de la figura
Public py1 As Integer = 1
Public relleno1 As Integer = 2
Public relleno4 As Integer = 4
Public signo As Integer = 1
Public sx As Integer = 0
Public sY As Integer = 0
Public Umbral As Integer = 10
Public varalfa As Single = 0.01
Public vel As Integer = 20
Public X(maximo) As Integer
Public X1(maximo) As Integer
Public X2(maximo) As Integer
Public X3(maximo) As Integer
Public Y(maximo) As Integer
Public Y1(maximo) As Integer
Public Y2(maximo) As Integer
Public Y3(maximo) As Integer
End Module
Imports System.IO
Module Module1
Sub EncontrarSer(a(,) As Integer, nf As Integer, nc As Integer, ByRef px As Integer,
ByRef py As Integer, elem As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1034-
For col = 0 To nc - 1
If a(fila, col) = elem Then
px = col
py = fila
Exit Sub
End If
Next col
Next fila
End Sub
Private Sub cmdGrabarVector_Click()
Dim fila As Integer
Form1.OpenFileDialog1.ShowDialog()
NombreArchivo = Form1.OpenFileDialog1.FileName
Dim escritor As StreamWriter
escritor = New StreamWriter(nombreArchivo)
For fila = 1 To nelem
escritor.WriteLine(" {0}{1}{2}{4} ", X(fila), vbTab, Y(fila), vbCrLf)
Next
escritor.Close()
End Sub
Function evaluar(X() As Integer, Y() As Integer, ne As Integer, _
px As Integer, py As Integer, camino As Integer, borde1 As Integer) As Integer
Dim valor1 As Integer, valor2 As Integer, valor3 As Integer, col As Integer
Dim suma As Integer
Dim fila1 As Integer, col1 As Integer
valor1 = 1
valor2 = 1
valor3 = 1
If px = 3 And py = 6 Then
px = 3
End If
For col = 0 To ne - 1
If (X(col) = px And Y(col) = py) Then
valor1 = 0
Exit For
End If
Next
If Azules(py, px) <> camino Then valor2 = 0
suma = 0
For fila1 = py - 1 To py + 1
For col1 = px - 1 To px + 1
If Azules(fila1, col1) = borde1 Then
suma = suma + 1
End If
Next
Next
If suma < 1 Then valor3 = 0
evaluar = valor1 * valor2 * valor3
End Function
Sub RecuperarPuntos(NombreArchivo As String, X() As Integer, Y() As Integer,
ByRef nelem As Integer)
Dim cadena As String, subcadena As String
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1035-
Dim pos As Integer
lector = New StreamReader(NombreArchivo)
contador = 0
cadena = lector.ReadLine
Do While Not (cadena Is Nothing)
cadena = cadena & Chr(9)
pos = InStr(1, cadena, Chr(9))
subcadena = Mid(cadena, 1, pos - 1)
X(contador) = Val(subcadena)
subcadena = Mid(cadena, pos + 1, Len(cadena) - pos)
Y(contador) = Val(subcadena)
cadena = lector.ReadLine
contador = contador + 1
Loop
lector.Close()
nelem = contador - 1
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Integer, ByVal
nf As Integer, ByVal nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = CStr(CInt(CSng(Val(subcadena))))
inicio = pos + 1
Next
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Function calcularborde() As Integer
Dim res As Integer
res = 0
Do
res = evaluar(X, Y, contador, px1 + 1, py1, camino, borde1) ' *** derecha
If res = 1 Then
px1 = px1 + 1
X(contador) = px1
Y(contador) = py1
contador = contador + 1
Exit Do
End If
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1036-
res = evaluar(X, Y, contador, px1, py1 + 1, camino, borde1) '**+ abajo
If res = 1 Then
py1 = py1 + 1
X(contador) = px1
Y(contador) = py1
contador = contador + 1
Exit Do
End If
res = evaluar(X, Y, contador, px1 - 1, py1, camino, borde1) ' Izquierda
If res = 1 Then
px1 = px1 - 1
X(contador) = px1
Y(contador) = py1
contador = contador + 1
Exit Do
End If
res = evaluar(X, Y, contador, px1, py1 - 1, camino, borde1) ' *** arriba
If res = 1 Then
py1 = py1 - 1
X(contador) = px1
Y(contador) = py1
contador = contador + 1
Exit Do
res = 0
Exit Do
End If
Loop While res = 1
calcularborde = res
End Function
Sub GrabarMatriz(NombreArchivo As String, A(,) As Integer, nf As Integer, nc As
Integer)
Dim fila, col As Integer
escritor = New StreamWriter(NombreArchivo)
For fila = 0 To nf - 1
For col = 0 To nc - 1
escritor.Write("{0}{1}", A(fila, col), vbTab)
Next col
escritor.WriteLine()
Next
escritor.Close()
End Sub
Sub Centroide(X() As Integer, Y() As Integer, nelem As Integer, ByRef sx As Integer,
ByRef sy As Integer)
Dim fila As Integer
For fila = 0 To nelem - 1
sx = sx + X(fila)
sy = sy + Y(fila)
Next
sx = sx / nelem
sy = sy / nelem
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1037-
Function EsPosible(X() As Integer, Y() As Integer, nelem As Integer, px As Integer,
py As Integer) As Integer
Dim valor As Integer = 0
Dim fila As Integer
For fila = 0 To nelem - 1
If X(fila) = px And Y(fila) = py Then
valor = 1
Exit For
End If
Next
Return valor
End Function
End Module
Imports System.IO
Public Class Form1
Sub Iniciar()
DataGridView1.RowCount = 8
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).Width = 50
DataGridView1.Columns(1).Width = 50
DataGridView1.Columns(2).Width = 50
DataGridView1.Columns(0).HeaderText = "Prop"
DataGridView1.Columns(1).HeaderText = "V1"
DataGridView1.Columns(2).HeaderText = "V2"
DataGridView1.Rows(0).Cells(0).Value = "Ancho/alto"
DataGridView1.Rows(0).Cells(1).Value = nc
DataGridView1.Rows(0).Cells(2).Value = nf
DataGridView1.Rows(1).Cells(0).Value = "alfa"
DataGridView1.Rows(1).Cells(1).Value = alfa1
DataGridView1.Rows(1).Cells(2).Value = alfa2
DataGridView1.Rows(2).Cells(0).Value = "VarAlfa"
DataGridView1.Rows(2).Cells(1).Value = varalfa
DataGridView1.Rows(3).Cells(0).Value = "Npuntos"
DataGridView1.Rows(3).Cells(1).Value = ne1
DataGridView1.Rows(3).Cells(2).Value = ne2
DataGridView1.Rows(4).Cells(0).Value = "vel/relleno"
DataGridView1.Rows(4).Cells(1).Value = vel
DataGridView1.Rows(4).Cells(2).Value = resn
DICCIONARIO TRADUCTOR
Imports System.IO
Module Module1
Public A(25000, 2) As String
Public nf As Integer
Sub LeerArchivo(A(,) As String, ByRef nf As Integer)
Dim srLector As StreamReader = New StreamReader("e:\DATOS\DIC1.txt")
Dim Linea As String
Dim cont As Integer = 0
Dim pos As Integer
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
pos = InStr(1, Linea, Chr(9))
A(cont, 0) = Mid(Linea, 1, pos - 1)
A(cont, 1) = Mid(Linea, pos + 1, Len(Linea))
cont = cont + 1
Linea = srLector.ReadLine()
Loop
nf = cont
End Sub
End Module
Imports System.IO
Module Module1
Public A(25000, 2) As String
Public nf As Integer
Sub LeerArchivo(A(,) As String, ByRef nf As Integer)
Dim srLector As StreamReader = New StreamReader("e:\DATOS\DIC1.txt")
Dim Linea As String
Dim cont As Integer = 0
Dim pos As Integer
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1049-
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
pos = InStr(1, Linea, Chr(9))
A(cont, 0) = Mid(Linea, 1, pos - 1)
A(cont, 1) = Mid(Linea, pos + 1, Len(Linea))
cont = cont + 1
Linea = srLector.ReadLine()
Loop
nf = cont
End Sub
Sub BuscarInglesCastellano(A(,) As String, Ingles As String, nf As Integer)
Dim i As Integer
Dim largo As Integer
Dim cont1 As Integer = 0
For i = 0 To nf - 1
largo = InStr(A(i, 0), Ingles)
If largo > 0 Then
Console.WriteLine(" {0}===> {1} ====>{2}", cont1, A(i, 0), A(i, 1))
cont1 = cont1 + 1
End If
Next
Console.WriteLine("Palabras encontradas{0}", cont1)
End Sub
Sub BuscarCastellanoIngles(A(,) As String, Castellano As String, nf As Integer)
Dim i As Integer
Dim largo As Integer
Dim cont1 As Integer = 0
For i = 0 To nf - 1
largo = InStr(A(i, 1), Castellano)
If largo > 0 Then
Console.WriteLine(" {0}===> {1} ====>{2}", cont1, A(i, 1), A(i, 0))
cont1 = cont1 + 1
End If
Next
Console.WriteLine("Palabras encontradas{0}", cont1)
End Sub
Sub Main()
LeerArchivo(A, nf)
Dim opcion As Integer
Dim Ingles, Castellano As String
Do
Console.WriteLine("1. Ingles castellano 2. Castellano Ingles 3.Salir ")
Console.Write("ingrese opcion ")
opcion = Console.ReadLine()
Select Case opcion
Case 1
Console.WriteLine("Ingrese palabra en Inglés ")
Ingles = Console.ReadLine
BuscarInglesCastellano(A, Ingles, nf)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1050-
Case 2
Console.WriteLine("Ingrese palabra en Castellano ")
Castellano = Console.ReadLine
BuscarCastellanoIngles(A, Castellano, nf)
End Select
Loop While opcion <> 3
End Sub
End Module
Imports System.IO
Public Class Form1
Const Maximo As Integer = 25000
Public A(Maximo) As String
Public B(Maximo) As String
Dim fuente As Font
Dim Color As Color
Dim camino As Path
Dim nterminos As Integer = 2
Dim Texto As String = ""
Private Sub InglesEspañol(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInglesEspañol.Click
Dim fila1 As Integer
Dim nombre1 As String
Dim nombre2 As String
Texto = txtFuente.Text
For fila1 = 0 To nterminos - 1
nombre1 = A(fila1) ' INGLES
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1051-
nombre2 = B(fila1) ' ESPAÑOL
Texto = Replace(Texto, nombre1, nombre2)
Next
txtDestino.Text = Texto
End Sub
End Sub
CUADRO CROMATICO
Imports System.Drawing
Public Class Form1
Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha As SolidBrush
Dim ancho As Integer = 255
Dim alto As Integer = 255
Dim color1 As Color
Private Sub btnCromatico_Click(sender As Object, e As EventArgs) Handles
btnCromatico.Click
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1054-
Dim fila, col As Integer
For fila = 0 To alto - 1
For col = 0 To ancho - 1
brocha.Color = Color.FromArgb(fila, col, 0)
Grafico.FillRectangle(brocha, fila, col, 1, 1)
Next
Next
End Sub
Problema 2
PUNTO X Y
0 -3.00 0.00
1 -2.00 5.00
2 -1.00 8.00
3 0.00 9.00
4 1.00 8.00
5 2.00 5.00
6 3.00 0.00
Alfa=0.1
1- Determine la función de salida obtenida para la entrada -3 ( explicar) (3 puntos)
2- Propague el error hacia atrás y calcule los nuevos pesos ( 3 puntos)
3- Elabore un programa en visual Basic modo ocnsola o formulario , o lenguaje c (
3 puntos)
EN PROGRAMACION VISUAL
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1056-
Imports System.IO
Module Module1
Public Const limite As Integer = 5
Public Const limdatos As Integer = 10
b1(0) = 3
b1(1) = 4
b1(2) = 9
b2(0) = 7
b2(1) = 0
x(1) = -3 : y(1) = 0
x(2) = -2 : y(2) = 5
x(3) = -1 : y(3) = 8
x(4) = 0 : y(4) = 9
x(5) = 1 : y(5) = 8
x(6) = 2 : y(6) = 5
x(7) = 3 : y(7) = 0
alfa = 0.1
End Sub
Sub GrabarVector(A() As Single, nf As Integer, nombre As String)
Dim escritor As New StreamWriter(nombre)
Dim i As Integer
For i = 0 To nf - 1
escritor.WriteLine(" suma {0} {1}= {2}", i, vbTab, A(i))
Next
escritor.Close()
End Sub
Sub Mostrar(A() As Single, nf As Integer)
Dim i As Integer
Dim cadena As String = ""
For i = 0 To nf - 1
cadena = cadena + " " + A(i).ToString
Next
Form1.ListBox1.Items.Add(cadena)
End Sub
Sub sigmoidea(A() As Single, nf As Single)
Dim i As Integer
Dim valor As Single
For i = 0 To nf - 1
valor = (Math.Exp(A(i)) - Math.Exp(-A(i))) / (Math.Exp(A(i)) + Math.Exp(-A(i)))
A(i) = valor
Next
End Sub
Function Probar(entrada As Single, salida As Single) As Single
' funcion suma
For i = 0 To ne1 - 1
a1(i) = a1(i) + entrada * w1(i) + b1(i)
Next i
Form1.ListBox1.Items.Add(" la suma es ")
Mostrar(a1, ne1)
' calcular la funcion de salida
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1058-
sigmoidea(a1, ne1)
Form1.ListBox1.Items.Add(" salida de capa 1 a1 ")
Mostrar(a1, ne1)
'salida de la red
a2 = 0
For i = 0 To ne1 - 1
a2 = a2 + a1(i) * w2(i)
Next i
a2 = a2 + b2(0)
Form1.ListBox1.Items.Add(" salida de capa 2 " & a2)
Return a2
End Function
End Module
EVALUACION DE EXPRESIONES
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1059-
'***CODIGO DEL MODULO 1
Module Module1
Public EvalRes As Boolean ' Resultado de la evaluacion
Public CadA, CadB, CadC, CadD, CadE, CadX As String
Public CadenaEcuacion As String
Public Cadena As String = "XXXX"
Public VSignos As String = "^*/"
Public CadSigno As String = ""
Public CadenaExpresion As String
Public nelem As Integer = 0
Public CadNumeros As String = "0123456789.+-*/^() "
Public suma As Single
Public ck As Single = 0.279
' **************
Public x1 As Single = 1
Public Li As Single = -5
Public Ls As Single = 5
Public Dx As Single = 1
Public Ndiv As Integer = 10
Public cx As Integer = 200
Public cy As Integer = 200
Public ex As Integer = 10
Public ey As Integer = 10
Public A As Single = 0
Public B As Single = 0
Public C As Single = 1
Public D As Single = 0
Public vE As Single = 0
Public Umbral As Single = 2
Function PotMultiDivi(cadena As String, tipo As Integer) As String
Dim Signo1, signo2, signo3, cadsigno As String
Dim cad1, cad2, cad3 As String
Dim Cadena1, Cadena2, Cadena3 As String
Dim CadA, CadB As String
Dim pos1, pos2, pos3, posini As Integer
Dim R As Single
Dim fila As Integer
cadena = " " + cadena + " "
cadsigno = ""
Select Case tipo
Case 1 ' si son potencias
For fila = 0 To Len(cadena) - 1
If cadena(fila) = "^" Then
cadsigno = cadena(fila)
pos2 = fila
Exit For
End If
Next
Case 2
'multiplicaciones y divisiones tienen igual prioridad
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1060-
For fila = 0 To Len(cadena) - 1
If cadena(fila) = "*" Or cadena(fila) = "/" Then
cadsigno = cadena(fila)
pos2 = fila
Exit For
End If
Next
End Select
' primero buscamos si son las potencias
CadA = Extrae(cadena, 0, pos2 - 1)
CadB = Extrae(cadena, pos2 + 1, Len(cadena) - 1)
' la cadena anterior
For fila = pos2 - 1 To 0 Step -1
If cadena(fila) = "+" Or cadena(fila) = "-" Or cadena(fila) = "*" Or cadena(fila) =
"/" Or cadena(fila) = "^" Then
pos1 = fila
Exit For
Else
cad1 = cadena(fila) + cad1
End If
Next
' busca hacia adelante
pos3 = pos2
' si el primer signo + o - entonces si cuenta 2o
If CadB(0) = "+" Or CadB(0) = "-" Then
posini = pos2 + 2
cad3 = CadB(0)
Else
cad3 = ""
posini = pos2 + 1
End If
pos3 = Len(cadena) - 1
For fila = posini To Len(cadena) - 1
' cadsigno = cadena(fila)
If cadena(fila) = "+" Or cadena(fila) = "-" Or _
cadena(fila) = "*" Or cadena(fila) = "/" Or cadena(fila) = "^" Or fila >
Len(cadena) - 1 Then
pos3 = fila
Exit For
Else
cad3 = cad3 + cadena(fila)
End If
Next
Select Case cadsigno
Case "^" : R = Val(cad1) ^ Val(cad3) 'tiene mayor prioridad
Case "*" : R = Val(cad1) * Val(cad3)
Case "/" : R = Val(cad1) / Val(cad3)
End Select
'reemplazamos el resultado de la multiplicacion
Cadena1 = Extrae(cadena, 0, pos1)
Cadena3 = Extrae(cadena, pos3, Len(cadena) - 1)
' juntamos la cadena
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1061-
Cadena2 = Str(R)
' Console.WriteLine(" la cadena 1 es {0} ", Cadena1)
' Console.WriteLine(" la cadena 2 es {0} ", Cadena2)
' Console.WriteLine(" la cadena 3 es {0} ", Cadena3)
Signo1 = Cadena1(Len(Cadena1) - 1)
signo2 = Cadena2(0)
Select Case Signo1
Case "+"
Select Case signo2
Case "+" : signo3 = "+"
Case " " : signo3 = "+"
Case "-" : signo3 = "-"
End Select
Case "-"
Select Case signo2
Case "+" : signo3 = "-"
Case " " : signo3 = "-"
Case "-" : signo3 = "+"
End Select
Case "*"
signo3 = Signo1
Case "/"
signo3 = Signo1
End Select
Cadena1 = Extrae(Cadena1, 0, Len(Cadena1) - 2)
Cadena2 = Extrae(Cadena2, 1, Len(Cadena2) - 1)
cadena = Cadena1 + signo3 + Cadena2 + Cadena3
Return cadena
End Function
End Function
Function EvaluarExpresion(cadena As String) As Single
Dim R As Single
' quitamos los parentesis primero
cadena = CadLibre(cadena)
' Console.WriteLine(" la cadena resultante es {0} ", cadena)
' evaluamos la cadena
nelem = contar(cadena, "^")
For fila = 0 To nelem - 1
cadena = PotMultiDivi(cadena, 1) ' es de tipo potencia
Next
' Console.WriteLine("cadena es {0} ", cadena)
nelem = 0
nelem = contar(cadena, "*")
nelem = nelem + contar(cadena, "/")
For fila = 0 To nelem - 1
cadena = PotMultiDivi(cadena, 2) 'l multiplicaciones y divisiones
Next
' evaluamos la cadena sis parentesis
Console.WriteLine("cadena final {0} ", cadena)
cadena = " " + cadena + " "
R = Sumasrestas(cadena)
Return R
End Function
Function CadLibre(Cadena As String) As String
Dim subcadena As String
Dim Cadena1, Cadena2, cadena3 As String
Dim cpar As Integer
Dim R As Single
Dim fila, k, pos1, pos2 As Integer
cpar = contar(Cadena, "(")
For k = 0 To cpar - 1
' primero quitamos los parentesis
pos1 = Encontrar(Cadena, "(", 1)
pos2 = Encontrar(Cadena, ")", pos1 + 1)
subcadena = Extrae(Cadena, pos1 + 1, pos2 - 1)
' Console.WriteLine(" subcadena {0}", subcadena)
' evaluamos la cadena
nelem = contar(subcadena, "^")
For fila = 0 To nelem - 1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1065-
subcadena = PotMultiDivi(subcadena, 1) ' es de tipo potencia
Next
' Console.WriteLine("cadena es {0} ", subcadena)
nelem = 0
nelem = contar(subcadena, "*")
nelem = nelem + contar(subcadena, "/")
For fila = 0 To nelem - 1
subcadena = PotMultiDivi(subcadena, 2)
Next
Console.WriteLine("cadena final {0} ", subcadena)
subcadena = " " + subcadena + " "
R = Sumasrestas(subcadena)
Console.WriteLine(" la suma y resta es {0}", R)
' formando la nueva cadena
Cadena1 = Extrae(Cadena, 0, pos1 - 1)
Cadena2 = Str(R)
cadena3 = Extrae(Cadena, pos2 + 1, Len(Cadena) - 1)
Cadena = Cadena1 + Cadena2 + cadena3
Next
Return Cadena
End Function
Function Sumasrestas(cadena As String) As Single
Dim suma As Single
Dim signo1, signo2, subcadena As String
Dim psigno1, psigno2, possigno As Integer
Dim cont1, cont2, largo As Integer
largo = Len(cadena)
' buscar el primer signo si es mas o menos
psigno1 = Encontrar(cadena, "+", 0)
psigno2 = Encontrar(cadena, "-", 0)
If psigno1 < psigno2 Then
possigno = psigno1
Else
possigno = psigno2
End If
cont1 = possigno + 1
cont2 = possigno + 1
signo1 = cadena(possigno)
' sumas y restas
suma = 0
While (cont2 < largo)
signo2 = cadena(cont2)
If signo2 = "-" Or signo2 = "+" Or cont2 >= largo - 1 Then
subcadena = Extrae(cadena, cont1, cont2 - 1)
' Console.WriteLine("subcadena {0} ", subcadena)
Select Case signo1
Case "+" : suma = suma + Val(subcadena)
Case "-" : suma = suma - Val(subcadena)
End Select
signo1 = signo2
cont2 = cont2 + 1
cont1 = cont2
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1066-
' Console.WriteLine("la suma es {0}", suma)
Else
cont2 = cont2 + 1
End If
End While
Return suma
End Function
End Module
' *** CODIGO DEL FORMULARIO
Public Class Form1
Dim Grafico As Graphics
Dim pen As Pen
Sub ObtenerValores()
cx = DataGridView1.Rows(0).Cells(1).Value
cy = DataGridView1.Rows(1).Cells(1).Value
Li = DataGridView1.Rows(2).Cells(1).Value
Ls = DataGridView1.Rows(3).Cells(1).Value
Ndiv = DataGridView1.Rows(4).Cells(1).Value
Dx = DataGridView1.Rows(5).Cells(1).Value
A = DataGridView1.Rows(6).Cells(1).Value
B = DataGridView1.Rows(7).Cells(1).Value
C = DataGridView1.Rows(8).Cells(1).Value
D = DataGridView1.Rows(9).Cells(1).Value
vE = DataGridView1.Rows(10).Cells(1).Value
x1 = DataGridView1.Rows(11).Cells(1).Value
ex = DataGridView1.Rows(12).Cells(1).Value
ey = DataGridView1.Rows(13).Cells(1).Value
ck = DataGridView1.Rows(14).Cells(1).Value
End Sub
Function ObtenerEcuacion(CadExpresion As String, cadA As String, cadB As String, _
cadC As String, cadD As String, cadE As String, cadX As String)
CadExpresion = Reemplazar(CadExpresion, "A", cadA)
CadExpresion = Reemplazar(CadExpresion, "B", cadB)
CadExpresion = Reemplazar(CadExpresion, "C", cadC)
CadExpresion = Reemplazar(CadExpresion, "D", cadD)
CadExpresion = Reemplazar(CadExpresion, "E", cadE)
CadExpresion = Reemplazar(CadExpresion, "X", cadX)
Return CadExpresion
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
pen = New Pen(Brushes.Red, 2)
DataGridView1.RowCount = 15
DataGridView1.ColumnCount = 2
DataGridView1.Columns(0).HeaderText = "Prop"
DataGridView1.Columns(1).HeaderText = "Valor"
DataGridView1.Columns(0).Width = 60
DataGridView1.Columns(1).Width = 80
DataGridView1.Rows(0).Cells(0).Value = "Cx"
DataGridView1.Rows(0).Cells(1).Value = cx
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1067-
DataGridView1.Rows(1).Cells(0).Value = "Cy"
DataGridView1.Rows(1).Cells(1).Value = cy
DataGridView1.Rows(2).Cells(0).Value = "Li"
DataGridView1.Rows(2).Cells(1).Value = Li
DataGridView1.Rows(3).Cells(0).Value = "Ls"
DataGridView1.Rows(3).Cells(1).Value = Ls
DataGridView1.Rows(4).Cells(0).Value = "Nd"
DataGridView1.Rows(4).Cells(1).Value = Ndiv
DataGridView1.Rows(5).Cells(0).Value = "Dx"
DataGridView1.Rows(5).Cells(1).Value = Dx
DataGridView1.Rows(6).Cells(0).Value = "A"
DataGridView1.Rows(6).Cells(1).Value = A
DataGridView1.Rows(7).Cells(0).Value = "B"
DataGridView1.Rows(7).Cells(1).Value = B
DataGridView1.Rows(8).Cells(0).Value = "C"
DataGridView1.Rows(8).Cells(1).Value = C
DataGridView1.Rows(9).Cells(0).Value = "D"
DataGridView1.Rows(9).Cells(1).Value = D
DataGridView1.Rows(10).Cells(0).Value = "E"
DataGridView1.Rows(10).Cells(1).Value = vE
DataGridView1.Rows(11).Cells(0).Value = "X"
DataGridView1.Rows(11).Cells(1).Value = x1
DataGridView1.Rows(12).Cells(0).Value = "EX"
DataGridView1.Rows(12).Cells(1).Value = ex
DataGridView1.Rows(13).Cells(0).Value = "EY"
DataGridView1.Rows(13).Cells(1).Value = ey
DataGridView1.Rows(14).Cells(0).Value = "CK"
DataGridView1.Rows(14).Cells(1).Value = ck
End Sub
Sub ObtenerCadenas()
CadenaEcuacion = txtEcuacion.Text
CadA = DataGridView1.Rows(6).Cells(1).Value
CadB = DataGridView1.Rows(7).Cells(1).Value
CadC = DataGridView1.Rows(8).Cells(1).Value
CadD = DataGridView1.Rows(9).Cells(1).Value
CadE = DataGridView1.Rows(10).Cells(1).Value
CadX = DataGridView1.Rows(11).Cells(1).Value
End Sub
Function Sumasrestas(cadena As String) As Single
Dim suma As Single
Dim signo1, signo2, subcadena As String
Dim psigno1, psigno2, possigno As Integer
Dim cont1, cont2, largo As Integer
largo = Len(cadena)
' buscar el primer signo si es mas o menos
psigno1 = Encontrar(cadena, "+", 0)
psigno2 = Encontrar(cadena, "-", 0)
If psigno1 < psigno2 Then
possigno = psigno1
Else
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1068-
possigno = psigno2
End If
cont1 = possigno + 1
cont2 = possigno + 1
signo1 = cadena(possigno)
' sumas y restas
suma = 0
While (cont2 < largo)
signo2 = cadena(cont2)
If signo2 = "-" Or signo2 = "+" Or cont2 >= largo - 1 Then
subcadena = Extrae(cadena, cont1, cont2 - 1)
' Console.WriteLine("subcadena {0} ", subcadena)
Select Case signo1
Case "+" : suma = suma + Val(subcadena)
Case "-" : suma = suma - Val(subcadena)
End Select
signo1 = signo2
cont2 = cont2 + 1
cont1 = cont2
' Console.WriteLine("la suma es {0}", suma)
Else
cont2 = cont2 + 1
End If
End While
Return suma
End Function
Function Encontrado(SIGNO As String) As Boolean
Dim fila As Integer
Dim valor As Boolean = False
For fila = 0 To Len(CadNumeros) - 1
If CadNumeros(fila) = SIGNO Then
valor = True
Exit For
End If
Next
Return valor
End Function
y = EvaluarExpresion(CadTemporal)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
'Grafico.FillRectangle(Brushes.Blue, x2, y2, ex, ey)
ListBox1.Items.Add(x & " " & y)
Next
End Sub
Private Sub btnVarXA_Click(sender As Object, e As EventArgs) Handles
btnVarXC.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim vc As Single
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1070-
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadC = "C"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For vc = Li To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "C", vc)
x = Li
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
CadTemporal2 = " " + CadTemporal2 + " "
y = EvaluarExpresion(CadTemporal2)
x1 = cx + x * ex
y1 = cy + y * (ey * -1)
For x = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnXd_Click(sender As Object, e As EventArgs) Handles BtnXd.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim vd As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadD = "D"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For vd = Li To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "D", vd)
x = Li
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1071-
CadTemporal2 = " " + CadTemporal2 + " "
y = EvaluarExpresion(CadTemporal2)
x1 = cx + x * ex
y1 = cy + y * (ey * -1)
For x = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnVarXE_Click(sender As Object, e As EventArgs) Handles
BtnVarXE.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim ve As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadE = "E"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For ve = Li To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "E", ve)
x = Li
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
CadTemporal2 = " " + CadTemporal2 + " "
y = EvaluarExpresion(CadTemporal2)
x1 = cx + x * ex
y1 = cy + y * (ey * -1)
For x = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1072-
Private Sub BtnBorra_Click(sender As Object, e As EventArgs) Handles
BtnBorra.Click
Grafico.Clear(Color.Black)
End Sub
Private Sub btnCX_Click(sender As Object, e As EventArgs) Handles btnCX.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim vc As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadC = "C"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For x = Li + Dx To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "X", x)
'BtnBorra_Click(sender, e)
System.Threading.Thread.Sleep(50) ' 1 segundo
Application.DoEvents()
Grafico.Clear(Color.Black)
vc = Li
CadTemporal2 = Reemplazar(CadTemporal1, "C", vc)
y = EvaluarExpresion(CadTemporal2)
x1 = cx + vc * ex
y2 = cy + y * (ey * -1)
For vc = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "C", vc)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + vc * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnFractal_Click(sender As Object, e As EventArgs) Handles
BtnFractal.Click
Dim brocha As SolidBrush
brocha = New SolidBrush(Color.FromArgb(255, 0, 0))
Dim cadena1 As String
Dim Resultado As Single
Dim cont As Integer = 0
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1073-
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
TxtExpresion.Text = CadenaExpresion
ListBox1.Items.Clear()
Dx = (Ls - Li) / Ndiv
For fila = Li To Ls Step Dx
cadena1 = ""
Resultado = Fractal(fila, cadena1)
' Console.WriteLine("cont {0} X {1} Y {2} {3} ", cont, fila, Resultado, cadena)
ListBox1.Items.Add(" cont " & cont & " fila " & fila & "res " & Resultado & " cad "
& cadena1)
cont = cont + 1
Grafico.FillRectangle(brocha, cx + fila * ex, cy + Resultado * ey * (-1), ex, ey)
Next
' Console.ReadLine()
End Sub
Los trabajos tienen que ser en modo visual . se deben presentar en grupos de 3
1. Aplicación de fractales y recursividad ejemplo modelización de terrenos
2. Aplicación de autómatas celulares y computación universal. Juego de la vida en
2d y 3D
3. Aplicación del programa del buscador en optimización en modo grafico
4. Manejo del puerto USB
5. Programación de ADN manejo de secuencias cadenas
6. Programación genérica plantillas ( Templates)
7. Base de datos biológica
8. Aplicación 3d en opengl y visual estudio 2010, Simulación 3D
9. Aplicaciones Web Lenguaje HTML, Java, etc. y su importancia
10. Temas de inteligencia artificial como programación evolutiva , redes
neuronales,etc
11. Sistemas de información en Office Excel
12. My sql
13. Automatización industrial plc, sensores,
14. Aplicaciones de sistemas de información para optimización
15. Simulación 3d, ejemplo simio.etc
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1074-
16. Programación en Windows. Uso de otros controles como por ejemplo el
Microsoft char
17. Programación genérica plantillas ( Templates)
18. Seguridad de base de datos en sqlserver
19. Otros temas relacionados al curso de sistemas de información
20. usando recursividad encuentre la posicion de cada objeto y cuantos
elementos tiene cada uno
EVALUACION DE EXPRESIONE
Module Module2
Public Signo As Integer
Function Evaluar(ByVal Txt As String) As String
Dim i As Integer, oNB As Integer, fNB As Integer
Dim P1 As Integer, P2 As Integer
Dim Buff As String
' Dim T As String
'Para los calculos es necesario un punto en lugar de la coma
Txt = Replace(Txt, ",", ".")
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1075-
'Ver si hay (
For i = 1 To Len(Txt)
If Mid(Txt, i, 1) = "(" Then oNB = oNB + 1
Next i
'Si hay ( (abiertos), ver si concuerdan) (cerrados)
If oNB > 0 Then
For i = 1 To Len(Txt)
If Mid(Txt, i, 1) = ")" Then fNB = fNB + 1
Next i
Else
'No hay parentesis, Evalua directamente el calculo
Evaluar = EvaluaExpresion(Txt)
Exit Function
End If
If oNB <> fNB Then
'Los parentesis no concuerdan, mostrar mensaje de error de parentesis
Return "ERROR"
Exit Function
End If
Module Module1
Sub TestCalcul()
Dim A As String
Dim Ret As String
A = "(((3*(12.223+ 15)) - 7)*21)/7"
Ret = Evaluar(A)
'Debug.Print Ret
'= 224.007
A = "((123.32/2.67)*6)+2127.34"
Ret = Evaluar(A)
'=2404.46359550562
'Debug.Print Ret
End Sub
Sub Main()
TestCalcul()
Console.ReadLine()
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1077-
End Sub
End Module
Fractal
Module Module1
Dim Li, Ls, Dx As Single
Dim x, y As Single
Dim k As Single = 0.279
Dim umbral As Single = 2
Dim cont As Integer = 0
Function Fractal(Li As Single, ByRef cadres As String) As Single
Dim fila As Integer
cadres = "Dentro"
Dim valor As Single = 0
x = Li
cont = 0
For fila = 1 To 25
y = Math.Pow(x, 2) - k
' Console.WriteLine("fila {0} x {1} y {2}", fila, x, y)
cont = cont + 1
If Math.Abs(y) > umbral Then
cadres = "FUERA"
Exit For
End If
x=y
Next
If cont > 24 Then
valor = y
Else
valor = cont
End If
Return valor
End Function
Sub Main()
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1078-
Dim cadena As String
Dim Resultado As Single
Dim cont As Integer = 0
Li = -2
Ls = 2
Dx = 0.05
For fila = Li To Ls Step Dx
Resultado = Fractal(fila, cadena)
Console.WriteLine("cont {0} X {1} Y {2} {3} ", cont, fila, Resultado, cadena)
cont = cont + 1
Next
Console.ReadLine()
End Sub
End Module
11.19 VER UNA PARTE DE LA PANTALLA Modificar el programa para ver parte de
una pantalla(corregir)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1079-
'****** CODIGO DEL MODULO 1
Imports System.IO
Module Module1
Public Npremios As Integer = 10
Public Px As Integer = 10 ' posicion X del curso en la matrizal
Public Py As Integer = 10 ' posicon Y del cursor en la matriz
Public RxTem(10) As Integer ' variable para obtener temporal
Public RyTem(10) As Integer ' variable y para obtener temporal
Public RValor1(10) As Integer ' variable que almacena el valor
Public RValor2(10) As Integer ' variable que almacena el valor
Imports System.IO
Module Module1
Imports System.Drawing
Public Class Form1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1088-
Public alturamaxima As Integer = 20
Public maxcol As Integer = 2
Public maxfilas As Integer = 100
Public A(maxfilas, maxcol) As Single
Public NombreArchivo As String = "E:\datos\datos1.txt"
Public grafico As Graphics
Public pen As Pen
Public pen1 As Pen
Public brocha As SolidBrush
Public brochaletra As SolidBrush
Public cx As Integer = 30
Public cy As Integer = 420
Public ex As Integer = 40
Public ey As Integer = 20
Public alto As Integer = 450
Public ancho As Integer = 600
Public nf As Integer = 5
Public nc As Integer = 2
Public li As Integer = 0
Public ls As Integer = 5
Dim MiFuente As New Font("Verdana", 10, FontStyle.Bold)
End Sub
Sub MostrarCadenas(Cadenas() As String, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
Console.WriteLine("{0}", Cadenas(fila))
Next
End Sub
cad1 = cad3
Return cont
End Function
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1093-
Function obtenerVectores(Mred(,) As String, Act() As String, X() As Integer, Y() As
Integer, nact As Integer) As Integer
Dim k, nf1, nc1 As Integer
Dim letra As String
Dim posletra As Boolean
Dim cont As Integer = 0
For k = 0 To nact - 1
letra = Act(k)
posletra = EncontrarLetraMatriz(MR1, letra, ncad1, nper, nf1, nc1)
If posletra = True Then
X(cont) = nc1
Y(cont) = nf1
cont = cont + 1
End If
Next
Return cont
End Function
End Sub
Sub MostrarMatriz(M(,) As String, nf As Integer, nc As Integer)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1096-
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0,2}", M(fila, col))
Next
Console.WriteLine()
Next
End Sub
Module Module1
Public Const maxcol As Integer = 20
Public Const maxfilas As Integer = 10
Public Act(maxfilas) As String
Public Asig(maxfilas) As String
Public brocha As SolidBrush
Public brochaTexto As SolidBrush
Public Cadenas1(maxcol) As String ' cadena de secuencias origen destino
Public Const max As Integer = 5
Public cx As Integer = 10
Public cy As Integer = 10
Public ex As Integer = 80
Public ey As Integer = 80
Public Grafico As Graphics
Public MGantt(maxfilas, maxcol) As String
Public MP(maxfilas, maxcol) As String
Public MR1(maxfilas, maxcol) As String
'Public MRed(,) As String = {{"A", "B", "C", "E"}, {"A", "D", "E", "X"}}
Public nact As Integer = 5
Public ncad1 As Integer ' cantidad de cadenas iniciales
Public nper As Integer = 4
Public Nper1 As Integer = 15
Public npuntos As Integer
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1098-
Public Pen As Pen
Public Periodos(maxcol) As Integer
Public plantilla As String = "ABCDE"
Public redcol As Integer
Public T(maxfilas) As Integer
Public X(maxfilas) As Integer
Public Y(maxcol) As Integer
Public nvec As Integer
Public Nelem As Integer
Dim CAD1(10) As String
Sub Iniciar()
Dim letra As String
'Iniciar1()
IniciarMatriz(MR1, nact, Nper1)
IniciarMatriz(MP, nact, Nper1)
IniciarMatriz(MGantt, nact, Nper1)
MostrarCadenas(CAD1, Nelem)
Next
End Sub
Sub Leer3VectoresF(V1() As String, V2() As String, V3() As Integer, ne As Integer)
Dim fila As Integer
For fila = 0 To ne - 1
V1(fila) = DataGridView1.Rows(fila).Cells(0).Value
V2(fila) = DataGridView1.Rows(fila).Cells(1).Value
V3(fila) = DataGridView1.Rows(fila).Cells(2).Value
Next
End Sub
Sub Mostrar4VectoresF(V1() As String, V2() As Integer, V3() As Integer, V4() As
Integer, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
DataGridView2.Rows(fila).Cells(0).Value = V1(fila)
DataGridView2.Rows(fila).Cells(1).Value = V2(fila)
DataGridView2.Rows(fila).Cells(2).Value = V3(fila)
DataGridView2.Rows(fila).Cells(3).Value = V4(fila)
Next
End Sub
DataGridView1.Columns(0).HeaderText = "Act"
DataGridView1.Columns(1).HeaderText = "Sig"
DataGridView1.Columns(2).HeaderText = "Tiempog"
Iniciar1()
DataGridView2.RowCount = 5
DataGridView2.ColumnCount = 4
DataGridView2.Columns(0).Width = 40
DataGridView2.Columns(1).Width = 40
DataGridView2.Columns(2).Width = 40
DataGridView2.Columns(3).Width = 40
DataGridView2.Columns(0).HeaderText = "Act"
DataGridView2.Columns(1).HeaderText = "X"
DataGridView2.Columns(2).HeaderText = "Y"
DataGridView2.Columns(3).HeaderText = "PER"
End Sub
Sub Graficar(Act() As String, X() As Integer, Y() As Integer, ne As Integer)
Dim fila As Integer
Dim MiFuente As New Font("Verdana", 20, FontStyle.Bold)
End Sub
letra2 = Cadenas1(fila)(1)
nrofila = EncontrarFilaCadena(plantilla, letra2, nact)
x2 = X(nrofila)
y2 = Y(nrofila)
Grafico.DrawLine(Pen, cx + x1 * ex + CInt(ex / 2), cy + y1 * ey + CInt(ey / 4), cx
+ x2 * ex, cy + y2 * ey + CInt(ey / 4))
Next
End Sub
Sub MostrarMatriz(Matriz(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Select Case Matriz(fila, col)
Case "A"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(255, 0, 0)
Case "B"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(0, 255, 0)
Case "C"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(0, 0, 255)
Case "D"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(255, 255, 0)
Case "E"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(255, 0, 255)
Case "F"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(0, 255, 255)
Case "G"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(255, 155, 0)
Case "H"
DataGridView3.Rows(fila).Cells(col).Style.BackColor =
Color.FromArgb(155, 255, 155)
End Select
DataGridView3.Rows(fila).Cells(col).Value = Matriz(fila, col)
Next
Next
End Sub
Private Sub btnGantt_Click(sender As Object, e As EventArgs) Handles
btnGantt.Click
btnUnir_Click(sender, e)
Dim col As Integer
DataGridView3.RowCount = nact
DataGridView3.ColumnCount = Nper1
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1102-
' poner titulos de la columnas
DataGridView3.Columns(0).HeaderText = "Act\Per"
For col = 0 To Nper1 - 1
DataGridView3.Columns(col).HeaderText = Periodos(col)
DataGridView3.Columns(col).Width = 30
Next
For fila = 0 To nact - 1
DataGridView3.Rows(fila).HeaderCell.Value = Act(fila)
Next
MostrarMatriz(MGantt, nact, Nper1)
End Sub
End Sub
End Sub
End Sub
End Class
End Sub
Sub MostrarMatriz(M(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0,2}", M(fila, col))
Next
Console.WriteLine()
Next
End Sub
' FORMULARIO
Imports System.Drawing
End Sub
letra2 = Cadenas1(fila)(1)
nrofila = EncontrarFilaCadena(plantilla, letra2, nact)
x2 = X(nrofila)
y2 = Y(nrofila)
Grafico.DrawLine(Pen, cx + x1 * ex + CInt(ex / 2), cy + y1 * ey + CInt(ey / 4), cx
+ x2 * ex, cy + y2 * ey + CInt(ey / 4))
Next
End Sub
Sub MostrarMatriz(Matriz(,) As String, nf As Integer, nc As Integer)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1111-
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView3.Rows(fila).Cells(col).Value = Matriz(fila, col)
Next
Next
End Sub
Private Sub btnGantt_Click(sender As Object, e As EventArgs) Handles
btnGantt.Click
btnUnir_Click(sender, e)
Dim col As Integer
DataGridView3.RowCount = nact
DataGridView3.ColumnCount = Nper1
' poner titulos de la columnas
DataGridView3.Columns(0).HeaderText = "Act\Per"
For col = 0 To Nper1 - 1
DataGridView3.Columns(col).HeaderText = Periodos(col)
DataGridView3.Columns(col).Width = 30
Next
For fila = 0 To nact - 1
DataGridView3.Rows(fila).HeaderCell.Value = Act(fila)
Next
MostrarMatriz(MGantt, nact, Nper1)
End Sub
End Sub
End Class
Module Module2
Sub MostrarCadenas(Cadenas() As String, nf As Integer)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1112-
Dim fila As Integer
For fila = 0 To nf - 1
Console.WriteLine("{0}", Cadenas(fila))
Next
End Sub
Function cadenas2(cadenas() As String, cad1() As String, letra As String, ne As
Integer) As Integer
Dim fila As Integer
Dim cont As Integer = 0
For fila = 0 To ne - 1
If letra = cadenas(fila)(0) Then
cad1(cont) = cadenas(fila)
cont = cont + 1
End If
Next
Return cont
End Function
Dim Cad2(10) As String
Function cadenas3(cadenas() As String, ByRef cad1() As String, letra As String, ne
As Integer, ini As Integer) As Integer
Dim fila As Integer
Dim cont As Integer = 0
Dim cad2(10) As String
Dim cad3(10) As String
Dim letra1 As String
Dim letra2 As String
Dim nf1 As Integer
For fila = 0 To ne - 1
letra2 = (cadenas(fila)(0))
If letra = letra2 Then
cad2(cont) = cadenas(fila)
cont = cont + 1
End If
Next
nf1 = cont
'' trasladra a cadena reemplazando la ultima letra con todas las combinaciones
de cad
cont = 0
Dim letra4 As String
For fila = 0 To ini - 1
Dim largo As Integer
letra1 = cad1(fila)
largo = Len(letra1)
letra4 = letra1(largo - 1)
If letra = letra4 Then
' reemplaza con todos los posibles valores
For k = 0 To nf1 - 1
cad3(cont) = cad1(fila) + cad2(k)(1)
cont = cont + 1
Next
Else
cad3(cont) = cad1(fila)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1113-
cont = cont + 1
End If
Next
cad1 = cad3
Return cont
End Function
End Module
End Module
Programación genética
John Koza, en 1992, adaptó los AG para la creación de programas de
computador, permitiendo que las técnicas de Computación Evolutiva se
utilizaran para construir grandes poblaciones de programas que evolucionan
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1114-
y finalmente obtienen, de forma automática, un programa que constituye la
solución a un problema dado. Él mismo bautizó a esta nueva técnica como
“Genetic Programming” o “Programación Genética”.
Así, la Programación Genética (en adelante PG) surge como una
evolución de los AG tradicionales, manteniendo el mismo principio de
selección natural. Es una técnica de búsqueda en la que, a partir de un
conjunto inicial de programas (población), éstos se van combinando
sucesivamente, formando distintas generaciones para dar lugar a programas
mejores. Al igual que los AG, la PG también forma parte de las
denominadas técnicas de Computación Evolutiva.
ADN molecular
En esta técnica se utiliza el ADN de seres vivos para resolver
problemas computacionales.
Es una técnica masivamente paralela y muy prometedora, pero en la
actualidad el procesado de la información (probetas con piezas de ADN) es
realizado por el investigador y es muy laborioso y lento.
de optimización y búsqueda.
Vida artificial
La Vida Artificial trata acerca de la creación de modelos
computacionales con comportamientos biológicos. Se emplean múltiples
agentes simples para conseguir un comportamiento complejo.
Ronald ofrece una de las definiciones más completa: “la Vida
Artificial es una disciplina experimental que consiste fundamentalmente en
la observación de los comportamientos de ejecución, aquellas interacciones
complejas generadas cuando las poblaciones de criaturas artificiales
hechas por el hombre están inmersas en entornos reales o simulados” [13].
En muchos casos se busca determinar los mecanismos de interacción
entre los individuos de una colectividad que hacen emerger
comportamientos adaptativos o inteligentes al nivel de toda la colectividad
de organismos.
Computación evolutiva
Operadores genéticos
Creatividad Computacional
Redes Backpropagation
BIOINFORMÁTICA: Genética e
Informática
José Mª Barreiro, Juan Pazos1, Alfonso Rodríguez
Autómatas reproductores
La primera aportación de las ciencias
Autorreproducción
Butler en su novela utópica "Erewhon", palabra que, en inglés, es la
imagen especular de "nowhere" que significa en ninguna parte, plantea la
posibilidad de que las máquinas utilicen a los hombres como intermediarios
para construir nuevas máquinas. En el siglo pasado, hubo muchos casos de
331
Imports System.IO
Module Module2
'w1(0) = -16.43
'w1(1) = -157.28
'w2(0) = 6.76
'w2(1) = -10.11
'b1(0) = 3.04
'b1(1) = 150.71
'b2(0) = 6.22
w1(0) = 0
w1(1) = 0
w2(0) = 0
w2(1) = 0
b1(0) = 0
b1(1) = 0
b2(0) = 0
x(0) = -3 : y(0) = 6
x(1) = -2 : y(1) = 3
x(2) = -1 : y(2) = 2
x(3) = 0 : y(3) = 3
x(4) = 1 : y(4) = 6
x(5) = 2 : y(5) = 11
End Sub
End Module
EN PROGRAMACION VISUAL
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1121-
Imports System.IO
Module Module1
Public Const limite As Integer = 5
Public Const limdatos As Integer = 10
w2(0) = 5
w2(1) = 6
w2(2) = 10
b1(0) = 3
b1(1) = 4
b1(2) = 9
b2(0) = 7
b2(1) = 0
x(1) = -3 : y(1) = 0
x(2) = -2 : y(2) = 5
x(3) = -1 : y(3) = 8
x(4) = 0 : y(4) = 9
x(5) = 1 : y(5) = 8
x(6) = 2 : y(6) = 5
x(7) = 3 : y(7) = 0
alfa = 0.1
End Sub
Sub GrabarVector(A() As Single, nf As Integer, nombre As String)
Dim escritor As New StreamWriter(nombre)
Dim i As Integer
For i = 0 To nf - 1
escritor.WriteLine(" suma {0} {1}= {2}", i, vbTab, A(i))
Next
escritor.Close()
End Sub
Sub Mostrar(A() As Single, nf As Integer)
Dim i As Integer
Dim cadena As String = ""
For i = 0 To nf - 1
cadena = cadena + " " + A(i).ToString
Next
Form1.ListBox1.Items.Add(cadena)
End Sub
Sub sigmoidea(A() As Single, nf As Single)
Dim i As Integer
Dim valor As Single
For i = 0 To nf - 1
valor = (Math.Exp(A(i)) - Math.Exp(-A(i))) / (Math.Exp(A(i)) + Math.Exp(-A(i)))
A(i) = valor
Next
End Sub
Function Probar(entrada As Single, salida As Single) As Single
' funcion suma
For i = 0 To ne1 - 1
a1(i) = a1(i) + entrada * w1(i) + b1(i)
Next i
Form1.ListBox1.Items.Add(" la suma es ")
Mostrar(a1, ne1)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1123-
' calcular la funcion de salida
sigmoidea(a1, ne1)
Form1.ListBox1.Items.Add(" salida de capa 1 a1 ")
Mostrar(a1, ne1)
'salida de la red
a2 = 0
For i = 0 To ne1 - 1
a2 = a2 + a1(i) * w2(i)
Next i
a2 = a2 + b2(0)
Form1.ListBox1.Items.Add(" salida de capa 2 " & a2)
Return a2
End Function
End Module
Problema 2
• El diagrama de la red multicapa se muestra en la figura 1. La red tiene 3 capas
una capa de entrada con una neurona, una capa oculta con dos neuronas y una
capa de salida con 1 neurona
• La función de transferencia en la primera capa es la función tangente Sigmoida
Hiperbólica (Ec. 1).
• Y la función de transferencia en la segunda capa (capa de salida ) es la función
lineal ( Ec. 3)
Los valores de entrada son
PUNTO X Y
0 -3.00 0.00
1 -2.00 5.00
2 -1.00 8.00
3 0.00 9.00
4 1.00 8.00
5 2.00 5.00
6 3.00 0.00
Alfa=0.1
4- Determine la función de salida obtenida para la entrada -3 ( explicar) (3
puntos)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1124-
5- Propague el error hacia atrás y calcule los nuevos pesos ( 3 puntos)
6- Elbore un programa en visual Basic modo ocnsola o formulario , o
lenguaje c ( 3 puntos)
Elabore un cuadro compartivo de modleo Modelos usados en sistemas Inteligentes
(minimo 10) ( 3 puntos)
elementos (
Nro. Modelo Descripción grafico) Obs
1 redes neuronales
2 Lógica difusa
3 sistemas expertos
4 algoritmos genéticos
5 autómatas celulares
6 Visón Artificial
7 Vida artificial
8 Robotica
9 Automatizacion
10 Busqueda
11 Adn
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1125-
Imports System.IO
Module Module2
Public Const maxfilas As Integer = 31
Public Const maxcol As Integer = 6
Public A(maxfilas, maxcol) As String
Public Objetos(maxfilas, maxcol) As String
Public Nfilas As Integer = 30
Public Ncol As Integer = 7
Public NfObjetos As Integer = 8
Public NcObjetos As Integer = 4
Module Module1
Dim cadena As String = "ABCEFG"
Sub main()
Dim fila, col, posletra As Integer
RecuperarMatriz(NombreArchivoObjetos, Objetos, NfObjetos, NcObjetos)
MostrarMatriz(Objetos, NfObjetos, NcObjetos)
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1127-
RecuperarMatriz(NombreArchivo, A, Nfilas, Ncol) ' recupera la matriz A
' MostrarMatriz(A, Nfilas, Ncol)
' For fila = 0 To NfObjetos - 1
Dim sumaX, sumaY As Single
Dim npuntos As Integer
For fila = 0 To 0
sumaX = 0
sumaY = 0
npuntos = Len(cadena)
Console.WriteLine("datos de la fila {0} ={1}", fila, Objetos(fila, 2))
cadena = Objetos(fila, 2)
Next
Console.WriteLine("suma x {0} ", sumaX / npuntos)
Console.WriteLine("suma Y {0} ", sumaY / npuntos)
Next
Console.ReadLine()
End Sub
End Module
Imports System.Drawing
End Sub
Private Sub Procesar1(sender As Object, e As EventArgs) Handles btnProcesar.Click
grafico.Clear(Color.Black)
' For fila = 0 To maxfilas - 1
For fila = 0 To 27
ProcesarFila(A, Nfilas, Ncol, fila, Color1)
Next
End Sub
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1129-
Sub MostrarCuadricula(A(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
DataGridView1.RowCount = nf + 1
DataGridView1.ColumnCount = nc
DataGridView1.Columns(0).HeaderText = "Nro"
DataGridView1.Columns(1).HeaderText = "X"
DataGridView1.Columns(2).HeaderText = "Y"
DataGridView1.Columns(3).HeaderText = "Ancho"
DataGridView1.Columns(4).HeaderText = "Alto"
DataGridView1.Columns(5).HeaderText = "Tipo"
DataGridView1.Columns(6).HeaderText = "Titulo"
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 60
Next
For fila = 0 To nf - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
' DataGridView1.Refresh()
End Sub
Sub ModificarMatrizdeCuadricula(A(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = DataGridView1.Rows(fila).Cells(col).Value
Next
Next
' DataGridView1.Refresh()
End Sub
End Sub
End Sub
For fila = 0 To 29
x1 = CSng(A(fila, 1))
y1 = CSng(A(fila, 2))
ancho = CSng(A(fila, 3))
alto = CSng(A(fila, 4))
Titulo = A(fila, 6)
grafico.DrawString(Titulo, MiFuente, brocha3, x1 * ex + ancho * ex / 2, y1 * ey +
alto * ey / 2 - AltoLetra)
Next
End Sub
Sub MostrarObjetos(Objetos(,) As String, nc As Integer, nroobjeto As Integer, ByRef
Px As Single, ByRef py As Single)
Dim Cadena1, letra As String
Dim col As Integer
Dim sumaX, sumaY, sAncho, sAlto As Single
Dim npuntos, posletra As Integer
Dim pancho, palto As Single
ListBox1.Items.Clear()
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1131-
sumaX = 0
sumaY = 0
sAncho = 0
sAlto = 0
Cadena1 = Objetos(nroobjeto, 2)
npuntos = Len(Cadena1)
End Sub
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1132-
Private Sub btnMostrarObjeto_Click(sender As Object, e As EventArgs) Handles
btnMostrarObjeto.Click
Dim titulo As String
Dim fila As Integer = 0
TRANSPARENCIAS
En la sigueinte aplicacion se puede puede mover el objeto trnsaparente.
End Sub
End Class
Juego de la vida
Lenguaje de programación 2015 \11 Aplicaciones Windows Forms \Ismael Véliz Vilca -1135-
'**************** modulo 2
Imports System.IO
Module Module2
Public srLector As StreamReader
Public Const maxfilas As Integer = 42
Public Const maxcol As Integer = 42
Public A(maxfilas, maxcol) As Integer
Public B(maxfilas, maxcol) As Integer
Public Modelo(maxfilas, maxcol) As Integer
Public nf As Integer = 40
Public nc As Integer = 40
Public ng As Integer = 200
'******************modulo 1
Module Module1
Sub Main()
Console.Write("juego de la vida de wonway")
Console.Write("Diseño escenarioen Excel y grabe archivo con bloque de notas ")
Console.Write("juego de la vida de wonway")
RecuperarMatriz("E:\datos\modelo40x20.txt", Modelo, nf, nc)
CopiarMatriz(Modelo, A, nc, nf)
VerPantalla(10, 4, A, nf, nc)
Console.ReadLine()
While (1)
'For i = 0 To ng
JuegoVida(A, B, nf, nc)
VerPantalla(10, 4, A, nf, nc)
'System.Threading.Thread.Sleep(10) ' 1 segundo
'Next
End While
Console.ReadLine()
End Sub
End Module
Imports System.Drawing
Public Class FrmVida
Public grafico As Graphics
Public brocha As SolidBrush
Public borrador As SolidBrush
Public ex As Single = 20
Public ey As Single = 20
Public cx As Integer = 10
Public cy As Integer = 10
Public cont As Integer = 0
Public velocidad As Integer = 50
End Sub
End Sub
End Sub
End Sub