Está en la página 1de 87

Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 1-

prácticas de programación día viernes 23 de marzo del 2018


Ejercicio 1. sumar dos números enteros

Module Module1
Dim nro1, nro2, suma As Integer
Sub Main()
Console.Write(" ingrese nro 1 ")
nro1 = Console.ReadLine
Console.Write(" ingrese nro 2 ")
nro2 = Console.ReadLine
suma = nro1 + nro2
Console.WriteLine(" la suma es {0}", suma)
Console.ReadLine()
End Sub
End Module

Ejercicio 2 modificacion agregando resta

Module Module1
Dim Nro1, Nro2, Suma, resta As Integer
Sub Main()
Console.Write("ingrese nro 1 ")
Nro1 = Console.ReadLine()
Console.Write("ingrese nro 2 ")
Nro2 = Console.ReadLine()
Suma = Nro1 + Nro2
resta = Nro1 - Nro2
Console.WriteLine("La suma es {0} ", Suma)
Console.WriteLine("La resta es {0} ", resta)
Console.ReadLine()
End Sub
End Module

Ejercicio 3. Escribir a colores


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 2-

Module Module1
Dim Nro1, Nro2 As Single
Sub Main()
Console.Write("ingrese nro 1 ") : Nro1 = Console.ReadLine()
Console.Write("ingrese nro 2 ") : Nro2 = Console.ReadLine()
Console.WriteLine("La suma es {0} ", Nro1 + Nro2)
Console.WriteLine("La resta es {0} ", Nro1 - Nro2)
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("La multiplicacion es {0} ", Nro1 * Nro2)
Console.WriteLine("La division entera es {0} ", Nro1 \ Nro2)
Console.WriteLine("La division real es {0} ", Nro1 / Nro2)
Console.ForegroundColor = 10
Console.WriteLine("el modulo es {0} ", Nro1 Mod Nro2)
Console.WriteLine("la raiz cuadrada es {0} ", Math.Sqrt(Nro1))
Console.WriteLine(" {0} elevado a {1} es {2} ", Nro1, Nro2, Math.Pow(Nro1, Nro2))
Console.WriteLine(" le fecha es {0} ", Date.Now)
Console.WriteLine(" el año es {0} ", Date.Now.Year)
Console.WriteLine(" nroo aleaorio es {0} ", Int(Rnd() * 20))
Console.SetCursorPosition(40, 12)
Console.Write("hola")
Console.ReadLine()
End Sub
End Module

Module Module1
Dim Nombre As String
Sub Main()
Console.Write("Como te llamas")
Nombre = Console.ReadLine
Console.ForegroundColor = 9
Console.Write(" *** MUCHO GUSTO DE CONOCERLO")
Console.ForegroundColor = 12
Console.BackgroundColor =14
Console.Write("<<<{0}>>>",NOMBRE)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 3-

Console.ForegroundColor = 9
Console.BackgroundColor = 0
Console.WriteLine("ESTIMADO AMIGO")
Console.ReadLine()
End Sub
End Module

Area del triangulo

Module Module1
Dim base, altura, area As Single
Sub Main()
Console.Write("Ingrese base")
base = Console.ReadLine
Console.Write("Ingrese altura")
altura = Console.ReadLine
area = (base * altura) / 2
Console.WriteLine("el area es {0}",area)
Console.ReadLine()
End Sub
End Module

CLASES DE PROGRAMACION Y METODOS NUMERICOS


VIERNES 06 DE ABRIL DEL 2018

Diagrama de flujo para calcular el area de un triangulo


Usando visual logic
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 4-

Usando DFD 1.0

Programa en Visual Basic modo consola

Module Module1
Dim Area, base, altura As Single
Sub Main()
Console.Write("ingrese base ")
base = Console.ReadLine
Console.Write("ingrese altura ")
altura = Console.ReadLine
Area = (base * altura) / 2
Console.WriteLine(" el area es {0} ", Area)
Console.ReadLine()
End Sub
End Module

Calcular el area del círculo


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 5-

Module Module1
Dim Area, radio As Single
Sub Main()
' este programa calcula area del radio
Console.Write("ingrese radio ")
radio = Console.ReadLine
Area = Math.PI * Math.Pow(radio, 2)
Console.ForegroundColor = 10
Console.WriteLine(" el area del circulo {0} ", Area)
Console.ReadLine()
End Sub
End Module

Calcule el area lateral y total del cilindro

Module Module1
Dim AreaBase, arealateral, areatotal, radio, altura As Single
Dim volumen As Single
Sub Main()
' este programa calcula area del radio
Console.Write("ingrese radio ")
radio = Console.ReadLine
Console.Write("ingrese altura ")
altura = Console.ReadLine
AreaBase = Math.PI * Math.Pow(radio, 2)
Console.ForegroundColor = 10
Console.WriteLine(" el area de la base es {0} ", AreaBase)
arealateral = 2 * Math.PI * radio * altura
Console.WriteLine(" el area lateral es {0} ", arealateral)
areatotal = 2 * AreaBase + arealateral
Console.WriteLine(" el area total es {0} ", areatotal)
volumen = AreaBase * altura
Console.WriteLine(" el volumen es {0} ", volumen)
Console.ReadLine()
End Sub
End Module

Área del circulo en modo formulario

PROBLEMAS
1. AREA DEL Trapecio
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 6-

2. Distancia Euclidiana y rectangular


3. Se ingresa Sueldo de un trabajador que tiene un descuento por AFP de 5 % por
quinta categoria 12% y sindicato 50 soles encuentre el sueldo neto
4. Clase console. Escribir a colores y en una coordenadas especificada
5. Hacer la preguntas de 1 a 4 en modo consola y modo formulario
Solución
Encuentre la distancia euclidiana y rectangular de dos puntos

' distancia de puntos euclidiana e rectangulo


Module Module1
Dim x1, y1, x2, y2, de, dr As Single

Sub Main()
Console.Write("INGRESE x1 ") : x1 = Console.ReadLine()
Console.Write("INGRESE y1 ") : y1 = Console.ReadLine()
Console.Write("INGRESE x2 ") : x2 = Console.ReadLine()
Console.Write("INGRESE y2 ") : y2 = Console.ReadLine()
de = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
dr = Math.Abs(x2 - x1) + Math.Abs(y2 - y1)
Console.WriteLine("Euclidiana (X1,Y1) {0}:{1} Y (X2,Y2) {2}:{3} = {4} ", _
x1, y1, x2, y2, de)
Console.WriteLine("Rectilinea (X1,Y1) {0}:{1} Y (X2,Y2) {2}:{3} = {4} ", _
x1, y1, x2, y2, dr)
Console.ReadLine()
End Sub
End Module

1 2 3 4 5 6 7 8 9 r 11
1 e
2 1 2 3 4 5 6
3 7 x1 y1 2 2
4 8 x2 y2 7 8
5 9
6 10
7 11
8 2
9

Encuentre el área del trapecio


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 7-

Module Module1
Dim BaseMenor, BaseMayor, Area, altura As Single
Sub Main()
Console.Write("INGRESE Base Menor")
BaseMenor = Console.ReadLine()
Console.Write("INGRESE BaseMayor")
BaseMayor = Console.ReadLine()
Console.Write("INGRESE ALtura")
altura = Console.ReadLine()
Area = (BaseMenor + BaseMayor) / 2 * altura
REM este programa calcula area del trapecio
Console.Write("el area es {0}", Area)
Console.ReadLine()
End Sub
End Module
Encuentre los puntos y grafique el triangulo
Elabore el área del triángulo en modo formulario

TAREA PARA LA PROXIMA SEMANA


Sentencias de control
Elaborar los ejercicios del capitulo 2 en modo consola y modo formulario
1. Ejemplo dibujar una marco cuadro líneas , etc

Practicas del dia martes 10 de abril del 2018


El problema del triangulo

Module Module1
Dim x1, x2, x3, y1, y2, y3 As Single
Dim a, b, c, p, area As Single
Sub Main()
X1 = 10 : Y1 = 2
X2 = 10 : Y2 = 12
X3 = 20 : Y3 = 12
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 8-

a = Math.Sqrt(Math.Pow(X2 - X1, 2) + Math.Pow(Y2 - Y1, 2))


b = Math.Sqrt(Math.Pow(x3 - x2, 2) + Math.Pow(y3 - y2, 2))
c = Math.Sqrt(Math.Pow(x3 - x1, 2) + Math.Pow(y3 - y1, 2))
p = 1 / 2 * (a + b + c)
area = Math.Sqrt(p * (p - a) * (p - b) * (p - c))
Console.WriteLine(" valor de a ={0} ", a)
Console.WriteLine(" valor de b ={0} ", b)
Console.WriteLine(" valor de c ={0} ", c)
Console.WriteLine(" perimetro ={0} ", p * 2)
Console.WriteLine("area es {0} ", area)
Console.ReadLine()
End Sub
End Module

Module Module1
Dim x1, x2, x3, y1, y2, y3 As Single
Dim a, b, c, p, area As Single
Sub Main()
Console.Write("x1 ") : x1 = Console.ReadLine
Console.Write("y1 ") : y1 = Console.ReadLine
Console.Write("x2 ") : x2 = Console.ReadLine
Console.Write("y2 ") : y2 = Console.ReadLine
Console.Write("x3 ") : x3 = Console.ReadLine
Console.Write("y3 ") : y3 = Console.ReadLine
a = Math.Sqrt(Math.Pow(X2 - X1, 2) + Math.Pow(Y2 - Y1, 2))
b = Math.Sqrt(Math.Pow(x3 - x2, 2) + Math.Pow(y3 - y2, 2))
c = Math.Sqrt(Math.Pow(x3 - x1, 2) + Math.Pow(y3 - y1, 2))
p = 1 / 2 * (a + b + c)
area = Math.Sqrt(p * (p - a) * (p - b) * (p - c))
Console.WriteLine(" valor de a ={0} ", a)
Console.WriteLine(" valor de b ={0} ", b)
Console.WriteLine(" valor de c ={0} ", c)
Console.WriteLine(" perimetro ={0} ", p * 2)
Console.WriteLine("area es {0} ", area)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 9-

PLAN DE CLASES PMN 13 DE ABRIL DEL 2018


1. EN LAS PRACTICAS Terminar el problema del triangulo
Sentencia if
1. Mayor de dos numero de 3 numeros n números
2. Selección multiple
bucles while
do while for for
sumatoria valores de una función
ejercicios del for. Línea espiral cuadro
triangulo usar funciones
un ser recorre la pantalla en forma aleatoria

