In Making use of animations in Visual Basic 2005 there are several commands that are used such as:
1. Readkey
2. KeyAvailable
3. Sleep
ReadKey is used to receive buttons or can also say to make the program stop until any button is pressed. Value of the button is pressed can be stored in a variable manner
dim i = console.readkey
The value of the variable i is the characteristic value of the button is pressed while if you want to take the numerical values of key presses are
dim i = console.readkey.key
suppose if we press the enter key then the value of the variable i is 13 or esc button which is worth 27
KeyAvailable function to check to see if there is button pressed or not. KeyAvailable will is true if any key is pressed and will be false if no button is pressed.
Sleep used to make a pause / stop within the specified time interval, time interval in a matter of 1 / 1000 sec. so if sleep were given high scores Benti it will make the program a long time.
Sleep is used by:
system.Threading.Thread.Sleep (time)
example: system.Threading.Thread.Sleep (100)
Sub main()
Dim x, y, ax, ay As Integer
x = 1
y = 1
ax = 1
ay = 1
Do
Console.CursorTop = y
Console.CursorLeft = x
Console.ForegroundColor = Int(Rnd() * 14)
Console.Write("O")
System.Threading.Thread.Sleep(100)
Console.CursorTop = y
Console.CursorLeft = x
Console.Write(" ")
If x = 78 Then
ax = -1
ElseIf x = 2 Then
ax = 1
ElseIf y = 23 Then
ay = -1
ElseIf y = 1 Then
ay = 1
End If
x = x + ax
y = y + ay
Loop While (Not Console.KeyAvailable)
End Sub
End Module
Sub main()
Dim i, x(10), y(10), ax(10), ay(10) As Integer
For i = 1 To 5
x(i) = (78 * Rnd() + 1)
y(i) = (23 * Rnd() + 1)
ax(i) = 1
ay(i) = 1
Next
Do
For i = 1 To 5
Console.CursorTop = y(i)
Console.CursorLeft = x(i)
Console.Write("O")
Next
System.Threading.Thread.Sleep(100)
For i = 1 To 5
Console.CursorTop = y(i)
Console.CursorLeft = x(i)
Console.Write(" ")
If x(i) = 78 Then
ax(i) = -1
ElseIf x(i) = 2 Then
ax(i) = 1
ElseIf y(i) = 23 Then
ay(i) = -1
ElseIf y(i) = 1 Then
ay(i) = 1
End If
x(i) = x(i) + ax(i)
y(i) = y(i) + ay(i)
Next
Loop While (Not Console.KeyAvailable)
End Sub
End Module
1. Readkey
2. KeyAvailable
3. Sleep
ReadKey is used to receive buttons or can also say to make the program stop until any button is pressed. Value of the button is pressed can be stored in a variable manner
dim i = console.readkey
The value of the variable i is the characteristic value of the button is pressed while if you want to take the numerical values of key presses are
dim i = console.readkey.key
suppose if we press the enter key then the value of the variable i is 13 or esc button which is worth 27
KeyAvailable function to check to see if there is button pressed or not. KeyAvailable will is true if any key is pressed and will be false if no button is pressed.
Sleep used to make a pause / stop within the specified time interval, time interval in a matter of 1 / 1000 sec. so if sleep were given high scores Benti it will make the program a long time.
Sleep is used by:
system.Threading.Thread.Sleep (time)
example: system.Threading.Thread.Sleep (100)
Code One Ball Animation
Module Module1Sub main()
Dim x, y, ax, ay As Integer
x = 1
y = 1
ax = 1
ay = 1
Do
Console.CursorTop = y
Console.CursorLeft = x
Console.ForegroundColor = Int(Rnd() * 14)
Console.Write("O")
System.Threading.Thread.Sleep(100)
Console.CursorTop = y
Console.CursorLeft = x
Console.Write(" ")
If x = 78 Then
ax = -1
ElseIf x = 2 Then
ax = 1
ElseIf y = 23 Then
ay = -1
ElseIf y = 1 Then
ay = 1
End If
x = x + ax
y = y + ay
Loop While (Not Console.KeyAvailable)
End Sub
End Module
Code with Random and Array Five Ball
Module Module1Sub main()
Dim i, x(10), y(10), ax(10), ay(10) As Integer
For i = 1 To 5
x(i) = (78 * Rnd() + 1)
y(i) = (23 * Rnd() + 1)
ax(i) = 1
ay(i) = 1
Next
Do
For i = 1 To 5
Console.CursorTop = y(i)
Console.CursorLeft = x(i)
Console.Write("O")
Next
System.Threading.Thread.Sleep(100)
For i = 1 To 5
Console.CursorTop = y(i)
Console.CursorLeft = x(i)
Console.Write(" ")
If x(i) = 78 Then
ax(i) = -1
ElseIf x(i) = 2 Then
ax(i) = 1
ElseIf y(i) = 23 Then
ay(i) = -1
ElseIf y(i) = 1 Then
ay(i) = 1
End If
x(i) = x(i) + ax(i)
y(i) = y(i) + ay(i)
Next
Loop While (Not Console.KeyAvailable)
End Sub
End Module















0 comments
Post a Comment