Estoy intentando representar gráficamente una onda que oscila. Pero me encuentro dos problemas:
- La onda no presenta "exageradamente" picos grandes. ¿ Por qué ?. ( No quiero que se rompa la onda ).
Tengo una matriz de puntos, tantos puntos como anchura tenga el área de dibujo.
A cada pasada que hace el timer, (podéis variar el tiempo). A cada punto,le añado 1, 0 o resto uno en su eje "Y",
el x no varia.
Os muestro el código y os subo el ejemplo.
' gambas class file
Private Const anchura As Integer = 1
Private matrizdepuntos As New Integer[][]
Private posy As Integer
Public Sub Form_Open()
End
Public Sub _new()
Dim x As Integer
Randomize
Pizarra.Background = Color.Black
'Generar tantos puntos como ancho tenga el area de dibujo
matrizdepuntos.Resize(Pizarra.Width)
'Para evitar valores nulos, llenamos cada indice del array con valores [0,0]
For x = 0 To Pizarra.Width - 1
matrizdepuntos[x] = [0, 0]
Next
'Asignar el primer punto que comienza en x = 0, y = mitad del alto del area de dibujo
matrizdepuntos[0] = [0, Pizarra.H / 2]
'Creamos un array de puntos con posiciones que varian entre -1 y 1
PosPuntos()
Timer1.Delay = 200
Timer1.Start
End
Public Sub PosPuntos()
Dim x As Integer
'El valor x se va ir incrementando de 0 hasta el ancho del area de dibujo
'Tenemos la posición del primer punto.
For x = 1 To Pizarra.Width - 1
'Generar valor entre -1 y 1
posy = Int(Rnd(-1, 2))
matrizdepuntos[x][0] = x
matrizdepuntos[x][1] = matrizdepuntos[x - 1][1] + posy
If matrizdepuntos[x][1] <= 1 Then
matrizdepuntos[x][1] += 1
Else If matrizdepuntos[x][1] >= Pizarra.Height - 1 Then
matrizdepuntos[x][1] -= 1
Endif
Next
End
Public Sub DibujaPunto()
Dim x As Integer
Paint.LineWidth = anchura
For x = 0 To matrizdepuntos.Max
Paint.FillRect(matrizdepuntos[x][0], matrizdepuntos[x][1], anchura, anchura, Color.Yellow)
Next
PosPuntos()
End
Public Sub Pizarra_Draw()
DibujaPunto
End
Public Sub Timer1_Timer()
Pizarra.Refresh
End
Private Const anchura As Integer = 1
Private matrizdepuntos As New Integer[][]
Private posy As Integer
Public Sub Form_Open()
End
Public Sub _new()
Dim x As Integer
Randomize
Pizarra.Background = Color.Black
'Generar tantos puntos como ancho tenga el area de dibujo
matrizdepuntos.Resize(Pizarra.Width)
'Para evitar valores nulos, llenamos cada indice del array con valores [0,0]
For x = 0 To Pizarra.Width - 1
matrizdepuntos[x] = [0, 0]
Next
'Asignar el primer punto que comienza en x = 0, y = mitad del alto del area de dibujo
matrizdepuntos[0] = [0, Pizarra.H / 2]
'Creamos un array de puntos con posiciones que varian entre -1 y 1
PosPuntos()
Timer1.Delay = 200
Timer1.Start
End
Public Sub PosPuntos()
Dim x As Integer
'El valor x se va ir incrementando de 0 hasta el ancho del area de dibujo
'Tenemos la posición del primer punto.
For x = 1 To Pizarra.Width - 1
'Generar valor entre -1 y 1
posy = Int(Rnd(-1, 2))
matrizdepuntos[x][0] = x
matrizdepuntos[x][1] = matrizdepuntos[x - 1][1] + posy
If matrizdepuntos[x][1] <= 1 Then
matrizdepuntos[x][1] += 1
Else If matrizdepuntos[x][1] >= Pizarra.Height - 1 Then
matrizdepuntos[x][1] -= 1
Endif
Next
End
Public Sub DibujaPunto()
Dim x As Integer
Paint.LineWidth = anchura
For x = 0 To matrizdepuntos.Max
Paint.FillRect(matrizdepuntos[x][0], matrizdepuntos[x][1], anchura, anchura, Color.Yellow)
Next
PosPuntos()
End
Public Sub Pizarra_Draw()
DibujaPunto
End
Public Sub Timer1_Timer()
Pizarra.Refresh
End
Ahora parece que funciona mejor.
OndaRepresentDatos2.tar.gz | ||
Descripción: | Descargar |
|
Nombre del archivo: | OndaRepresentDatos2.tar.gz | |
Tamaño: | 14.18 KB | |
Descargado: | 29 veces |
OndaRepresentDatos2.tar.gz | ||
Descripción: | Descargar |
|
Nombre del archivo: | OndaRepresentDatos2.tar.gz | |
Tamaño: | 14.18 KB | |
Descargado: | 29 veces |
OndaRepresentDatos2.tar.gz | ||
Descripción: | Descargar |
|
Nombre del archivo: | OndaRepresentDatos2.tar.gz | |
Tamaño: | 14.18 KB | |
Descargado: | 29 veces |