DevLabs > DevLabs Forums > Small Basic > 10 particle random walk
Ask a questionAsk a question
 

General Discussion10 particle random walk

  • Thursday, November 05, 2009 2:10 PMNuno.Pereira Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello, this is a test with random walk. I couldn't set N>10...memory problems. You can check the code here:
     http://smallbasic.com/program/?ZJQ520

    best regards

All Replies

  • Thursday, November 05, 2009 8:00 PMlitdevAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The main problem you have is:

    y[y ] = Math.GetRandomNumber(gw_height - 2 * radius)

    Should be:

    y[k ] = Math.GetRandomNumber(gw_height - 2 * radius)

    The only other comment is that shapes are drawn from the top left corner so to centre shapes on a coordinate we often do the following:

    Shapes.Move(particle[k], x[k]-radius, y[k]-radius)


    I added some paths behind 100 particles. This shows that the random walk is preferentially diagonal since x_step and y_step are relative to the window size.



    GraphicsWindow.PenColor = "#33ffffff" 'partially transparent white
    GraphicsWindow.PenWidth = 1
    While (FlagRun = 1)
    ...
        xlast = x[k]
        ylast = y[k]
        x[k] = x[k] + dx * signal
        y[k] = y[k] + dy * signal
        GraphicsWindow.DrawLine(xlast,ylast,x[k],y[k])
        Shapes.Move(particle[k], x[k], y[k])

  • Thursday, November 05, 2009 9:30 PMNuno.Pereira Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello lidev

    Thanks a lot for your comments! What a bug :-) I made some changes after the post but I didn't look at that problem. I'm going to correct the code and make some changes. Version 2.0 will be with particle interaction.

    Have a nice day/night

    n.p