Results 1 to 17 of 17

Thread: Testing fox vbtool thing. Btw, look at the amazing Graphics: Electric Field demo

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Put it all in a form, run and enjoy:

    Code:
    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.

  2. #2
    Guest
    kedaman, You Rock

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Very cool
    Harry.

    "From one thing, know ten thousand things."

  4. #4

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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?=
    Attached Files Attached Files
    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.

  5. #5
    Guest
    I liked the other one better. The new one doesnt put the holes/spikes in the right place, although it is still very cool =)

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yeah, that's cool!

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

  7. #7
    Guest
    It also splits strings, which gives an error in kedaman's code (the first one).

    Z.

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Done.

    Code:
    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...)

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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 ^_^
    Last edited by Fox; Mar 9th, 2001 at 12:03 PM.

  10. #10
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    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


  11. #11
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    kedaman, cool man! Are you an expert in math & physic huh...

  12. #12
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Fox, juz wanna to know what does the vbBulletin Tools do?

  13. #13
    Junior Member pranavdesai's Avatar
    Join Date
    Feb 2001
    Location
    india
    Posts
    24

    wow!

    you are simply the best
    pmd

  14. #14
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    It formats the code as shown above. (adds color tags, upper-cases keywords and some other options)

  15. #15

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  16. #16
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Fox, Juz try out the vBulletin Tool. it cool and if it can have a bigger Editor screen will be better still )

  17. #17
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I'll remember that for further versions, thx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width