Real Time Motion v01

Real Time Motion v01 preview image

1 collaborator

Default-person walter stroup (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.2 • Viewed 24 times • Downloaded 4 times • Run 0 times
Download the 'Real Time Motion v01' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals
[
xlist
ylist
mxlist
mylist
x1_list
x2_list
y1_list
y2_list
vx_list
vy_list

smoothx
smoothy
smooth_x1
smooth_x2
smooth_y1
smooth_y2
smooth_vx
smooth_vy


times
mytime
]

to setup
  ca
  ask patches [set pcolor white]
  set mytime 0
  set xlist []
  set ylist []
end 

to turtle-draw
  reset-ticks
  ifelse mouse-down?
    [ ;; first make sure there's a turtle (if the user just pressed
      ;; the mouse button, there won't be yet)
      if not any? turtles
        [ ask patch mouse-xcor mouse-ycor
            [ sprout 1
                [ pen-down
                  set shape "circle"
                  ;;; set pen-size 2 ht ] ] ]
                  set pen-size 4  ] ] ]
      ;; now that we're sure we have a turtle, we ask it to move
      ;; towards the mouse

      ask turtles [

        set mxlist [] set mylist [] set times []  set x1_list [] set x2_list [] set y1_list [] set y2_list [] set vx_list [] set vy_list []
        repeat smoothing [set mxlist lput mouse-xcor mxlist set mylist lput mouse-ycor mylist]
        set smoothx mean mxlist set xlist lput smoothx xlist
        set smoothy mean mylist set ylist lput smoothy ylist
        set times lput mytime times

        if mytime > 5 [  ; changed from 6
          ;set  x1_list lput (item (mytime - 5) xlist) x1_list
          set  x1_list lput (item (mytime - 4) xlist) x1_list
          set  x1_list lput (item (mytime - 3) xlist) x1_list
          set  x1_list lput (item (mytime - 2) xlist) x1_list
          set  x1_list lput (item (mytime - 1) xlist) x1_list


          ;set  x2_list lput (item (mytime - 4) xlist) x2_list
          set  x2_list lput (item (mytime - 3) xlist) x2_list
          set  x2_list lput (item (mytime - 2) xlist) x2_list
          set  x2_list lput (item (mytime - 1) xlist) x2_list
          set  x2_list lput (item (mytime - 0) xlist) x2_list

          set smooth_x1 mean x1_list
          set smooth_x2 mean x2_list

          ; delta t is 1 unit so velocity is x2-x1 / 1
          set smooth_vx (smooth_x2 - smooth_x1) / 1






        ]
        ;smooth_x1 mean [

        ;;;item index list

        set-current-plot "graph_1"
        set-current-plot-pen "Pos_X"
        if mytime = 6 [plot-pen-up plotxy mytime smoothx plot-pen-down]
        if mytime > 5 [plotxy mytime smoothx]

       if graph_2? [
        set-current-plot "graph_2"
        set-current-plot-pen "Vel_X"
        ;if mytime = 6 [plot-pen-up plotxy mytime smooth_vx plot-pen-down]
        if mytime = 6 [plot-pen-up plotxy mytime smooth_vx]
        if mytime > 7 [plot-pen-down plotxy mytime smooth_vx ]
        ]
      ]

      ask turtles
        ;[ if distancexy mouse-xcor mouse-ycor > 0
            ;[ facexy mouse-xcor mouse-ycor
      [ if distancexy smoothx smoothy > 0
        [ facexy smoothx smoothy
              fd 0.4  ;; 0.4 gives nice smooth lines
              display ] ]
     set mytime mytime + 1
   ]

  ;;========================
    ;; once the user releases the mouse button, we don't need the
    ;; turtle anymore
    [
     set-current-plot "graph_1"
     set-current-plot-pen "Pos_X"
     plot-pen-up

     set-current-plot "graph_2"
     set-current-plot-pen "Vel_X"
     plot-pen-up


     ;plot-pen-reset

     clear-turtles
     set mytime 0
      set xlist []
      set ylist []
    ]
end 

There is only one version of this model, created 10 months ago by walter stroup.

Attached files

File Type Description Last updated
Real Time Motion v01.png preview Preview for 'Real Time Motion v01' 10 months ago, by walter stroup Download

This model does not have any ancestors.

This model does not have any descendants.