Option Explicit
'KedamansChargesandElectricFieldDemo
' 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 (Save as...)
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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?=
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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 (Save as...)
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)
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.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com
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.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.