|
-
Aug 4th, 2009, 09:30 PM
#10
Thread Starter
Addicted Member
Re: graphical APIs
I'll give you the code I'm using. In order for you to use it, you'll need a form, with its Picture property set to a colored bitmap about half the width of your screen and the same height as the screen. You'll also need a commandbutton and a timer (Interval = 1). Here follows the code:
Code:
Option Explicit
Option Base 1
Private Type bitmap
bmtype As Long
bmwidth As Long
bmheight As Long
bmwidthbytes As Long
bmplanes As Integer
bmbitspixel As Integer
bmbits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hobject As Long, ByVal ncount As Long, lpobject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hbitmap As Long, ByVal dwcount As Long, ByRef lpbits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hbitmap As Long, ByVal dwcount As Long, ByRef lpbits As Any) As Long
Private Sub Command1_Click()
Timer1.Enabled=True
End Sub
Private Sub Form_Load()
Timer1.Enabled=False
End Sub
Private Sub Timer1_Timer()
Dim bm As bitmap, imagedata() As Byte, imagedatacopy() As Byte, x As Long, y As Long, freq As Single, phase As Single
Static i As Long
i=i+1
Randomize Timer
GetObject Picture.Handle, Len(bm), bm
ReDim imagedata(bm.bmbitspixel\8, bm.bmwidth, bm.bmheight)
GetBitmapBits Picture.Handle, bm.bmwidthbytes*bm.bmheight, imagedata(1,1,1)
imagedatacopy=imagedata
For y = 1 To bm.bmheight
freq = 10 * Rnd
phase = Rnd * bm.bmwidth
For x = 1 To bm.bmwidth
If y + 7 < bm.bmheight And x + 7 < bm.bmwidth And x - 7 > 0 Then
imagedata(3, x, y + CInt(1 * Abs(Sin(freq * x + phase)))) = imagedata(3, x, y)
imagedata(2, x, y + CInt(1 * Abs(Sin(freq * x + phase)))) = imagedata(2, x, y)
imagedata(1, x, y + CInt(1 * Abs(Sin(freq * x + phase)))) = imagedata(1, x, y)
imagedatacopy(3, x + CInt(7 * Sin(0.2 * y + i)), y) = imagedata(3, x, y)
imagedatacopy(2, x + CInt(7 * Sin(0.2 * y + i)), y) = imagedata(2, x, y)
imagedatacopy(1, x + CInt(7 * Sin(0.2 * y + i)), y) = imagedata(1, x, y)
End If
Next x
Next y
SetBitmapBits Picture.Handle, bm.bmwidthbytes * bm.bmheight, imagedatacopy(1, 1, 1)
Refresh
End Sub
The outcome is what I desire. However, it's slow. And the reason is not the APIs, but the calculations (I tried it without calculations and it works fast enough). Do you know how I can speed it up?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|