Module Module1
Dim N1, N2, mayor As Single
Sub Main()
'N1 = 3 'N2 = 2
Console.Write(" ingrese Nro 1 ")
N1 = Console.ReadLine
Console.Write(" ingrese Nro 2 ")
N2 = Console.ReadLine
If (N1 > N2) Then
mayor = N1
Else
mayor = N2
End If
Console.WriteLine(" le mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 10-

Mayor de 3 numeros

Module Module1
Dim N1, N2, N3, mayor As Single
Sub Main()
Console.Write(" ingrese Nro 1 ")
N1 = Console.ReadLine
Console.Write(" ingrese Nro 2 ")
N2 = Console.ReadLine
Console.Write(" ingrese Nro 3 ")
N3 = Console.ReadLine
mayor = N1
If (N2 > mayor) Then mayor = N2
If (N3 > mayor) Then mayor = N3
Console.WriteLine(" le mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module

Mayor de 5 numeros

Module Module1
Dim N1, N2, N3, N4, mayor As Single
Sub Main()
Console.Write(" ingrese Nro 1 ")
N1 = Console.ReadLine
Console.Write(" ingrese Nro 2 ")
N2 = Console.ReadLine
Console.Write(" ingrese Nro 3 ")
N3 = Console.ReadLine
Console.Write(" ingrese Nro 4 ")
N4 = Console.ReadLine
mayor = N1
If (N2 > mayor) Then mayor = N2
If (N3 > mayor) Then mayor = N3
If (N4 > mayor) Then mayor = N4
Console.WriteLine(" le mayor es {0} ", mayor)
Console.ReadLine()
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 11-

End Sub
End Module

Ejemplo de select case convertir un numero a letras

Module Module1
Dim Nro As Integer
Dim numletras As String
Dim SIGNO As String
Sub Main()
Console.Write(" ingrese Nro ")
Nro = Console.ReadLine
If Nro >= 0 Then
SIGNO = "(+) MAS"
Else
SIGNO = "(-) MENOS"
End If
Select Case Math.Abs(Nro)
Case 0 : numletras = "CERO"
Case 1 : numletras = "UNO "
Case 2 : numletras = "DOS "
Case 3 : numletras = "TRES "
Case 4 : numletras = "CUATRO"
Case 5 : numletras = "CINCO"
Case 6 : numletras = "SEIS "
Case 7 : numletras = "SIETE"
Case 8 : numletras = "OCHO"
Case 9 : numletras = "NUEVE"
Case Else : numletras = " ERROR TIENE QUE SOLO UN DIGITO"
End Select
Console.Write(" {0} EN LETRAS ES ", Nro)
Console.ForegroundColor = ConsoleColor.Blue
Console.Write(" {0} ", SIGNO)
Console.ForegroundColor = ConsoleColor.Yellow
Console.Write("{0} ", numletras)
Console.ReadLine()
End Sub
End Module

Se ingresa edad de una persona y de acuerdo a la edad lanza un mensaje


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 12-

' EJEMPLO DE SELECT CASE


Module Module1
' TABLA DE EDADES
' 0 -14 NIÑO
'14-17 ADOLECENTE
' 18-24 JOVEN
'25-35 ADULTO MENOR
'36-50 ADULTO PROMEDIO
'50 -65 ADULTO MAYOR
'65-80 TERCERA EDAD
'80-100 CUARTA EDAD
' >100 LONGEVO
Dim Edad As Integer
Dim Edadletras As String
Sub Main()
Console.Write(" ingrese Edad ")
Edad = Console.ReadLine
Select Case Edad
Case 0 To 14 : Edadletras = "NIÑO"
Case 15 To 17 : Edadletras = "ADOLECENTE "
Case 18 To 24 : Edadletras = "JOVEN"
Case 25 To 35 : Edadletras = "ADULTO MENOR "
Case 36 To 50 : Edadletras = "ADULTO PROMEDIO"
Case 51 To 65 : Edadletras = "ADULTO MAYOR "
Case 66 To 80 : Edadletras = "TERCERA EDAD"
Case 81 To 100 : Edadletras = "CUARTA "
Case Is > 100 : Edadletras = "longevo"
Case Else : Edadletras = " ERROR"
End Select
Console.Write(" {0} EN LETRAS ES ", Edad)
Console.ForegroundColor = ConsoleColor.Yellow
Console.Write("{0} ", Edadletras)
Console.ReadLine()
End Sub
End Module

Ejemplo de while mayor de numeros

' EJEMPLO while mayor de numeros


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 13-

Module Module1
Dim N As Integer
Dim Nro As Single ' variable para almacenar los numeros queleo
Dim mayor As Single = -1000000
Sub Main()
Dim i As Integer = 0 ' contador
Console.Write(" ingrese cntidad de numeros que quiere procesar ")
N = Console.ReadLine
While (i < N)
Console.Write(" ingrese nro {0} ", i)
Nro = Console.ReadLine
If Nro > mayor Then mayor = Nro
i=i+1
End While
Console.WriteLine(" el mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module

El mayor de n numeros con Do while

' EJEMPLO while mayor de numeros


Module Module1
Dim N As Integer
Dim Nro As Single ' variable para almacenar los numeros queleo
Dim mayor As Single = -1000000
Sub Main()
Dim i As Integer = 0 ' contador
Console.Write(" ingrese cntidad de numeros que quiere procesar ")
N = Console.ReadLine
Do
Console.Write(" ingrese nro {0} ", i)
Nro = Console.ReadLine
If Nro > mayor Then mayor = Nro
i=i+1
Loop While (i < N)
Console.WriteLine(" el mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 14-

El mayor de n numeros con for

Module Module1
Dim N As Integer
Dim Nro As Single ' variable para almacenar los numeros queleo
Dim mayor As Single = -1000000
Sub Main()
Dim i As Integer = 0 ' contador
Console.Write(" ingrese cntidad de numeros que quiere procesar ")
N = Console.ReadLine
For i = 1 To N
Console.Write(" ingrese nro {0} ", i)
Nro = Console.ReadLine
If Nro > mayor Then mayor = Nro
Next i
Console.WriteLine(" el mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module

EJERCICIOS
1. valores de una funcion f(x)
2. valores de una funcion f(x,y)
3. sumatorias
4. graficos en modos consola. ejemplo un cuadro un marco, lineas , creacion del
alumno

Calcular los valores de f(x) = x*x de Li= -3 ls =4, incremento 0.5

Module Module1
Sub Main()
Dim x, y, dx, lix, lsx As Single
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 15-

lix = -3
lsx = 4
dx = 0.5
For x = lix To lsx Step dx
y = Math.Pow(x, 2)
Console.WriteLine("{0:F2}{1}{2:F2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module

Grafico de una funcion en modo texto

Module Module1
Sub Main()
Dim x, y, dx, lix, lsx As Single
Dim cx, cy, ex, ey As Integer
lix = -6
lsx = 6
dx = 0.1
cx = 40
cy = 20
ex = 6
ey = -2
For x = lix To lsx Step dx
y = Math.Sin(x)
' Console.WriteLine("{0:F2}{1}{2:F2}", x, vbTab, y)
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module

PRACTICAS DE PROGRAMACION Y METODOS NUMERICOS VIERNES 13 DE


ABRIL DEL 2018 ( cancha de tenis)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 16-

Module Module1
Sub Main()
Dim f, c As Integer
' horizontales
Console.BackgroundColor = 10
Console.Clear()
Console.ForegroundColor = ConsoleColor.Red
Console.BackgroundColor = ConsoleColor.Red
For c = 20 To 60
Console.SetCursorPosition(c, 4)
Console.Write("*")
Console.SetCursorPosition(c, 16)
Console.Write("*")
Next
For c = 30 To 50
Console.SetCursorPosition(c, 10)
Console.Write("*")
Next
For f = 4 To 16
Console.SetCursorPosition(20, f) : Console.Write("*")
Console.SetCursorPosition(30, f) : Console.Write("*")
Console.SetCursorPosition(40, f) : Console.Write("*")
Console.SetCursorPosition(50, f) : Console.Write("*")
Console.SetCursorPosition(60, f) : Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module

Espiral decreciente
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 17-

Module Module1
Sub Main()
Dim vel As Integer = 10
Dim x1, x2, y1, y2, pasox, pasoy As Integer
Console.ForegroundColor = ConsoleColor.Blue
pasox = 6 : pasoy = 2 : x1 = 1 : x2 = 78 : y1 = 1 : y2 = 24
Dim f, c, k As Integer
Dim nvueltas As Integer = 6
For k = 1 To 5
x2 = x2 - pasox
For c = x1 To x2
Console.SetCursorPosition(c, y1)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // derecha
Next
y2 = y2 - pasoy
For f = y1 To y2
Console.SetCursorPosition(x2, f)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // abajo
Next
x1 = x1 + pasox
For c = x2 To x1 Step -1
Console.SetCursorPosition(c, y2)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // izqueirda
Next
y1 = y1 + pasoy
For f = y2 To y1 Step -1
Console.SetCursorPosition(x1, f)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // izqueirda
Next f
Next k
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 18-

Console.ReadLine()
End Sub
End Module

Tarea elaborar una cuadricula

Module Module1
Sub Main()
Dim x1, y1, x2, y2, pasoy, pasox As Integer
x1 = 1 : y1 = 1 : x2 = 73 : y2 = 22 : pasoy = 3 : pasox = 8
Dim fila, col As Integer
Console.BackgroundColor = 4
Console.Clear()
'***********// horizontales
Console.ForegroundColor = 10
Console.BackgroundColor = 10
For fila = y1 To y2 Step pasoy
For col = x1 To x2
Console.SetCursorPosition(col, fila)
Console.Write("*")
Next
Next
'***********verticales
For col = x1 To x2 Step pasox
For fila = y1 To y2
Console.SetCursorPosition(col, fila)
Console.Write("*")
Next
Next
Console.ReadLine()
End Sub
End Module

1. mover un mensaje con las teclas direccionales (resuelto ver libro)


2. en modo formulario ingrese los puntos de un triangulo y dibuje los puntos
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 19-

3. mover un ser e forma aleatoria

Module Module1
Dim cki As ConsoleKeyInfo
Sub Main()
Randomize()
Dim Cadena As String = "HOLA"
Dim cx, cy, x1, y1, x2, y2, pasox, pasoy, rx, ry As Integer
x1 = 2 : y1 = 2 : x2 = 78 : y2 = 24 : pasox = 2 : pasoy = 1
cx = 40 : cy = 12
Console.SetCursorPosition(cx, cy)
Console.Write(Cadena)
Do
Console.ForegroundColor = 0
Console.SetCursorPosition(cx, cy)
Console.Write(Cadena)
rx = -pasox + Int(Rnd() * pasox * 2)
ry = -pasoy + Int(Rnd() * pasoy * 2)
If cx + rx > x1 And cx + rx < x2 Then cx = cx + rx
If cy + ry > y1 And cy + ry < y2 Then cy = cy + ry
Console.ForegroundColor = 14
Console.SetCursorPosition(cx, cy)
Console.Write(Cadena)
System.Threading.Thread.Sleep(100)
Loop While cki.Key <> ConsoleKey.Escape
End Sub
End Module

Ejemplo 8:Generar aleatoriamente en la pantalla numeros de 0 a 15 con los 16 colores

Practicas del martes 17 de abril del 2018


Grafica de una función
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 20-

Module Module1
Sub Main()
Dim x, y, lix, lsx, dx As Single
lix = -3 : lsx = 3 : dx = 0.5
For x = lix To lsx Step dx
y = Math.Pow(x, 2)
Console.WriteLine("{0:F2}{1}{2:f2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module

Module Module1
Sub Main()
Dim x, y, lix, lsx, dx, cx, cy, ex, ey As Single
cx = 40 : cy = 12 : ex = 1 : ey = -1
lix = -3 : lsx = 3 : dx = 0.5
Console.ForegroundColor = 14
'Console.BackgroundColor = 14
For x = lix To lsx Step dx
y = Math.Pow(x, 2)
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module

Graficar varias funciones


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 21-

Module Module1
Sub Main()
Dim x, y, lix, lsx, dx, cx, cy, ex, ey As Single
cx = 40 : cy = 12 : ex = 10 : ey = -10
lix = -3 : lsx = 3 : dx = 0.1
'coordenada x
Console.ForegroundColor = ConsoleColor.Blue
For x = 1 To 78
Console.SetCursorPosition(x, cy)
Console.Write("=")
Next
'coordenada y
Console.ForegroundColor = ConsoleColor.Blue
For y = 1 To 24
Console.SetCursorPosition(cx, y)
Console.Write("=")
Next
For x = lix To lsx Step dx
y = Math.Sin(x)
Console.ForegroundColor = 14
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
y = Math.Cos(x)
Console.ForegroundColor = 10
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
y = 0.5 * x
Console.ForegroundColor = 12
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
'Console.WriteLine("{0:F2}{1}{2:f2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Graficar varias funciones en varios ejes de coordenadas
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 22-

En modo formulario

Public Class Form1


Dim lienzo As Graphics
Dim pluma As Pen
Dim brocha As SolidBrush
Private Sub btnGrafcias_Click(sender As Object, e As EventArgs) Handles
btnGrafcias.Click
lienzo = PictureBox1.CreateGraphics
pluma = New Pen(Brushes.Red, 2)
brocha = New SolidBrush(Color.Green)
Dim x, y, lix, lsx, dx, cx, cy, ex, ey As Single
cx = 300 : cy = 200 : ex = 10 : ey = -10
lix = -30 : lsx = 30 : dx = 0.5
lienzo.DrawLine(Pens.Blue, cx, 0, cx, 400)
lienzo.DrawLine(Pens.Blue, 0, cy, 400, cy)
Dim x1, y1, x2, y2, x3 As Single
For x = lix To lsx Step dx
x1 = x
y1 = Math.Sin(x1)
x2 = x1 + dx
y2 = Math.Sin(x2)
lienzo.DrawLine(pluma, cx + x1 * ex, cy + y1 * ey, cx + x2 * ex, cy + y2 * ey)
' otro graficos
x3 = x1 + dx
y1 = (x1 - 4) * (x1 - 1) * (x1 + 2)
y2 = (x3 - 4) * (x3 - 1) * (x3 + 2)
lienzo.DrawLine(Pens.Yellow, cx + x1 * ex, cy + y1 * ey, cx + x3 * ex, cy + y2 * ey)
Next
End Sub
Private Sub btnBorrar_Click(sender As Object, e As EventArgs) Handles
btnBorrar.Click
ColorDialog1.ShowDialog()
lienzo.Clear(ColorDialog1.Color)
End Sub
End Class
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 23-

Plan de clases para viernes 20 de abril del 2018

Funciones de fecha y hora en visual basic


Otras sentencias. Continue ,exit, return
Menú de conversiones
Sentencia goto y etiquetas
Sentencia anidadas
Funciones f(X,Y) tabla de multiplicar
Funciones predefinidas
Clase console. Sonido y colores en la pantalla
Beep, (int,int)

Dibujar un cuadro, marco


Ejercicio de proceso de datos empresa , universidad , porductos,etc
Graficar funciones en modo grafico ( en formulario pluma pincel y lienzo)
Tarea leer capitulo 1 y 2 y resolver todos los ejercicios
Elabore el plano de su casa visto de parte superior en modo consola y en modo formulario

Elaborar aplicaciones windows forms para las sentencias de control


Aplicaciones de sonido

Clases del viernes 20 de abril del 2018


Funciones de fecha y horas

Module Module1
Sub Main()
Console.WriteLine(" Timestring {0} ", Now)
Console.WriteLine("DATE {0} ", Now.Date)
Console.WriteLine("AÑO {0} ", Now.Year)
Console.WriteLine("MES {0} ", Now.Month)
Console.WriteLine("DIA {0} ", Now.Day)
Console.WriteLine("DIA SEMANA{0} ", Now.DayOfWeek)
Console.WriteLine("DIA AÑO{0} ", Now.DayOfYear)
Console.WriteLine("HORA {0} ", Now.Hour)
Console.WriteLine("MINUTE {0} ", Now.Minute)
Console.WriteLine("SEGUNDO {0} ", Now.Second)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 24-

NUMERO PRIMO
Module Module1
Dim NRO As Integer
Sub Main()
Dim I As Integer
Console.Write("INGRESE UN NRO ENTERO ")
NRO = Console.ReadLine
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
Console.WriteLine(" {0} no es PRIMO", NRO)
GoTo fin
End If
Next
Console.WriteLine(" {0} SI ES PRIMO", NRO)
fin:
Console.ReadLine()
End Sub
End Module

Module Module1
Dim NRO As Integer
Sub Main()
Dim I, control As Integer
Console.Write("INGRESE UN NRO ENTERO ")
NRO = Console.ReadLine
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
control = 1
Exit For
End If
Next
If control = 1 Then
Console.WriteLine(" {0} *** NO ES PRIMO", NRO)
Else
Console.WriteLine(" {0} ES PRIMO ", NRO)
End If

Console.ReadLine()
End Sub
End Module

OTRA FORMA
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 25-

Module Module1
Dim NRO As Integer
Sub Main()
Dim cadena = " ES PRIMO"
Dim I As Integer
Console.Write("INGRESE UN NRO ENTERO ")
NRO = Console.ReadLine
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
cadena = "NO ES PRIMO"
Exit For
End If
Next
Console.WriteLine(" {0} {1}", NRO, cadena)
Console.ReadLine()
End Sub
End Module

Listar los numeros si son primos o no a un numero dado

Module Module1
Dim NRO As Integer ' Para evaluar si ese numero es primo o no
Dim n As Integer '' el numero limite para listado de primos
Sub Main()
Dim cadena = " ES PRIMO"
Dim I, j As Integer
Console.Write("INGRESE UN NRO ENTERO cantidad de nros ")
n = Console.ReadLine
For j = 1 To n
NRO = j
cadena = " ES PRIMO"
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
cadena = "NO ES PRIMO"
Exit For
End If
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 26-

Next
Console.WriteLine(" {0} {1}", NRO, cadena)
Next j
Console.ReadLine()
End Sub
End Module

Module Module1
Dim n As Integer '' el numero limite para listado de primos
Sub Main()
Dim I, j, control As Integer
Console.Write("INGRESE UN NRO ENTERO cantidad de nros ")
n = Console.ReadLine
For j = 1 To n
control = 0
For I = 2 To j - 1
If j Mod I = 0 Then
control = 1
Exit For
End If
Next I
If control = 0 Then Console.Write(" {0} {1}", j, vbTab)
Next j
Console.ReadLine()
End Sub
End Module

Module Module1
Dim li, ls As Integer '' el numero limite para listado de primos
Sub Main()
Dim I, j, control As Integer
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 27-

Console.Write("INGRESE limite inferior de numeros primos ")


li = Console.ReadLine
Console.Write("INGRESE limite superior de numeros primos ")
ls = Console.ReadLine
For j = li To ls
control = 0
For I = 2 To j - 1
If j Mod I = 0 Then
control = 1
Exit For
End If
Next I
If control = 0 Then Console.Write(" {0} {1}", j, vbTab)
Next j
Console.ReadLine()
End Sub
End Module

Module Module1
Dim n As Integer '' el numero limite para listado de primos
Sub Main()
Dim I, j, control, cont As Integer
Console.Write("INGRESE cantidad de numeros que quieres generar ")
n = Console.ReadLine
cont = 1
For j = 1 To 1000
control = 0
For I = 2 To j - 1
If j Mod I = 0 Then
control = 1
Exit For
End If
Next I
If control = 0 Then
Console.Write(" {0} {1}", j, vbTab)
cont = cont + 1
End If
If cont > n Then Exit For
Next j
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 28-

' pregutnta 1. elabore la tabla de multiplicar de 1 al 12 como se meustra

Solución
Module Module1
Sub Main()
Dim x, y, z As Integer
' Console.WriteLine("{0,8}{1,8}{2,8}", "x", "y", "z")
For x = 1 To 12
For y = 1 To 12 Step 1
z=x*y
Console.Write("{0,4}", z)
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module

Animación de tabla de multiplicar

Module Module1
Sub Main()
Dim fila, col, k, pasocol As Integer
pasocol = 4
Do
For k = 1 To 14
Console.ForegroundColor = k
Console.BackgroundColor = 14 - k
For fila = 1 To 12
For col = 1 To 12
Console.SetCursorPosition(col * pasocol, fila)
Console.Write("{0,4}", fila * col)
Next col
Console.WriteLine()
Next fila
System.Threading.Thread.Sleep(200)
Next k
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 29-

Loop
Console.ReadLine()
End Sub
End Module

PRACTICAS DE LABORATORIO DEL VIERNES 20 DE ABRIL DEL 2018


pregutnta 1. mover un mensaje en la pantalla de de izqueirda a derecha

Module Module1
Dim mensaje As String = "HOLA"
Dim borrador As String = " "
Sub Main()
Dim Y1, col, x1, x2 As Integer
Y1 = 2 : x1 = 20 : x2 = 30
Dim color As Integer = 1
Do
If color > 14 Then
color = 1
Else
color = color + 1
End If
Console.ForegroundColor = color
For col = x1 To x2
Console.SetCursorPosition(col, Y1)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(col, Y1)
Console.Write(borrador)
Next
Loop
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 30-

Que camina en un cuadrado


' pregutnta 1. mover un mensaje en la pantalla de de izqueirda a derechara

Module Module1
Dim mensaje As String = "HOLA"
Dim borrador As String = " "
Sub Main()
Dim col, fila, x1, x2, y1, y2 As Integer
y1 = 10 : y2 = 20 : x1 = 20 : x2 = 50
Dim color As Integer = 1
Do
If color > 14 Then
color = 1
Else
color = color + 1
End If
Console.ForegroundColor = color
For col = x1 To x2 ' derecha
Console.SetCursorPosition(col, Y1)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(col, Y1)
Console.Write(borrador)
Next
For fila = y1 To y2 ' abajo
Console.SetCursorPosition(x2, fila)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(x2, fila)
Console.Write(borrador)
Next
For col = x2 To x1 Step -1 ' izquierda
Console.SetCursorPosition(col, y2)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(col, y2)
Console.Write(borrador)
Next
For fila = y2 To y1 Step -1 ' arriba
Console.SetCursorPosition(x1, fila)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(x1, fila)
Console.Write(borrador)
Next
Loop
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 31-

Marco

Module Module1
Dim mensaje As String = "HOLA"
Dim borrador As String = " "

Sub Main()
Dim col, fila, x1, x2, y1, y2 As Integer
y1 = 10 : y2 = 20 : x1 = 20 : x2 = 50
Console.ForegroundColor = 12
For col = x1 To x2 ' derecha
Console.SetCursorPosition(col, y1) : Console.Write("*")
Console.SetCursorPosition(col, y2) : Console.Write("*")
Next
For fila = y1 To y2 ' abajo
Console.SetCursorPosition(x1, fila) : Console.Write("*")
Console.SetCursorPosition(x2, fila) : Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module
Cuadro

' cuadro
Module Module1
Sub Main()
Dim x1, y1, ancho, alto, col, k As Integer
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 32-

x1 = 20 : y1 = 2
ancho = 40
alto = 20
Dim pasoalto As Integer = 1
Dim pasoancho As Integer = 1
For k = 1 To 10
Console.ForegroundColor = 15 - k
Console.BackgroundColor = 15 - k
For fila = 0 To alto
For col = 0 To ancho
Console.SetCursorPosition(col + x1, fila + y1)
Console.Write("*")
Next
Next
alto = alto - pasoalto * 2
ancho = ancho - pasoancho * 2
x1 = x1 + pasoancho
y1 = y1 + pasoalto
Next
Console.ReadLine()
End Sub
End Module

Ejemplo de sonido

Module Module1
Dim frec, durac, i As Integer
Sub Main()
For i = 1 To 10
frec = 10 + Int(Rnd() + 500)
durac = 10 + Int(Rnd() + 200)
Console.Beep(frec, durac)
Next
Console.ReadLine()
End Sub
End Module

Grafica de una funcion

Public Class Form1


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 33-

Dim lienzo As Graphics


Dim pluma As Pen
Dim brocha As SolidBrush
Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles
btnGraficar.Click
lienzo = PictureBox1.CreateGraphics
pluma = New Pen(Brushes.Red, 4)
brocha = New SolidBrush(Color.Green)
Dim x, y, cx, cy, ex, ey As Single
cx = 150 : cy = 150 : ex = 50 : ey = 50
Dim x1, y1, x2, y2 As Single
For x = -10 To 10 Step 0.1
y = Math.Sin(x)
x1 = x
y1 = y
x2 = x1 + 0.1
y2 = Math.Sin(x + 0.1)
lienzo.DrawLine(pluma, cx + x1 * ex, cy + y1 * ey, cx + x2 * ex, cy + y2 * ey)
Next
End Sub
End Class

Practica del martes 24 base de datos, menus y windows form

Module Module1
Sub Main()
Dim i = 1, suma = 0, n As Integer = 3
Console.Write("ingrese cantidad de numeros a sumar ")
n = Console.ReadLine()
While (i <= n)
Console.Write("{0} ", i)
suma += i
i=i+1
End While
Console.WriteLine(" la suma con while es {0} ", suma)
suma = 0
i=1
Do
Console.Write("{0} ", i)
suma += i
i=i+1
Loop While (i <= n)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 34-

Console.WriteLine(" suma con do loop while{0} ", suma)


suma = 0
For i = 1 To n Step 1
Console.Write("{0} ", i)
suma = suma + i
Next
Console.WriteLine(" suma con for {0} ", suma)
Console.ReadLine()
End Sub
End Module

CLASES DEL VIERNES 4 DE MAYO DEL 2018


FUNCIONES

Module Module1
Function SUMA(N1 As Single, _
N2 As Single) As Single
Dim S As Single
S = N1 + N2
'Return S
SUMA = S
End Function
Sub Main()
Dim A, B, RES As Single
A=2:B=3
RES = SUMA(A, B)
Console.WriteLine("LA SUMA ES {0}", RES)
Console.ReadLine()
End Sub
End Module

Factorial de un numero

Module Module1
Sub MAIN()
Dim N As Integer = 100
Console.Write("ingrese n 1.. 20")
N = Console.ReadLine
Dim I As Integer ' CONTADOR '
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 35-

Dim F As Double = 1
For I = 1 To N
F=F*I
Next
Console.WriteLine(" el factorial es {0} ", F)
Console.ReadLine()
End Sub
End Module

Module Module1
Function factorial(n As Integer) As Integer
Dim I As Integer ' CONTADOR '
Dim F As Double = 1
For I = 1 To n
F=F*I
Next
Return F
End Function
Sub MAIN()
Dim Nro, Fac As Integer
Console.Write("ingrese n 1.. 20 ")
Nro = Console.ReadLine
Fac = factorial(Nro)
Console.WriteLine(" el factorial es {0} ", Fac)
Console.ReadLine()
End Sub
End Module

Module Module1
Function factorial(n As Integer) As Integer
Dim I As Integer ' CONTADOR '
Dim F As Double = 1
For I = 1 To n
F=F*I
Next
Return F
End Function
Sub MAIN()
' 2C3=
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 36-

Dim Nro, Fac, combi, r As Integer


Console.Write("ingrese n ")
Nro = Console.ReadLine
Console.Write("ingrese r ")
r = Console.ReadLine
combi = factorial(Nro) / (factorial(r) * factorial(Nro - r))
Console.WriteLine(" el factorial es {0} ", combi)
Console.ReadLine()
End Sub
End Module

Potencia de un numero

Module Module1
Sub MAIN()
Dim base As Single = 8
Dim exponente As Single = 1 / 3
Dim poten As Single
poten = Math.Pow(base, exponente)
Console.WriteLine(" {0} elevado a {1} es = {2} ", base, exponente, poten)
Console.ReadLine()
End Sub
End Module

Module Module1
Function Potencia(base As Single, exponente As Single) As Single
Return Math.Pow(base, exponente)
End Function
Sub MAIN()
Dim base As Single = 8
Dim exponente As Single = 1 / 3
Dim poten As Single
poten = Potencia(base, exponente)
Console.WriteLine(" {0} elevado a {1} es = {2} ", base, exponente, poten)
Console.ReadLine()
End Sub
End Modul

Module Module1
Function Potencia(base As Single, n As Integer) As Single
Dim i As Integer
Dim producto As Single = base
For i = 1 To n - 1
producto = producto * base
Next
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 37-

Return producto
End Function
Sub MAIN()
Dim base As Single = 2
Dim exponente As Integer = 3
Dim poten As Single
poten = Potencia(base, exponente)
Console.WriteLine(" {0} elevado a {1} es = {2} ", base, exponente, poten)
Console.ReadLine()
End Sub
End Module

Calcular la formula
' X3 X5 X7
'Sen(x) = x- ---- + ---- - --- + ...
' 3! 5! 7!

Module Module1
Sub MAIN()
Dim x As Single = Math.PI / 4
Dim suma As Single = 0
Dim n As Integer = 10
Dim i As Integer
Dim signo As Integer = 1
For i = 1 To n Step 2
suma = suma + signo * Potencia(x, i) / factorial(i)
signo = signo * (-1)
Next
Console.WriteLine(" el seno de {0} con {1} terminos es {2} ", x, n, suma)
Console.ReadLine()
End Sub
End Module

Module Module1
Function f(x As Single) As Single
' Return x * x
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 38-

f = Math.Pow(x, 2)
End Function
Sub MAIN()
Dim x, y As Single
x=2
y = f(x)
Console.WriteLine("{0} {1} {2} ", x, vbTab, y)
Console.ReadLine()
End Sub
End Module

Module Module1
Function f(x As Single) As Single
' Return x * x
f = Math.Pow(x, 2)
End Function
Sub MAIN()
Dim x, y As Single
x=2
y = f(x)
For x = -3 To 3 Step 0.5
y = f(x)
Console.WriteLine("{0:f2} {1} {2:F2} ", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module

Module Module1
Function f(x As Single, Y As Single) As Single
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 39-

' Return x * x
f = Math.Pow(x, 2) + Math.Pow(Y, 2)
End Function
Sub MAIN()
Dim x, y, z As Single
'x = 2
'z = f(x, y)
'Console.WriteLine("{0} {1} {2}", x, y, z)
For y = -2 To 2 Step 1
Console.WriteLine()
For x = -2 To 2 Step 1
z = f(x, y)
Console.Write("{0:f2} {1} ", z, vbTab)
Next x
Next y
Console.ReadLine()
End Sub
End Module

FUNCIONES DE TIPO SUB


Dibujar un cuadro

Module Module1
Sub MAIN()
Dim cx, cy, ancho, alto, fila, col As Integer
cx = 10 : cy = 2
ancho = 20 : alto = 10
Console.ForegroundColor = 10
Console.BackgroundColor = 4
For fila = 0 To alto
For col = 0 To ancho
Console.SetCursorPosition(cx + col, cy + fila)
Console.Write("*")
Next
Next
Console.ReadLine()
End Sub
End Module

Con funciones
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 40-

Module Module1
Sub Cuadro(cx As Integer, cy As Integer, ancho As Integer, alto As Integer)
Dim fila, col As Integer
For fila = 0 To alto
For col = 0 To ancho
Console.SetCursorPosition(cx + col, cy + fila)
Console.Write("*")
Next
Next
End Sub
Sub MAIN()
Console.ForegroundColor = 10
Console.BackgroundColor = 4
Cuadro(10, 2, 20, 12)
Console.ReadLine()
End Sub
End Module

Practicas del Viernes 04 de mayo del 2018

Module Module1
Sub main()
Dim n1, n2, suma As Single
Console.Write(" ingrese n1 :")
n1 = Console.ReadLine
Console.Write(" ingrese n2 : ")
n2 = Console.ReadLine
suma = n1 + n2
Console.WriteLine(" la suma es {0} ", suma)
Console.ReadLine()
End Sub
End Module

En Modo formulario
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 41-

Public Class Form1


Dim n1, n2, res As Single
Private Sub sumar(sender As Object, e As EventArgs) Handles btnSumar.Click
n1 = txtNro1.Text
n2 = txtNro2.Text
res = n1 + n2
txtRes.Text = res
End Sub
Private Sub btRestar_Click(sender As Object, e As EventArgs) Handles
btRestar.Click
n1 = txtNro1.Text
n2 = txtNro2.Text
Res = n1 - n2
txtRes.Text = Res
End Sub

Private Sub btnMultiplicar_Click(sender As Object, e As EventArgs) Handles


btnMultiplicar.Click
n1 = txtNro1.Text
n2 = txtNro2.Text
res = n1 * n2
txtRes.Text = Res
End Sub
End Class

Forma corta

Public Class Form1


Dim n1, n2, res As Single
Private Sub operacion(sender As Object, e As EventArgs) Handles btnSumar.Click,
btRestar.Click, btnMultiplicar.Click
n1 = txtNro1.Text
n2 = txtNro2.Text
Select Case sender.tag
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 42-

Case 1 : res = n1 + n2
Case 2 : res = n1 - n2
Case 3 : res = n1 * n2
End Select
txtRes.Text = res
End Sub
End Class

graficos

Código
Public Class Form1
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 43-

Dim Grafico As Graphics


Dim pluma As Pen
Dim brocha As SolidBrush
Dim MiFuente As New Font("Verdana", 24, FontStyle.Bold)
Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles
btnGraficar.Click
brocha.Color = Color.Yellow
Grafico.DrawString("GRAFICOS,ARGB TRANSPARENCIAS", MiFuente, brocha,
20, 120)
brocha.Color = Color.FromArgb(200, 0, 0, 255)
Grafico.FillEllipse(brocha, 100, 80, 300, 120)
Grafico.DrawEllipse(pluma, 100, 80, 300, 120)
brocha.Color = Color.FromArgb(150, 0, 255, 0) ' 255ES OPCACO
Grafico.FillEllipse(brocha, 200, 40, 200, 180)
brocha.Color = Color.FromArgb(100, 255, 200, 100) ' 255ES OPCACO
Grafico.FillRectangle(brocha, 200, 20, 180, 250)
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Grafico = PictureBox1.CreateGraphics
pluma = New Pen(Brushes.Red, 4)
brocha = New SolidBrush(Color.Green)
End Sub

Private Sub btnBorrar_Click(sender As Object, e As EventArgs) Handles


btnBorrar.Click
Grafico.Clear(Color.Black)
End Sub

Private Sub btnPoligono_Click(sender As Object, e As EventArgs) Handles


btnPoligono.Click
Dim radio As Integer = 100
Dim cx As Integer = 200
Dim cy As Integer = 200
Dim nlados As Integer = 5
Dim alfa As Single = 0
Dim dalfa As Single = 2 * Math.PI / nlados
Dim X1, Y1, x2, y2 As Single
Do
X1 = cx + radio * Math.Cos(alfa)
Y1 = cy + radio * Math.Sin(alfa)
alfa = alfa + dalfa
x2 = cx + radio * Math.Cos(alfa)
y2 = cy + radio * Math.Sin(alfa)
Grafico.DrawLine(pluma, X1, Y1, x2, y2)
Loop Until alfa > Math.PI * 2
End Sub

Private Sub btnFoto_Click(sender As Object, e As EventArgs) Handles btnFoto.Click


OpenFileDialog1.ShowDialog()
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 44-

PictureBox1.Load(OpenFileDialog1.FileName)
End Sub
End Class

Otro ejercicio colores y transparencias

1. MODO FORMUALRIO SUMAR NUMEROS


2. GRAFICOS CIRCULO RGB TRANSPARENCIAS,
3. POLIGONOS LETRAS ,ETC

PRUEBE La funciones
Grafico.DrawClosedCurve()
Grafico.DrawPolygon()
Grafico.FillClosedCurve()
Grafico.DrawClosedCurve()
Dibuje polígonos regulares

RESUMEN
pag fecha TIPO
1 23-Mar practica
3 VIERNES 06 DE ABRIL DEL 2018 TEORIA
PRACTICA
Practicas del dia martes 10 de abril del 2018
7 S
9 VIERNES 13 DE ABRIL TEORIA
15 VIERNES 13 DE ABRIL PRACTICA
19 MARTES 17 DE ABRIL PRACTICA
23 VIERNES 20 DE ABRIL TEORIA
MARTRES 24 DE ABRIL PRACTICA
1 1MAYO DEL ABRIL FERIADO
FUNCIONE
24 VIERNES 4 DE MAYO TEORIA S
PRACTICA
30
VIERNES 4 DE MAYO S

CLASES DEL VIERNES 11 DE MAYO DEL 2018

Explicacion de la funcion suma

Module Module1
Sub Main()
Dim NRO1, NRO2, RES As Single
NRO1 = 2 : NRO2 = 3
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 45-

RES = SUMA(NRO1, NRO2)


Console.WriteLine("{0} + {1} = {2} ", NRO1, NRO2, RES)
Console.ReadLine()
End Sub
End Module

Module Module2
Function SUMA(N1 As Single, N2 As Single) As Single
Dim S1 As Single
S1 = N1 + N2
Return S1
'SUMA = S1
End Function
End Module

Pase de parametros por referencia

Module Module1
Sub INGRESAR(ByRef A As Single, ByRef B As Single)
Console.Write(" INGRESE NRO 1 ")
A = Console.ReadLine
Console.Write(" INGRESE NRO 2 ")
B = Console.ReadLine
End Sub
Function SUMA(N1 As Single, N2 As Single) As Single
Return N1 + N2
End Function
Sub main()
Dim RES As Single
Dim x As Single = 10
Dim y As Single = 50
INGRESAR(x, y)
RES = SUMA(x, y)
Console.WriteLine("x= {0} y ={1} SUMA {2} ", x, y, RES)
Console.ReadLine()
End Sub
End Module

PRACTICAS DEL VIERNES 11 DE MAYO DEL 2018


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 46-

Public Class Form1


Dim GRAFICO As Graphics
Dim pluma As Pen
Dim brocha As SolidBrush
Dim x, y, alto, teta, w, paro, rama, grosor As Single
Sub Arbol(ByVal x As Single, ByVal y As Single, ByVal alto As Single, _
ByVal teta As Single, ByVal w As Single, paro As Single, rama As Single)
Dim x1 As Single, y1 As Single, t1 As Single
If (alto > paro) Then '//condición de paro
x1 = x + alto * Math.Cos(teta)
y1 = y + alto * Math.Sin(teta)
GRAFICO.DrawLine(pluma, x, y, x1, y1)
't1 = alto / 1.8 '1.7
t1 = alto / rama
Arbol(x1, y1, t1, teta - w, w, paro, rama)
Arbol(x1, y1, t1, teta, w, paro, rama)
Arbol(x1, y1, t1, teta + w, w, paro, rama)
End If
End Sub

Private Sub BTNaRBOL_Click(sender As Object, e As EventArgs) Handles


BTNaRBOL.Click
Arbol(x, y, alto, 3 * Math.PI / 2.0, 0.6, 20, 1.4)
End Sub
Private Sub btnBosque_Click(sender As Object, e As EventArgs) Handles
btnBosque.Click
Randomize()
Dim fila, narboles, rojo, verde, azul, grosor As Integer
GRAFICO.Clear(brocha.Color)
narboles = 50 + Int(Rnd() * 200)
For fila = 1 To narboles
grosor = 1 + Int(Rnd() * 10)
pluma.Width = grosor
rojo = 4 + Int(Rnd() * 250)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 47-

verde = 4 + Int(Rnd() * 250)


azul = 4 + Int(Rnd() * 250)
pluma.Color = Color.FromArgb(rojo, verde, azul)
x = 50 + Int(Rnd() * 500)
y = 50 + Int(Rnd() * 500)
alto = 20 + Int(Rnd() * 200)
teta = 3 * Math.PI / 2.0
w = (Rnd() * 1000) / 1000
paro = 10 + Int(Rnd() * 100)
rama = 1.3 + (Rnd() * 30) / 100
Arbol(x, y, alto, teta, w, paro, rama)
Next
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


GRAFICO = PictureBox1.CreateGraphics
pluma = New Pen(Brushes.Green, 4)
pluma.Color = Color.Green
brocha = New SolidBrush(Color.Aqua)
brocha.Color = Color.FromArgb(255, 255, 123, 112)
grosor = 4
HSParo.Minimum = 10 : HSParo.Maximum = 80 : HSParo.Value = 20 :
txtparo.Text = HSParo.Value
HSRama.Minimum = 0
HSRama.Maximum = 200
pluma.Width = grosor : x = 200 : y = 300 : alto = 100
teta = 3 * Math.PI / 2.0 : w = 0.6 : paro = 20 : rama = 1.4
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub HSX_Scroll(sender As Object, e As ScrollEventArgs) Handles


HSX.Scroll
GRAFICO.Clear(brocha.Color)
x = HSX.Value
txtX.Text = x
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub HSy_Scroll(sender As Object, e As ScrollEventArgs) Handles HSy.Scroll


GRAFICO.Clear(brocha.Color)
y = HSy.Value
TXTy.Text = y
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub HSalto_Scroll(sender As Object, e As ScrollEventArgs) Handles


HSalto.Scroll
GRAFICO.Clear(brocha.Color)
alto = HSalto.Value
txtalto.Text = alto
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 48-

Arbol(x, y, alto, teta, w, paro, rama)


End Sub

Private Sub HSIncli_Scroll(sender As Object, e As ScrollEventArgs) Handles


HSIncli.Scroll
GRAFICO.Clear(brocha.Color)
teta = HSIncli.Value / 100
txtincli.Text = alto
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub HSAbertura_Scroll(sender As Object, e As ScrollEventArgs) Handles


HSAbertura.Scroll
GRAFICO.Clear(brocha.Color)
w = HSAbertura.Value / 100
txtAbertura.Text = alto
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub btnfondo_Click(sender As Object, e As EventArgs) Handles


btnfondo.Click
ColorDialog1.ShowDialog()
brocha.Color = ColorDialog1.Color
End Sub
Private Sub HSgrosor_Scroll(sender As Object, e As ScrollEventArgs) Handles
HSgrosor.Scroll
GRAFICO.Clear(brocha.Color)
grosor = HSgrosor.Value / 10
txtgrosor.Text = grosor
pluma.Width = grosor
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub HSValor_Scroll(sender As Object, e As ScrollEventArgs) Handles


HSParo.Scroll
GRAFICO.Clear(brocha.Color)
paro = HSParo.Value
txtparo.Text = paro
Arbol(x, y, alto, teta, w, paro, rama)
End Sub
Private Sub HSdx_Scroll(sender As Object, e As ScrollEventArgs) Handles
HSRama.Scroll
GRAFICO.Clear(brocha.Color)
rama = 1.2 + HSRama.Value / 1000
txtRama.Text = rama
Arbol(x, y, alto, teta, w, paro, rama)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


BtnColorArbol.Click
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 49-

ColorDialog1.ShowDialog()
pluma.Color = ColorDialog1.Color
End Sub

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles


btnAnimar.Click
Timer1.Interval = 100
Timer1.Start()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


btnParar.Click
Timer1.Stop()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


GRAFICO.Clear(brocha.Color)
If alto < 100 Then
alto = alto + 1
Else
alto = 20
End If
txtalto.Text = alto
HSalto.Value = alto
Arbol(x, y, alto, teta, w, paro, rama)
End Sub
End Class

METODOS NUMERICOS GRAFICAR INTEGRALES, VOLUMNES Y


TRAYECTORIAS ,

Public Class Form1


Dim n As Integer
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 50-

Dim a, b, area As Single


Dim Grafico As Graphics
Dim lapiz As Pen
Dim brocha As SolidBrush
Dim Cx As Integer = 20
Dim Cy As Integer = 200
Dim Ex As Integer = 50
Dim Ey As Integer = -50

Private Sub btnTrapecial_Click(sender As Object, e As EventArgs) Handles


btnTrapecial.Click
a = txtA.Text
b = txtB.Text
n = txtN.Text
area = Trapecial(a, b, n)
txtAREA.Text = area
End Sub

Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles


btnGraficar.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
dx = (b - a) / n
Grafico = PictureBox1.CreateGraphics
lapiz = New Pen(Brushes.Blue, 1)
brocha = New SolidBrush(Color.Green)
Grafico.DrawLine(lapiz, Cx, 0, Cx, PictureBox1.Height)
Grafico.DrawLine(lapiz, 0, Cy, PictureBox1.Width, Cy)
lapiz.Color = Color.Red
lapiz.Width = 2
For x = a To b Step dx
x1 = x
y1 = f(x1)
x2 = x1 + dx
y2 = f(x2)
Grafico.DrawLine(lapiz, Cx + x1 * Ex, Cy + y1 * Ey, Cx + x2 * Ex, Cy + y2 * Ey)
Next
End Sub
End Class

Module Module1
Function f(ByVal x As Single) As Single
Return x * x
End Function
Function Trapecial(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap, dx, x, y1, y2 As Single
dx = (b - a) / n
For x = a To b - dx Step dx
y1 = f(x)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 51-

y2 = f(x + dx)
ap = (y1 + y2) / 2 * dx
at = at + ap
Next
Return at
End Function
End Module

Clases del martes 15 de mayo del 2018

Public Class Form1


Dim GRAFICO As Graphics
Dim pluma As Pen
Dim brocha As SolidBrush
Dim x, y, alto, teta, w, paro, rama, grosor As Single
Dim fondo As Color

Private Sub BtnGraficar_Click(sender As Object, e As EventArgs) Handles


BtnGraficar.Click
GRAFICO.Clear(fondo)
pluma.Color = Color.Lime
pluma.Width = 5
Arbol(x, y, alto, teta, w, paro, rama)

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GRAFICO = PictureBox1.CreateGraphics
pluma = New Pen(Brushes.Green, 4)
brocha = New SolidBrush(Color.Aqua) : grosor = 4
pluma.Width = grosor : x = 100 : y = 300 : alto = 100
teta = 3 * Math.PI / 2.0 : w = 0.6 : paro = 20 : rama = 1.4
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 52-

Arbol(x, y, alto, teta, w, paro, rama)


End Sub
Private Sub HSx_Scroll(sender As Object, e As ScrollEventArgs) Handles HSx.Scroll
GRAFICO.Clear(Color.Black)
x = HSx.Value
TXTx.Text = x
Arbol(x, y, alto, teta, w, paro, rama)
End Sub
Private Sub TXTx_KeyPress(sender As Object, e As KeyPressEventArgs) Handles
TXTx.KeyPress
GRAFICO.Clear(Color.Black)
x = Val(TXTx.Text)
HSx.Value = x
Arbol(x, y, alto, teta, w, paro, rama)
End Sub
Sub Arbol(ByVal x As Single, ByVal y As Single, ByVal alto As Single, _
ByVal teta As Single, ByVal w As Single, paro As Single, rama As Single)
Dim x1 As Single, y1 As Single, t1 As Single
If (alto > paro) Then '//condición de paro
If alto > 80 Then
pluma.Color = Color.Chocolate
Else
pluma.Color = Color.Lime
End If
x1 = x + alto * Math.Cos(teta) : y1 = y + alto * Math.Sin(teta)
GRAFICO.DrawLine(pluma, x, y, x1, y1) : t1 = alto / rama
Arbol(x1, y1, t1, teta - w, w, paro, rama)
Arbol(x1, y1, t1, teta, w, paro, rama)
Arbol(x1, y1, t1, teta + w, w, paro, rama)
End If
End Sub

Private Sub BackgroundWorker1_DoWork(sender As Object, e As


System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
End Sub

Private Sub btnColor_Click(sender As Object, e As EventArgs) Handles


btnColor.Click
ColorDialog1.ShowDialog()
fondo = ColorDialog1.Color
GRAFICO.Clear(fondo)
End Sub

Private Sub btnAnimar_Click(sender As Object, e As EventArgs) Handles


btnAnimar.Click
Timer1.Interval = 50
Timer1.Start()
End Sub
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 53-

Private Sub btnParar_Click(sender As Object, e As EventArgs) Handles


btnParar.Click
Timer1.Stop()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


If alto < 120 Then
alto = alto + 1
Else
alto = 20
End If
GRAFICO.Clear(Color.Black)
Arbol(x, y, alto, teta, w, paro, rama)
End Sub
End Class

CLASES DEL VIERNES 18 DE MAYO DEL 2018

Public Class Form1


Dim n As Integer = 4
Dim a As Single = 0
Dim b As Single = 2
Dim area As Single
Dim Grafico As Graphics
Dim lapiz As Pen
Dim brocha As SolidBrush
Dim Cx As Integer = 20
Dim Cy As Integer = 300
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 54-

Dim Ex As Integer = 80
Dim Ey As Integer = -50
Dim MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Sub ObtenerDatos()
a = txtA.Text
b = txtB.Text
n = txtN.Text
End Sub
Sub PrepararGrafico()
brocha.Color = Color.Yellow
Grafico.DrawString(CStr(a), MiFuente, brocha, Cx + a * Ex, Cy)
Grafico.DrawString(CStr(b), MiFuente, brocha, Cx + b * Ex, Cy)
lapiz.Color = Color.Brown
lapiz.Width = 1
Grafico.DrawLine(lapiz, Cx, 0, Cx, PictureBox1.Height)
Grafico.DrawLine(lapiz, 0, Cy, PictureBox1.Width, Cy)
lapiz.Color = Color.Red
lapiz.Width = 2
brocha.Color = Color.Green
End Sub
Private Sub btnTrapecial_Click(sender As Object, e As EventArgs) Handles
btnTrapecial.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
area = Trapecial(a, b, n)
txtAREA.Text = area
PrepararGrafico()
dx = (b - a) / n
For x = a To b - dx Step dx
x1 = x
y1 = f(x1)
x2 = x1 + dx
y2 = f(x2)
' grafico de los trapecios
Dim np As Integer = 4
Dim VX(4) As Single
Dim VY(4) As Single
VX(0) = x1 : VY(0) = y1
VX(1) = x2 : VY(1) = y2
VX(2) = x2 : VY(2) = 0
VX(3) = x1 : VY(3) = 0
GraficarPoligono(Cx, Cy, VX, VY, Ex, Ey, np)
Next
brocha.Color = Color.Azure
Grafico.DrawString("METODO TRAPECIAL", MiFuente, brocha, 10, 10)

End Sub
Sub ObtenerDatosGrafico()
Cx = Val(txtCx.Text)
Cy = Val(txtCy.Text)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 55-

Ex = Val(txtEx.Text)
Ey = Val(txtEy.Text)
End Sub

Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles


btnGraficar.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
PrepararGrafico()
lapiz.Color = Color.Blue
lapiz.Width = 2
dx = 0.001
For x = a To b Step dx
x1 = x
y1 = f(x1)
x2 = x1 + dx
y2 = f(x2)
Grafico.DrawLine(lapiz, Cx + x1 * Ex, Cy + y1 * Ey, Cx + x2 * Ex, Cy + y2 * Ey)
Next
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Grafico = PictureBox1.CreateGraphics
lapiz = New Pen(Brushes.Blue, 1)
brocha = New SolidBrush(Color.Green)
txtCx.Text = Cx
txtCy.Text = Cy
txtEx.Text = Ex
txtEy.Text = Ey
txtA.Text = a
txtB.Text = b
txtN.Text = n
End Sub
Sub GraficarPoligono(cx As Integer, cy As Integer, X() As Single, Y() As Single, _
ex As Single, ey As Single, np As Integer)
Dim fila As Integer
Dim Puntos(np - 1) As Point
For fila = 0 To np - 1
Puntos(fila).X = cx + CInt(X(fila) * ex)
Puntos(fila).Y = cy + CInt(Y(fila) * ey)
Next
Grafico.FillPolygon(brocha, Puntos)
Grafico.DrawPolygon(lapiz, Puntos)
End Sub

Private Sub btnBorrar_Click(sender As Object, e As EventArgs) Handles


btnBorrar.Click
Grafico.Clear(Color.Black)
End Sub
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 56-

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


btnRCirc.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
area = circunscritos(a, b, n)
txtAREA.Text = area
PrepararGrafico()
dx = (b - a) / n
For x = a + dx To b Step dx
x1 = x - dx
y1 = f(x)
x2 = x
y2 = f(x)
' grafico de los rectangulos
Dim np As Integer = 4
Dim VX(4) As Single
Dim VY(4) As Single
VX(0) = x1 : VY(0) = y1
VX(1) = x2 : VY(1) = y2
VX(2) = x2 : VY(2) = 0
VX(3) = x1 : VY(3) = 0
GraficarPoligono(Cx, Cy, VX, VY, Ex, Ey, np)
Next
brocha.Color = Color.Beige
Grafico.DrawString("METODO RECTANGULOS INSCRITOS", MiFuente, brocha,
10, 10)
End Sub

Private Sub btnInscritos_Click(sender As Object, e As EventArgs) Handles


btnInscritos.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
area = inscritos(a, b, n)
txtAREA.Text = area
PrepararGrafico()
dx = (b - a) / n
For x = a To b - dx Step dx
x1 = x
y1 = f(x)
x2 = x + dx
y2 = f(x)
' grafico de los rectangulos
Dim np As Integer = 4
Dim VX(4) As Single
Dim VY(4) As Single
VX(0) = x1 : VY(0) = y1
VX(1) = x2 : VY(1) = y2
VX(2) = x2 : VY(2) = 0
VX(3) = x1 : VY(3) = 0
GraficarPoligono(Cx, Cy, VX, VY, Ex, Ey, np)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 57-

Next
brocha.Color = Color.Indigo
Grafico.DrawString("METODO RECTANGULOS CIRCUNSCRITOS", MiFuente,
brocha, 10, 10)
End Sub

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles


btnPuntoMedio.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
area = PuntoMedio(a, b, n)
txtAREA.Text = area
PrepararGrafico()
dx = (b - a) / n
For x = a + dx / 2 To b Step dx
x1 = x - dx / 2
y1 = f(x)
x2 = x + dx / 2
y2 = f(x)
' grafico de los rectangulos
Dim np As Integer = 4
Dim VX(4) As Single
Dim VY(4) As Single
VX(0) = x1 : VY(0) = y1
VX(1) = x2 : VY(1) = y2
VX(2) = x2 : VY(2) = 0
VX(3) = x1 : VY(3) = 0
GraficarPoligono(Cx, Cy, VX, VY, Ex, Ey, np)
Next
brocha.Color = Color.Beige
Grafico.DrawString("METODO RECTANGULOS PUNTO MEDIO", MiFuente,
brocha, 10, 10)
End Sub

Private Sub btnSimpson_Click(sender As Object, e As EventArgs) Handles


btnSimpson.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
area = Trapecial(a, b, n)
txtAREA.Text = area
PrepararGrafico()
dx = (b - a) / n
For x = a To b - dx Step dx
x1 = x
y1 = f(x1)
x2 = x1 + dx
y2 = f(x2)
Grafico.DrawLine(lapiz, Cx + x1 * Ex, Cy + y1 * Ey, Cx + x2 * Ex, Cy + y2 * Ey)
Next
brocha.Color = Color.Coral
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 58-

Grafico.DrawString("METODO simpson", MiFuente, brocha, 10, 10)


End Sub
End Class

Module Module1
Function f(ByVal x As Single) As Single
Return x * x
' Return Math.Sin(x)
End Function
Function circunscritos(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap As Single, dx As Single, x As Single, y As Single
dx = (b - a) / n
For x = a + dx To b Step dx
y = f(x)
ap = dx * y
at = at + ap
Next
Return at
End Function
Function inscritos(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap As Single, dx As Single, x As Single, y As Single
dx = (b - a) / n
For x = a To b - dx Step dx
y = f(x)
ap = dx * y
at = at + ap
Next
Return at
End Function

Function PuntoMedio(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As


Single
Dim at As Single = 0, ap As Single, dx As Single, x As Single, y As Single
dx = (b - a) / n
For x = a + dx / 2 To b Step dx
y = f(x)
ap = dx * y
at = at + ap
Next
Return at
End Function

Function Trapecial(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As


Single
Dim at As Single = 0, ap, dx, x, y1, y2 As Single
dx = (b - a) / n
For x = a To b - dx Step dx
y1 = f(x)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 59-

y2 = f(x + dx)
ap = (y1 + y2) / 2 * dx
at = at + ap
Next
Return at
End Function
Function Simpson(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap, h, x As Single
h = (b - a) / n
For x = a To b - h Step 2 * h
ap = h / 3 * (f(x) + 4 * f(x + h) + f(x + 2 * h))
at = at + ap
Next
Return at
End Function
End Module

Practicas del Viernes 25 de mayo del 2018

Valores de una función

Module Module1
Function f(x As Single) As Single
Return (x - 2) * (x + 1)

End Function
Sub Main()
Dim x, y, dx, li, ls As Single
li = -4 : ls = 4
dx = 0.5
For x = li To ls Step dx
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 60-

y = f(x)
Console.WriteLine("{0:f2}{1} {2:f2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module

Practica caliicada de programacion y metodos numericos


Viernes 1 de junio del 2018

Exaemn 8 de junio hasta funciones


Para la practica calificada resolver los trabajos
Presentación de los trabajos martes 15 de junio del 2018 siempre en cuando se
den plazo , todos presentar martes 5 de junio , y viernes 8 de junio y con
posibilidades de presentar el viernes 15 de junio como recuperación. Omojera.
Clases de viernes 1 de juni0
Trabajo de funciones y métodos numéricos con
Realizar un trbajo en grupos de hasta 5 alumnos de una aplicación en Windows
Forma ( también en modo consola) métodos de funciones y métodos numéricos
con 4 opciones
1. Recursivida analizar el árbol que se hizo y agregar algún aporte y otros
ejercicios de recursividad, fractales , torres de hanoi
2. FRACTALES EL ARBOL Y LA TAREA
3. Áreas, volumnes, trayectorias ,
4. Racies de ecuaciones , diferenciación numérica, interpolación y
optimización, distancia mas cercana, etc
5. Trabajo libre aposrte puede graficas en 3d ,etc VELERO QUE S EMUEVE,
problema de optimizacin punto de equilibrio , problema de confecciones en,lote
económico, modo grafico, aimaciones simple en modo grafico. Mover crecer,
decrecer por ejmplo ampair y reduiruna fota, que grafique trayectorias, eventos
del mouse y sus aplicaciones . ejemplo que pinte una figura si esta dentro del
polígono. Una aplicación puede4r trslacion, escalado, rotación, grafica de
funciones 3 d ( se necesita arreglos”

6. 10 Diseñe un figura de su creación y haga mover la figura


Demostración de aplicación de

7. D:\CLASES 2018\SISTEMAS DE INFORMACION 2018\SISTEMAS DE


INFORMACIONDOCUMENTOS\APLICACIONES 2016A\FRACTAL(A)

PRACTICA DE VIERNES 1 junio del 2018


Terminar la clase de métodos numéricos
4.7.5.- Método newton rapson
4.8 INTERSECCION DE DOS FUNCIONES
4.9 DIFERENCIACION NUMERICA
PUNTO DE equilibrio , problema de confeciones

Modelo y repitirlo
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 61-

CUADRO CUADROS ALETORIOS


TORE DE 5 ESCLAONE

3.6 ACCESIBILIDAD DE LAS VARIABLES. AMBITO ejemplos

3.9.- RECURSIVIDAD
TORRES DE HANOI
10 Diseñe un figura de su creación y haga mover la figura

Module Module1
Function f(ByVal x As Single) As Single
Return (x + 2) * (x - 3)
End Function

Sub Buscartodas(ByVal a As Single, ByVal b As Single, ByVal h As Single)


Dim x As Single
Dim cadena As String
Dim cont, res As Integer
For x = a To b Step h
res = f(x) * f(x + h)
If res <= 0 Then
cadena = "HAY RAIZ"
Console.WriteLine("Nro {0} entre {1} y {2} ={3} {4}", _
cont, x, x + h, res, cadena)
x=x+4*h
Else
cadena = "no hay raiz"
End If

cont = cont + 1
Next
End Sub
Sub Main()
Dim a As Single = -3, b As Single = 4
Dim h As Single = 0.1
Buscartodas(a, b, h)
Console.ReadLine()
End Sub
End Module

SOLIDOS DE REVOLUCION EN 3D VISUAL BASIC CON OPENGL


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 62-
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 63-

CODIGO DEL FORMULARIO

Imports Tao.Platform.Windows
Imports Tao.OpenGl
Imports System.IO
Public Class Form1
Sub Iniciar()
DataGridView1.ColumnCount = 4
DataGridView1.RowCount = 4
Dim fila, col As Integer
DataGridView1.Columns(0).Width = 50
For col = 0 To 3
DataGridView1.Columns(col).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PROPIEDAD"
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 64-

DataGridView1.Columns(1).HeaderText = "EjeX"
DataGridView1.Columns(2).HeaderText = "Eje Y"
DataGridView1.Columns(3).HeaderText = "Eje Z"

DataGridView1.Rows(0).Cells(0).Value = "Rotacion"
DataGridView1.Rows(0).Cells(1).Value = anguloCuboX
DataGridView1.Rows(0).Cells(2).Value = anguloCuboY
DataGridView1.Rows(0).Cells(3).Value = anguloCuboZ

DataGridView1.Rows(1).Cells(0).Value = "Traslacion"
DataGridView1.Rows(1).Cells(1).Value = tx
DataGridView1.Rows(1).Cells(2).Value = ty
DataGridView1.Rows(1).Cells(3).Value = tz

DataGridView1.Rows(2).Cells(0).Value = "Escalado"
DataGridView1.Rows(2).Cells(1).Value = ex
DataGridView1.Rows(2).Cells(2).Value = Ey
DataGridView1.Rows(2).Cells(3).Value = Ez
End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs)


Handles MyBase.Closed
Opengl.EliminarOpenGL()
End
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Iniciar()
Show()
Form2.Width = Ancho
Form2.Height = Alto
Opengl = New OGL
Opengl.InitOPENGL(User.GetDC(Form2.Handle))
Form2.Show()
Opengl.BucleOpenGl()
End Sub

Private Sub TxtRot_KeyDown(sender As Object, e As KeyEventArgs) Handles


TxtRot.KeyDown
anguloCuboX = DataGridView1.Rows(0).Cells(1).Value
anguloCuboY = DataGridView1.Rows(0).Cells(2).Value
anguloCuboZ = DataGridView1.Rows(0).Cells(3).Value
Select Case e.KeyCode
Case Keys.Right ' fflecha derecha rota al rededdor del x
anguloCuboX = anguloCuboX + PasoRot
Case Keys.Left ' fflecha izquierdaderecha rota al rededdor del x
anguloCuboX = anguloCuboX - PasoRot
Case Keys.Up ' flecha arriba a al rededdor del y
anguloCuboY = anguloCuboY + PasoRot
Case Keys.Down ' flecha arriba a al rededdor del y
anguloCuboY = anguloCuboY - PasoRot
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 65-

Case Keys.PageUp ' pagina arriba giro alrededor del eje z


anguloCuboZ = anguloCuboZ + PasoRot
Case Keys.PageDown ' pagina arriba giro alrededor del eje z
anguloCuboZ = anguloCuboZ - PasoRot
End Select
DataGridView1.Rows(0).Cells(1).Value = anguloCuboX
DataGridView1.Rows(0).Cells(2).Value = anguloCuboY
DataGridView1.Rows(0).Cells(3).Value = anguloCuboZ
TxtRot.Text = ""
End Sub

Private Sub btnObtener_Click(sender As Object, e As EventArgs) Handles


btnObtener.Click
anguloCuboX = DataGridView1.Rows(0).Cells(1).Value
anguloCuboY = DataGridView1.Rows(0).Cells(2).Value
anguloCuboZ = DataGridView1.Rows(0).Cells(3).Value
tx = DataGridView1.Rows(1).Cells(1).Value
ty = DataGridView1.Rows(1).Cells(2).Value
tz = DataGridView1.Rows(1).Cells(3).Value
ex = DataGridView1.Rows(2).Cells(1).Value
Ey = DataGridView1.Rows(2).Cells(2).Value
Ez = DataGridView1.Rows(2).Cells(3).Value
End Sub

Private Sub btnLuz_Click(sender As Object, e As EventArgs) Handles btnLuz.Click


Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, mat_specular)
Gl.glMaterialf(Gl.GL_FRONT, Gl.GL_SHININESS, mat_shininess(0))
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, light_position)
Gl.glEnable(Gl.GL_COLOR_MATERIAL)
Gl.glEnable(Gl.GL_LIGHT0)
Gl.glEnable(Gl.GL_LIGHTING)
Gl.glEnable(Gl.GL_DEPTH_TEST)
End Sub

Private Sub btnApagar_Click(sender As Object, e As EventArgs) Handles


btnApagar.Click
Gl.glDisable(Gl.GL_COLOR_MATERIAL)
Gl.glDisable(Gl.GL_LIGHTING)
Gl.glDisable(Gl.GL_LIGHT0)
End Sub

Private Sub btnSolido_Click(sender As Object, e As EventArgs) Handles


btnSolido.Click
Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL)
End Sub

Private Sub btnAlambre_Click(sender As Object, e As EventArgs) Handles


btnAlambre.Click
Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE)
End Sub
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 66-

Private Sub btn3d_Click(sender As Object, e As EventArgs) Handles btn3d.Click


Modelo = 2
End Sub

Private Sub btnSolRev_Click(sender As Object, e As EventArgs) Handles


btnSolRev.Click
Modelo = 1
End Sub

Private Sub btnARchivo_Click(sender As Object, e As EventArgs) Handles


btnARchivo.Click
RecuperarMatriz(NombreArchivo, MA, nfilas, ncol)
GraficarFuncion3d(MA, 0, ncol, 0, nfilas, ncol, nfilas)
Modelo = 3
End Sub

Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles


btnIniciar.Click
Iniciar()
End Sub

Private Sub txtTraslacion_KeyDown(sender As Object, e As KeyEventArgs) Handles


txtTraslacion.KeyDown
tx = DataGridView1.Rows(1).Cells(1).Value
ty = DataGridView1.Rows(1).Cells(2).Value
tz = DataGridView1.Rows(1).Cells(3).Value
Select Case e.KeyCode
Case Keys.Right ' fflecha derecha rota al rededdor del x
tx = tx + pasoTras
Case Keys.Left ' fflecha izquierdaderecha rota al rededdor del x
tx = tx - pasoTras
Case Keys.Up ' flecha arriba a al rededdor del y
ty = ty + pasoTras
Case Keys.Down ' flecha arriba a al rededdor del y
ty = ty - pasoTras
Case Keys.PageUp ' pagina arriba giro alrededor del eje z
tz = tz + pasoTras
Case Keys.PageDown ' pagina arriba giro alrededor del eje z
tz = tz - pasoTras
End Select
DataGridView1.Rows(1).Cells(1).Value = tx
DataGridView1.Rows(1).Cells(2).Value = ty
DataGridView1.Rows(1).Cells(3).Value = tz
txtTraslacion.Text = ""
End Sub

Private Sub txtEscalado_KeyDown(sender As Object, e As KeyEventArgs) Handles


txtEscalado.KeyDown
ex = DataGridView1.Rows(2).Cells(1).Value
Ey = DataGridView1.Rows(2).Cells(2).Value
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 67-

Ez = DataGridView1.Rows(2).Cells(3).Value
Select Case e.KeyCode
Case Keys.Right ' fflecha derecha rota al rededdor del x
ex = ex + pasoEscala
Case Keys.Left ' fflecha izquierdaderecha rota al rededdor del x
ex = ex - pasoEscala
Case Keys.Up ' flecha arriba a al rededdor del y
Ey = Ey + pasoEscala
Case Keys.Down ' flecha arriba a al rededdor del y
Ey = Ey - pasoEscala
Case Keys.PageUp ' pagina arriba giro alrededor del eje z
Ez = Ez + pasoEscala
Case Keys.PageDown ' pagina arriba giro alrededor del eje z
Ez = Ez - pasoEscala
End Select
DataGridView1.Rows(2).Cells(1).Value = ex
DataGridView1.Rows(2).Cells(2).Value = Ey
DataGridView1.Rows(2).Cells(3).Value = Ez
txtEscalado.Text = ""
End Sub
End Class

CODIGO DEL MODULE 1

Imports System.IO
Module Module1
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant
End Function

Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Single, ByRef nf


As Integer, ByRef 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
cadena = srLector.ReadLine()
nc = ContarLetra(cadena, vbTab) + 1
Do While Not (cadena = "")
cadena = cadena & vbTab
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 68-

inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
End Module

CODIGO DEL MODULE 2

Imports System.IO

Imports Tao.OpenGl
Imports Tao.OpenGl.Glu
Imports Tao.Platform.Windows

Module Module2
Public ambiente() As Single = {0.5, 0.5, 0.5, 1}
Public mat_specular() As Single = {1.0, 1.0, 1.0, 1.0}
Public mat_shininess() As Single = {50.0} '//resplandor
Public light_position() As Single = {15, 5, 5, 1}
Public difuso() As Single = {1, 1, 1, 1}
Public especular() As Single = {1, 1, 1, 1}
'******************
'Public NombreArchivo As String = "D:\datos\matriz20x20.txt"
Public Const limite As Integer = 120
Public NombreArchivo As String = "D:\datos\misti.txt"

Public MA(limite, limite) As Single


Public nfilas, ncol As Integer
' xxxxxxxxxxxxxxxxx
Public M3D(limite, limite) As Single
Public Lix As Single = -5
Public LsX As Single = 5
Public Liy As Single = -5
Public Lsy As Single = 5
Public npx As Integer = 80
Public npy As Integer = 80
Public Modelo As Integer = 1
' xxxxxxxxxxxxxxxxx
Public Opengl As OGL
Public anguloCuboX As Integer = 0 '-45
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 69-

Public anguloCuboY As Integer = 0


Public anguloCuboZ As Integer = 0
Public tx As Single = 0
Public ty As Single = 0
Public tz As Single = 0
Public pasoTras As Single = 1
Public ex As Single = 1
Public Ey As Single = 1
Public Ez As Single = 1
Public pasoEscala As Single = 0.1
Public Ancho As Single = 600
Public Alto As Single = 600
Public tam As Integer = 10
Public qobj As Glu.GLUquadric
Public PasoRot As Single = 5
Public tipo As Integer = 2
Public X(limite) As Single
Public Y(limite) As Single
Public Z(limite) As Single
Public Radio As Single = 4
Public npRadio As Integer = 16
Public ndiscos As Integer = 20
Public A As Single = -3
Public B As Single = 4
Function fxy(x As Single, y As Single) As Single
If Math.Cos(x * x + y * y) / (x * x + y * y) < tam / 4 Then
Return Math.Cos(x * x + y * y) / (x * x + y * y)
Else
Return tam / 4
End If
End Function
Function f(x As Single) As Single
'Return 2 + 0.5 * x
Return 4 + +0.1 * x + Math.Sin(x)
'Return Math.Sqrt(16 - x * x)
End Function
Sub generarPuntos3D(M3D(,) As Single, LiX As Single, LsX As Single, LiY As Single,
LsY As Single, NpX As Integer, NpY As Integer)
Dim Archivo As StreamWriter
Archivo = New StreamWriter("D:\datos\funcion3d.txt")
Dim dx As Single = (LsX - LiX) / NpX
Dim dy As Single = (LsY - LiY) / NpY
Dim x, y As Single
Dim fila, col As Integer
y = LiY
For fila = 0 To NpX
y = y + dy
x = LiX
For col = 0 To NpY
x = x + dx
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 70-

M3D(fila, col) = fxy(x, y)


Archivo.Write("{0}{1}", M3D(fila, col), vbTab)
Next
Archivo.WriteLine()
Next
Archivo.Close()
End Sub
Sub generarPuntos(X() As Single, Y() As Single, Z() As Single, Radio As Single,
npuntos As Integer)
Dim dx As Single = 2 * Math.PI / npuntos
Dim fila As Integer
Dim px, py As Single
Dim alfa As Single = 0
For fila = 0 To npuntos + 1
px = Radio * Math.Cos(alfa)
py = Radio * Math.Sin(alfa)
X(fila) = px
Y(fila) = py
Z(fila) = 0
alfa = alfa + dx
Next
End Sub

Sub Traslacion(X() As Single, Y() As Single, Z() As Single, _


X1() As Single, Y1() As Single, Z1() As Single, _
np As Integer, tx As Single, ty As Single, tz As Single)
Dim fila As Integer
For fila = 0 To np - 1
X1(fila) = X(fila) + tx
Y1(fila) = Y(fila) + ty
Z1(fila) = Z(fila) + tz
Next
End Sub

Sub DISCO(X() As Single, Y() As Single, Z() As Single, nRadio As Integer, altura As
Single)
Dim fila As Integer
Dim x1(100), Y1(100), Z1(100) As Single
Traslacion(X, Y, Z, x1, Y1, Z1, nRadio, 0, 0, altura)
Gl.glBegin(Gl.GL_POLYGON) ' inicio del poligono
For fila = 0 To nRadio - 1
Gl.glVertex3f(X(fila), Y(fila), Z(fila)) ' // color verde
Next
Gl.glEnd()
Gl.glBegin(Gl.GL_POLYGON) ' inicio del poligono
For fila = 0 To nRadio - 1
Gl.glVertex3f(x1(fila), Y1(fila), Z1(fila)) ' // color verde
Next
Gl.glEnd()
For fila = 0 To nRadio - 2
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 71-

Gl.glBegin(Gl.GL_QUADS)
Gl.glVertex3f(X(fila), Y(fila), Z(fila))
Gl.glVertex3f(x1(fila), Y1(fila), Z1(fila))
Gl.glVertex3f(x1(fila + 1), Y1(fila + 1), Z1(fila + 1))
Gl.glVertex3f(X(fila + 1), Y(fila + 1), Z(fila + 1))
Gl.glEnd()
Next
End Sub
Sub GraficarFuncion3d(M3D(,) As Single, Lix As Single, lsX As Single, _
Liy As Single, lsy As Single, _
npX As Integer, npy As Integer)
Dim fila, col As Integer
Dim dx As Single = (lsX - Lix) / npX
Dim dy As Single = (lsy - Liy) / npy
Dim x, y As Single
y = Liy
For fila = 0 To npy
y = y + dy
x = Lix
For col = 0 To npX
x = x + dx
Gl.glBegin(Gl.GL_QUADS)
Gl.glVertex3f(x, y, M3D(fila, col))
Gl.glVertex3f(x, y + dy, M3D(fila + 1, col))
Gl.glVertex3f(x + dx, y + dy, M3D(fila + 1, col + 1))
Gl.glVertex3f(x + dx, y, M3D(fila, col + 1))
Gl.glEnd()
Next
Next
End Sub
Sub GraficarFuncion(VX() As Single, VY() As Single, VZ() As Single, a As Single, b
As Single, _
npRadio As Integer, ndiscos As Integer)
Dim x, y, x1, y1, x2, y2, dx As Single
dx = (b - a) / ndiscos
For x = a To b - dx Step dx
x1 = x
y1 = f(x)
x2 = x + dx
y2 = f(x + dx)
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(x1, y1, 0)
Gl.glVertex3f(x2, y2, 0)
Gl.glEnd()
Gl.glPushMatrix()
Gl.glColor3f(1, 1, 0)
Gl.glRotatef(90, 0.0F, 1.0F, 0.0F)
Radio = (y1 + y2) / 2
generarPuntos(VX, VY, VZ, Radio, npRadio)
Gl.glTranslatef(0, 0, x)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 72-

DISCO(VX, VY, VZ, npRadio, dx)


Gl.glPopMatrix()
Next
End Sub
End Module

CODIGO DE LA CLASE OGL

Imports Tao.OpenGl
Imports Tao.Platform.Windows
Imports System.IO

Public Class OGL


Dim hRC As System.IntPtr
Dim hDc As System.IntPtr
' Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByVal
Destination As Gdi.PIXELFORMATDESCRIPTOR, ByVal Length As Integer)
Public Sub InitOPENGL(ByVal ghDC As System.IntPtr)
Dim pfd As Gdi.PIXELFORMATDESCRIPTOR
Dim PixelFormat As Integer
hDc = ghDC
' ZeroMemory(pfd, Len(pfd))
pfd.nSize = Len(pfd)
pfd.nVersion = 1
pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW Or Gdi.PFD_SUPPORT_OPENGL
Or Gdi.PFD_DOUBLEBUFFER
pfd.iPixelType = Gdi.PFD_TYPE_RGBA
pfd.cColorBits = 32
pfd.cDepthBits = 32
pfd.cStencilBits = 32
pfd.iLayerType = Gdi.PFD_MAIN_PLANE
PixelFormat = Gdi.ChoosePixelFormat(ghDC, pfd)
If PixelFormat = 0 Then
MessageBox.Show("Imposible obtener el formato de los pixels")
End
End If
If Not (Gdi.SetPixelFormat(ghDC, PixelFormat, pfd)) Then
MessageBox.Show("Imposible establecer formato de pixel")
End
End If
hRC = Wgl.wglCreateContext(ghDC)
If hRC.ToInt32 = 0 Then
MessageBox.Show("imposible obtener el contexto del renderizado")
End
End If
If Not (Wgl.wglMakeCurrent(ghDC, hRC)) Then
MessageBox.Show("Imposible hacer el contexto del renderizado")
End
End If
Inicializaciones()
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 73-

End Sub
Public Sub EliminarOpenGL()
Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero)
Wgl.wglDeleteContext(hRC)
End Sub

Public Sub BucleOpenGl()


Inicializaciones()
Do
Render()
Loop
End Sub
Private Sub Render()
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT)
Application.DoEvents()
display()
Gdi.SwapBuffers(hDc)
End Sub
Sub Coordenadas()
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)
Gl.glColor3f(1, 0, 0) REM eje x
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(0, 0, 0)
Gl.glVertex3f(tam, 0, 0)
Gl.glEnd()

Gl.glColor3f(0, 1, 0) REM eje y


Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(0, 0, 0)
Gl.glVertex3f(0, tam, 0)

Gl.glEnd()
Gl.glColor3f(0, 0, 1) REM eje z
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(0, 0, 0)
Gl.glVertex3f(0, 0, tam)
Gl.glEnd()
End Sub
Sub display()
Gl.glLoadIdentity()
Gl.glRotatef(anguloCuboX, 1.0F, 0.0F, 0.0F)
Gl.glRotatef(anguloCuboY, 0.0F, 1.0F, 0.0F)
Gl.glRotatef(anguloCuboZ, 0.0F, 0.0F, 1.0F)
Gl.glScalef(ex, Ey, Ez)
Gl.glTranslatef(tx, ty, tz)

Coordenadas()
Gl.glColor3f(1, 1, 0)
Select Case Modelo
Case 1
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 74-

GraficarFuncion(X, Y, Z, A, B, npRadio, ndiscos)


Gl.glPushMatrix()
Gl.glColor3f(1, 1, 1)
Gl.glTranslatef(light_position(0), light_position(1), light_position(2))
Glu.gluSphere(qobj, 0.2, 32, 32)
Gl.glPopMatrix()
Case 2
GraficarFuncion3d(M3D, Lix, LsX, Liy, Lsy, npx, npy)
Case 3
GraficarFuncion3d(MA, 0, ncol, 0, nfilas, ncol, nfilas)
End Select
Gl.glFlush()
End Sub

Sub Inicializaciones()
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambiente)
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, difuso)
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, especular)

Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, mat_specular)


Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SHININESS, mat_shininess)
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, light_position)
Gl.glEnable(Gl.GL_DEPTH_TEST)
Gl.glEnable(Gl.GL_COLOR_MATERIAL)
Gl.glEnable(Gl.GL_LIGHTING)
Gl.glEnable(Gl.GL_LIGHT0)

Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F)


qobj = New Glu.GLUquadric
qobj = Glu.gluNewQuadric()
Gl.glColor3f(0, 1, 0)
Gl.glMatrixMode(Gl.GL_PROJECTION)
Gl.glLoadIdentity()
Gl.glOrtho(-tam, tam, -tam, tam, -tam * 2, tam * 2)
Gl.glMatrixMode(Gl.GL_MODELVIEW)
Gl.glLoadIdentity()
Gl.glLightModeli(Gl.GL_LIGHT_MODEL_TWO_SIDE, Gl.GL_FALSE) ' solo se
ilumina un lado
Gl.glEnable(Gl.GL_DEPTH_TEST)
'Gl.glShadeModel(Gl.GL_SMOOTH)
Gl.glShadeModel(Gl.GL_FLAT)
generarPuntos3D(M3D, Lix, LsX, Liy, Lsy, npx, npy)
End Sub
End Class

b
EJERCICIO PREGUNTAS TIPO PARA EL SEGUNDO EXAMEN

15. usando funciones encuentre los valores de Z= X*X+Y*Y


X= 1,2,3,4,5,6 i Y=1,1; 1,2; ...1,9; 2,0
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 75-

16 Encuentre los valores de la función mostrada


Y= x si 0<=x<=10
Y= sin(x) +10 si 10<x <= 20
Y= 30-x si 20<x<030
Y= 0 en lo demás casos
17 usando la función cuadro juegue con elle forme figura dibuje otras figuras

Mover, escalar, y forme otras figuras


1. Lo mismo, pero en modo formulario
Función línea dibuje una figura
RECURSVIDAD.
Integral de una función
Figuras recursivas
Recursividad en modo formulario fractales

METODO NUEMRICOS
Encuentra el área y volumen de una figura de su creación e interprete en modo consola
y modo formulario
Encuentre la raíz de una ecuación que usted mismo se plantee
Problema de optimizacion, problema de confesiones y punto de equilibro
Hallar el área sombreada

Se revisara el avance del trabajo dejado


MAÑANA se resolverá consultas y plantee problemas d einteres para resolver y
consulta de dudas

PRACTICAS DEL MARTES 6 DE JUNIO DEL 2018

Funciones de suma

Function suma(n As Integer) As Integer


If n > 1 Then
' suma = n + suma(n - 1)
Return n + suma(n - 1)
Else
Return 1
End If
End Function
Sub MAIN()
Console.WriteLine(" la suma es {0} ", suma(10))
Console.ReadLine()
En sub
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 76-

Integral recursive

Module Module4
Function f(ByVal x As Single) As Single
Return x * x
End Function
Function Trapecialrecursivo(ap, a, b, h) As Single
Dim x, y1, y2 As Single
If a < b Then
y1 = f(a)
y2 = f(a + h)
ap = (y1 + y2) / 2 * h
Return ap + Trapecialrecursivo(ap, a + h, b, h)
Else
Return 0
End If
End Function
Function Trapecial(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single, ap, dx As Single
ap = 0
dx = (b - a) / n
at = Trapecialrecursivo(ap, a, b, dx)
Return at
End Function

Sub Main()
Dim a, b, area As Single
area = Trapecial(0, 2, 4000)
Console.WriteLine("La integral es {0} ", area)
Console.ReadLine()
End Sub
End Module

Practicas del martes 5 de junio del 2018


Se tiene la función f(x)=(x+1)(x-2)(x-4)
A) Hallar los valores de la funcion
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 77-

Module Module1
Function f(x As Single) As Single
Return (x + 1) * (x - 2) * (x - 4)

End Function
Sub Main()
Dim x, y As Single
Dim a, b, dx As Single
a = -2 : b = 5 : dx = 0.5
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 78-

For x = a To b Step dx
y = f(x)
Console.WriteLine(" {0} {1} {2} ", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module

Posibles preguntas
1 cambiar la funion y halle
1. Ingrese a,b, y nro de divisiones
2. Grafique la funcion
3. Grafique la funciones pero en modo formualarioo
4. Encuentre las raíces de la ecuaciones
5. Encuentre el recorrido de la función desde la raíz 1 hasta la raíz 3. Un móvil
recorre por esa funcion
6. Integral de la raiz1 a la raíz 3
7. Volumen de revolución de r1 a r33 pr el método de disco ( simpson)
8. Volumen de disco por el método de los cilidnicos
9. Área lateral de r1 a r3
10. Encuntre el máximo de la función de la r1 a r2 ( valores de x y y)
11. En que parte la función se tiene mayor derivada ( pendiente)
12. Otras que usted vea por conviene por ejemplo dado un punto encuentre el punto
mas cercano

Funciones f(x,y)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 79-

eLabore tabla de mulgtiplicar de 1 la 12 o tablas de interés

Imports System.IO
Module Module1
Function fxy(x As Single, y As Single) As Single
Return Math.Cos(x * x + y * y) / (x * x + y * y)

End Function
Sub Main()
Dim x, y, z As Single
Dim lix, lsx, liy, lsy, dx, dy As Single
Dim archivo As StreamWriter
archivo = New StreamWriter("D:\datos\grafico3d.txt")
lix = -5 : lsx = 5 : dx = 0.5 : liy = -5 : lsy = 5 : dy = 0.5
For y = liy To lsy Step dy
For x = lix To lsx Step dx
z = fxy(x, y)
Console.Write("{0}{1}", z, vbTab)
archivo.Write("{0}{1}", z, vbTab)
Next
Console.WriteLine()
archivo.WriteLine()
Next
archivo.Close()
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 80-

Chart Title

2
Series19
1
Series13
0
Series7
1 3 5
-1 7 9 11 13 Series1
15 17 19 21

-1-0 0-1 1-2 2-3 3-4

Grafique la funcion en 3d con su rotacion traslacionn y escalado en modo formulario


Encuentre el punto mas alto y otras caraterisitcia
Otras funciones

Se debe practicar para el examen

Jueguen con el auto por ejemplo carrera de autos, y la función f(x) y f(x,y) hecho
en practicas. Recursivdad tanto function como sub. Cree figuras recursivas, vea
el punto de quilibrio confeciones y otros problemas de optimización.
ProbLEmea de conduccion terminado

Module Module1
Dim cki As ConsoleKeyInfo
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 81-

Dim ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 As Integer
Function prueba(px As Integer, py As Integer) As Integer
Dim r1, r2 As Integer
If (px > ax1 And px < ax2 And py > ay1 And py < ay2) Then
r1 = 1
Else
r1 = 0
End If

If (px < bx1 Or px > bx2 Or py < by1 And py > by2) Then
r2 = 1
Else
r2 = 0
End If
If r1 = 1 And r2 = 1 Then
Return 1
Else
Return 2
End If
Return 1
End Function
Sub contadorMov(cx As Integer, cy As Integer, Mov As Integer)
Console.ForegroundColor = 15
Console.SetCursorPosition(30, 12)
Console.Write("Cx = {0} cy= {1} Mov ={2}", cx, cy, Mov)
End Sub
Sub main()

ax1 = 2 : ay1 = 2 : ax2 = 76 : ay2 = 22


bx1 = 20 : by1 = 10 : bx2 = 40 : by2 = 6
Cuadro(1, 1, 79, 24, 10)
Cuadro(ax1, ay1, ax2, ay2, 8)
Cuadro(bx1, by1, bx2, by2, 2)
Px = 40 : Py = 6 : alto = 1 : ancho = 5 : Color1 = 14 : Color2 = 9
autoderecho(Px, Py, ancho, alto, Color1, Color2, "A")
dir = 1
mov = 0
contadorMov(Px, Py, mov)
Do
cki = Console.ReadKey()
mov = mov + 1
contadorMov(Px, Py, mov)
Select Case dir
Case 1 : autoderecho(Px, Py, ancho, alto, borrador, borrador, "") ' derecha
Case 2 : autoabajo(Px, Py, alto, ancho, borrador, borrador, "") ' abajo
Case 3 : autoIzquierdo(Px, Py, ancho, alto, borrador, borrador, "") 'izquierda
Case 4 : autoarriba(Px, Py, alto, ancho, borrador, borrador, "")
End Select
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 82-

If cki.Key = ConsoleKey.LeftArrow And prueba(Px - 1, Py) = 1 Then 'flecha


izquierda
Px = Px - 1
dir = 3
autoIzquierdo(Px, Py, ancho, alto, Color1, Color2, "B")
End If
If cki.Key = ConsoleKey.RightArrow And prueba(Px + 1, Py) = 1 Then ' derecha
Px = Px + 1
dir = 1
autoderecho(Px, Py, ancho, alto, Color1, Color2, "A")
End If
If cki.Key = ConsoleKey.UpArrow And prueba(Px, Py - 1) = 1 Then ' flecha
arriba
Py = Py - 1
dir = 4
autoarriba(Px, Py, alto, ancho, Color1, Color2, "D")
End If
If cki.Key = ConsoleKey.DownArrow And prueba(Px, Py + 1) = 1 Then 'flecha
abajo
Py = Py + 1
dir = 2
autoabajo(Px, Py, alto, ancho, Color1, Color2, "C")
End If
Loop While cki.Key <> ConsoleKey.Escape
Console.ReadLine()

End Sub

End Module

Module Module2

Public ancho As Integer = 6


Public alto As Integer = 1
Public dir As Integer = 1
Public Nombre As String = "A"
Public Px As Integer = 40
Public Py As Integer = 12
Public Color1 As Integer = 14
Public Color2 As Integer = 9
Public borrador As Integer = 8
Public mov As Integer = 0
Sub Cuadro(cx As Integer, cy As Integer, ancho As Integer, alto As Integer, COLOR
As Integer)
Dim fila, col As Integer
Console.ForegroundColor = COLOR
Console.BackgroundColor = COLOR
For fila = 0 To alto - 1
For col = 0 To ancho - 1
Console.SetCursorPosition(cx + col, cy + fila)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 83-

Console.Write("X")
Next
Next
End Sub

Sub Marca(px1 As Integer, py1 As Integer, Nombre As String)


Console.ForegroundColor = 15
Console.SetCursorPosition(px1, py1)
Console.Write(Nombre)
End Sub
Sub autoderecho(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer, _
color1 As Integer, color2 As Integer, nombre As String)
Cuadro(Px - ancho, Py - alto, ancho, alto, color1)
Cuadro(Px - ancho, Py, ancho, alto, color1)
Cuadro(Px - ancho, Py + alto, ancho, alto, color1)

Cuadro(Px - ancho, Py - alto * 2, alto, alto, color2)


Cuadro(Px - alto * 2, Py - alto * 2, alto, alto, color2)
Cuadro(Px - ancho, Py + alto * 2, alto, alto, color2)
Cuadro(Px - alto * 2, Py + alto * 2, alto, alto, color2)

Marca(px1 - 1, py1, nombre)

End Sub
Sub autoIzquierdo(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer,
_
color1 As Integer, color2 As Integer, nombre As String)
Cuadro(px1, py1 - alto, ancho, alto, color1)
Cuadro(px1, py1, ancho, alto, color1)
Cuadro(px1, py1 + alto, ancho, alto, color1)
Cuadro(Px + alto, Py - alto * 2, alto, alto, color2)
Cuadro(Px + ancho - alto, Py - alto * 2, alto, alto, color2)
Cuadro(Px + alto, Py + alto * 2, alto, alto, color2)
Cuadro(Px + ancho - alto, Py + alto * 2, alto, alto, color2)
Marca(px1, py1, nombre)
End Sub
Sub autoabajo(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer, _
color1 As Integer, color2 As Integer, nombre As String)
Cuadro(Px - ancho, Py - alto, ancho, alto, color1)
Cuadro(Px, Py - alto, ancho, alto, color1)
Cuadro(Px + ancho, Py - alto, ancho, alto, color1)

Cuadro(Px - ancho * 2, Py - alto, ancho, ancho, color2)


Cuadro(Px + ancho * 2, Py - alto, ancho, ancho, color2)
Cuadro(Px - ancho * 2, Py - ancho * 2, ancho, ancho, color2)
Cuadro(Px + ancho * 2, Py - ancho * 2, ancho, ancho, color2)

Marca(Px, Py - 1, nombre)
End Sub
Sub autoarriba(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer, _
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 84-

color1 As Integer, color2 As Integer, nombre As String)


Cuadro(Px - ancho, Py, ancho, alto, color1)
Cuadro(Px, Py, ancho, alto, color1)
Cuadro(Px + ancho, Py, ancho, alto, color1)

Cuadro(Px - ancho * 2, Py + ancho, ancho, ancho, color2)


Cuadro(Px + ancho * 2, Py + ancho, ancho, ancho, color2)
Cuadro(Px - ancho * 2, Py + alto - ancho, ancho, ancho, color2)
Cuadro(Px + ancho * 2, Py + alto - ancho, ancho, ancho, color2)
Marca(Px, Py, nombre)
End Sub
End Module

Public Class Form1


Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha1 As SolidBrush
Dim brocha2 As SolidBrush

Dim brochacircuito As SolidBrush


Sub autoderechoGrafico(px1 As Integer, py1 As Integer, ancho As Integer, alto As
Integer, tipo As Integer)
Select Case tipo
Case 1
Grafico.FillRectangle(brocha1, Px - ancho, Py - alto, ancho, alto)
Grafico.FillRectangle(brocha1, Px - ancho, Py - alto, ancho, alto)
Grafico.FillRectangle(brocha1, Px - ancho, Py, ancho, alto)
Grafico.FillRectangle(brocha1, Px - ancho, Py + alto, ancho, alto)
Grafico.FillRectangle(brocha2, Px - ancho, Py - alto * 2, alto, alto)
Grafico.FillRectangle(brocha2, Px - alto * 2, Py - alto * 2, alto, alto)
Grafico.FillRectangle(brocha2, Px - ancho, Py + alto * 2, alto, alto)
Grafico.FillRectangle(brocha2, Px - alto * 2, Py + alto * 2, alto, alto)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 85-

Case 2
Grafico.FillRectangle(brochacircuito, px1 - ancho, Py - 2 * alto, ancho, 5 * alto)
End Select

'Marca(px1 - 1, py1, nombre)

End Sub
Sub autoIzquierdografico(px1 As Integer, py1 As Integer, ancho As Integer, alto As
Integer, tipo As Integer)
Select tipo
Case 1

Grafico.FillRectangle(brocha1, px1, py1 - alto, ancho, alto)


Grafico.FillRectangle(brocha1, px1, py1, ancho, alto)
Grafico.FillRectangle(brocha1, px1, py1 + alto, ancho, alto)
Grafico.FillRectangle(brocha2, Px + alto, Py - alto * 2, alto, alto)
Grafico.FillRectangle(brocha2, Px + ancho - alto, Py - alto * 2, alto, alto)
Grafico.FillRectangle(brocha2, Px + alto, Py + alto * 2, alto, alto)
Grafico.FillRectangle(brocha2, Px + ancho - alto, Py + alto * 2, alto, alto)
Case 2
Grafico.FillRectangle(brochacircuito, px1, Py - 2 * alto, ancho, 5 * alto)
End Select
'Marca(px1, py1, Nombre)
End Sub
Sub autoabajoGrafico(px1 As Integer, py1 As Integer, ancho As Integer, alto As
Integer, tipo As Integer)
Select tipo
Case 1
Grafico.FillRectangle(brocha1, Px - ancho, Py - alto, ancho, alto)
Grafico.FillRectangle(brocha1, Px, Py - alto, ancho, alto)
Grafico.FillRectangle(brocha1, Px + ancho, Py - alto, ancho, alto)

Grafico.FillRectangle(brocha2, Px - ancho * 2, Py - alto, ancho, ancho)


Grafico.FillRectangle(brocha2, Px + ancho * 2, Py - alto, ancho, ancho)
Grafico.FillRectangle(brocha2, Px - ancho * 2, Py - ancho * 2, ancho, ancho)
Grafico.FillRectangle(brocha2, Px + ancho * 2, Py - ancho * 2, ancho, ancho)
Case 2
Grafico.FillRectangle(brochacircuito, px1 - 2 * ancho, Py - alto, 5 * ancho, alto)
End Select
'Marca(Px, Py - 1, nombre)
End Sub
Sub autoarribagrafico(px1 As Integer, py1 As Integer, ancho As Integer, alto As
Integer, tipo As Integer)
Select tipo
Case 1
Grafico.FillRectangle(brocha1, Px - ancho, Py, ancho, alto)
Grafico.FillRectangle(brocha1, Px, Py, ancho, alto)
Grafico.FillRectangle(brocha1, Px + ancho, Py, ancho, alto)

Grafico.FillRectangle(brocha2, Px - ancho * 2, Py + ancho, ancho, ancho)


Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 86-

Grafico.FillRectangle(brocha2, Px + ancho * 2, Py + ancho, ancho, ancho)


Grafico.FillRectangle(brocha2, Px - ancho * 2, Py + alto - ancho, ancho,
ancho)
Grafico.FillRectangle(brocha2, Px + ancho * 2, Py + alto - ancho, ancho, ancho)
Case 2
Grafico.FillRectangle(brochacircuito, px1 - 2 * ancho, Py, 5 * ancho, alto)
End Select
'Marca(Px, Py, nombre)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
Pen = New Pen(Color.Blue, 8)
brocha1 = New SolidBrush(Color.FromArgb(255, 255, 0))
brocha2 = New SolidBrush(Color.FromArgb(0, 0, 255))
brochacircuito = New SolidBrush(Color.DarkGray)
End Sub

Private Sub btnEmpezar_Click(sender As Object, e As EventArgs) Handles


btnEmpezar.Click
Grafico.ResetTransform()
Grafico.ScaleTransform(4, 4)
Px = 30 : Py = 12 : alto = 2 : ancho = 10 : Color1 = 14 : Color2 = 9
Grafico.FillRectangle(Brushes.Orange, 1, 1, 154, 104)
Grafico.FillRectangle(brochacircuito, 3, 3, 150, 100)
Grafico.FillRectangle(Brushes.Green, 30, 20, 100, 60)
autoderechoGrafico(Px, Py, ancho, alto, 1)
Grafico.DrawRectangle(Pens.Red, Px - ancho, 2, 20, 20)
dir = 1
mov = 0
End Sub

Private Sub txtMover_KeyDown(sender As Object, e As KeyEventArgs) Handles


txtMover.KeyDown
Select Case dir
Case 1 : autoderechoGrafico(Px, Py, ancho, alto, 2) ' derecha
Case 2 : autoabajoGrafico(Px, Py, alto, ancho, 2) ' abajo
Case 3 : autoIzquierdografico(Px, Py, ancho, alto, 2) 'izquierda
Case 4 : autoarribagrafico(Px, Py, alto, ancho, 2)
End Select
Select Case e.KeyCode
Case Keys.Right ' fflecha derecha rota al rededdor del x
Px = Px + 1
dir = 1
autoderechoGrafico(Px, Py, ancho, alto, 1)
Case Keys.Left ' fflecha izquierdaderecha rota al rededdor del x
Px = Px - 1
dir = 3
autoIzquierdografico(Px, Py, ancho, alto, 1)
Case Keys.Up ' flecha arriba a al rededdor del y
Py = Py - 1
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 87-

dir = 4
autoarribagrafico(Px, Py, alto, ancho, 1)
Case Keys.Down ' flecha arriba a al rededdor del y
Py = Py + 1
dir = 2
autoabajoGrafico(Px, Py, alto, ancho, 1)
End Select
mov = mov + 1
TextBox1.Text = mov
ListBox1.Items.Add("px= " & Px & "py =" & Py & " mov" & mov)
End Sub

End Class

También podría gustarte