PDA

Click to See Complete Forum and Search --> : Testing fox vbtool thing. Btw, look at the amazing Graphics: Electric Field demo


kedaman
Mar 8th, 2001, 06:34 PM
Put it all in a form, run and enjoy:


Option Explicit
'Kedamans Charges and Electric Field Demo

' 1. mouse down where you want to have a chage
' 2. drag to set the size
' 3. hold shift down for positive chages

Const Grid! = 50 'Decrease this value (not below 15) for more more gridpoints ( _
cool), increase to see the field lines (also cool) to 100 or 150
Const ShowCharges As Boolean = True
Const Escale! = 2000000 'Field Strength Scale Constant

Private Type P2S
X As Single
Y As Single
End Type
Private Type Charge
Mag As Single
Pos As P2S
End Type
Private Enum enmmode
None
DrawCharge
End Enum
Dim mode As enmmode, current As Charge, _
charges() As Charge, chargescount As Long

Private Sub Draw()
On Error Resume Next
Dim x!, y!, n&, sumx!, sumy!, dx!, dy!, m!, q!
Cls
For Y = ScaleTop To ScaleTop + ScaleHeight Step Grid
For X = ScaleLeft To ScaleWidth Step Grid
sumx = 0
sumy = 0
For N = 0 To chargescount - 1
With charges(N)
dx = .Pos.X - X
dy = .Pos.Y - Y
M = (dx * dx + dy * dy)
Q = Sqr(M)
If Q > 10 And M > 10 Then
sumx = sumx + dx * .Mag / (M * Q) * Escale
sumy = sumy + dy * .Mag / (M * Q) * Escale
End If
End With
Next N
M = sumx * sumx + sumy * sumy
Q = Sqr(M)
'if you want you could make a function that gradiently shifts between colors

If Q Then Line (X, Y)-Step( _
sumx / Q * 100, sumy / Q * 100), RGB((M / 1000) And 255, _
(M / 100) And 255, (M / 10000) And 255)

'this is another version, doesn't look cool though, red and logaritmic
'If q Then Line (x, y)-Step(sumx / q * 100, sumy / q * 100), (Log(m) * 10)

'If m < 10000000 Then Line (x, y)-Step(sumx / 10, sumy / 10), RGB((Log(m) * 2) And 255, _
(Log(m) * 4) And 255, (Log(m) * 6) And 255)


Next X
Next Y
If ShowCharges Then
For N = 0 To chargescount - 1
With charges(N)
FillColor = QBColor(Sgn(.Mag) * 1.5 + 2.1)
Circle (.Pos.X, .Pos.Y), Abs(.Mag)
End With
Next N
End If
End Sub

Private Sub Form_Load()
Caption = "Kedamans Electric field and chages demo: mouse down where you want to have a chage, drag to set the size, _
hold shift down for positive chages"
FillStyle = vbDiagonalCross
WindowState = vbMaximized
'BackColor = 0
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
current.Pos.X = X
current.Pos.Y = Y
mode = DrawCharge
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim dx!, dy!
If mode = DrawCharge Then
With current
dx = .Pos.X - X
dy = .Pos.Y - Y
FillColor = QBColor(Shift * 3 + 1)
Circle (.Pos.X, .Pos.Y), Sqr(dx * dx + dy * dy)
End With
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim dx!, dy!
dx = current.Pos.X - X
dy = current.Pos.Y - Y
current.Mag = Sqr(dx * dx + dy * dy) * Sgn(Shift - 0.5)
mode = None
ReDim Preserve charges(chargescount)
charges(chargescount) = current
chargescount = chargescount + 1
Draw
End Sub

Private Sub Form_Resize()
Draw
End Sub


'Code improved by vBulletin Tool (http://orion.spaceports.com/~mccloud/vbtool.zip) (Save as...)

Mar 8th, 2001, 06:40 PM
kedaman, You Rock

HarryW
Mar 8th, 2001, 07:07 PM
Very cool :)

kedaman
Mar 8th, 2001, 07:40 PM
Yep, here's another version, it doesn't display the field lines but instead a matrix of the magnitudes. The thing is that you can "dig holes" and they can be pretty cool shaped ;) Try it out, cool landscaping tool maybe?=

Mar 8th, 2001, 09:02 PM
I liked the other one better. The new one doesnt put the holes/spikes in the right place, although it is still very cool =)

Fox
Mar 8th, 2001, 11:57 PM
Yeah, that's cool!

And thx for testing :)
(reminds me the error when splitting comment-lines)

Mar 8th, 2001, 11:59 PM
It also splits strings, which gives an error in kedaman's code (the first one).

Z.

Fox
Mar 9th, 2001, 12:15 AM
Done.



Caption = "Testing this new function to test the new-lines when using strings and " & _
"comments. It is a useless text that I write here but it should give you the idea " & _
"*hehe*" 'So this is a long comment originally written on one line...
'It dont need to tell you anything about the program since it's only a test of code.

'Code improved by vBulletin Tool (http://orion.spaceports.com/~mccloud/vbtool.zip) (Save as...)

Fox
Mar 9th, 2001, 10:51 AM
Phew, you're right. That looks bad :(

I made a little bugfix but I don't think I can make your ideas in this project. Just because I don't have the time ;) Best is if you disable the newline option... well I planned to make a new version from the beginning as soon as I got more time.

(You can set the indenting since 1.0.12, see options)

However, to colorize code it works fine ^_^

Technocrat
Mar 9th, 2001, 11:13 AM
Damnit Kidman you make me sick. You are just to damn good at this stuff. I think you and Megatron should just go live on an island somewhere making some cool software for us. :D

Chris
Mar 9th, 2001, 11:27 AM
kedaman, cool man! Are you an expert in math & physic huh... :)

Chris
Mar 9th, 2001, 11:33 AM
Fox, juz wanna to know what does the vbBulletin Tools do?

pranavdesai
Mar 9th, 2001, 11:47 AM
you are simply the best

Fox
Mar 9th, 2001, 12:10 PM
It formats the code as shown above. (adds color tags, upper-cases keywords and some other options)

kedaman
Mar 9th, 2001, 01:22 PM
Ok i turned of the auto wrapping thing, and now it shows as it should.

Now the previous versions wasn't really why i made this app at all, they look cool but that wasn't the point. The point was to show how the electric field lines are going, and i think the one i edited above was the best version of it. Have a look at that one too ;)

The guts behind isn't that complicates as you may think. Electric field is basically a vector:
Ê=sumof(k*Qi/r^2i*r^i)
where Qi is each charge and r^i is the base vector to it
which is applied in nested loops over a specified grid on the form.

Chris
Mar 10th, 2001, 04:29 AM
Fox, Juz try out the vBulletin Tool. it cool and if it can have a bigger Editor screen will be better still :))

Fox
Mar 10th, 2001, 05:58 AM
I'll remember that for further versions, thx.