Sound Machines

Sound Machines preview image

3 collaborators

Uri_dolphin3 Uri Wilensky (Author)
79107734_n00-1 Seth Tisue (Author)
Turtlezero2-white-048 James Steiner (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 372 times • Downloaded 68 times • Run 3 times
Download the 'Sound Machines' modelDownload this modelEmbed this model

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


WHAT IS IT?

This model shows one way turtles can make interesting and varied sounds, or if you like, music. It uses some simple physics to make "machines" that twist, spin, turn, twitch, and bounce. When a part of the machine touches a wall, ceiling, or floor, it makes a sound. The pitch of the sound depends on the location of the touch.

You can start with a standard machine, or generate a random one. You can change and build machines yourself, by changing the characteristics of each part. You can sit back and let the machines play themselves, or you can use the mouse to move them around to control the sound yourself.

HOW IT WORKS

The machines are made up of levers. Levers can be different sizes and are pulled down by gravity (in proportion to their size) and subject to friction.

Each lever has one or two "hooks" to connect it to adjacent levers. Each lever rather simple-mindedly tries to move and rotate to keep its hooks attached (or at least pointing towards) its neighbors' hooks.

Some levers have additional constraints. A lever can be fixed in position so it can't move. It can also rotate, as if powered by a motor.

The rules aren't perfect; for example, sometimes the levers separate. Nonetheless, the behavior is often surprisingly realistic, and is rich enough to generate interesting motion which generates interesting sounds.

HOW TO USE IT

Press one of the SETUP... buttons to create a machine. If you want, change NUM-LEVERS first to get more or fewer levers.

Press GO to start the machine going. You should start hearing sounds, although if your machine never touches the wall (or ceiling or floor), you won't hear anything.

You can use the mouse to select a lever by clicking on it, or to move a lever by dragging it. The selected lever has a circle around it.

Once you have selected a lever, a variety of controls on the left let you change that lever's properties. They are not described in detail here; play with him and see for yourself what they do.

Some parameters affecting the entire system are on the bottom left and the right. F is friction, G is gravity. There are also controls for spin.

You can use the INSTRUMENT slider to pick a different musical instrument for the levers to play.

If you make a machine you especially like, you can use Export World and Import World on the File menu to save it out and load it back in again.

THINGS TO NOTICE

The simple rules followed by the levers produce some quite realistic-looking behavior.

Some machines don't do anything. Other machines make simple, repetitive motions. And others are wildly chaotic.

THINGS TO TRY

Try all of the different SETUP buttons.

Try all of the lever controls on the left.

Explore the effect of the parameters on the right.

See if you can make machines which are somewhat repetitive, but also somewhat unpredictable and chaotic. Sometimes these make the most pleasing "music".

Using the command center, tell the turtles to put their pens down (using the pen-down command, abbreviated pd). This generates some pleasing patterns. Use clear-drawing (abbreviated cd) to start a new drawing.

EXTENDING THE MODEL

There are endless possibilities for how the same basic physics engine could be used to generate sound. The levers could:

  • Play different instruments, instead of all the same one.
  • Make percussion sounds in addition pitched sounds.
  • Make sounds even when they don't hit the wall
  • Make sounds that depend on their characteristics

And so on.

How "normal" and "musical" can you make the model sound? Currently the rules of the model aren't based on scales or tonality; by choosing pitches more carefully, you might be able to produce music which is less strange, more like music composed by humans. You could also try to produce more regular rhythms by timing sounds to coincide with a regular beat.

Or, you could take the opposite approach, and see how wild, different, and unusual can you make the sounds. Make something that doesn't sound like anything you've ever heard before!

NETLOGO FEATURES

The model uses NetLogo's sound extension. The sound extension is described in the Sound section of the NetLogo User Manual.

RELATED MODELS

  • Beatbox
  • Composer
  • GasLab With Sound
  • Sound Workbench
  • Percussion Workbench

CREDITS AND REFERENCES

This model is a streamlined variant of the Machines 2005 model created and submitted to the NetLogo User Community Models repository by James Steiner. Machines 2005 is available from http://ccl.northwestern.edu/netlogo/models/community/machines-2005.

Thanks to James for creating an earlier version which was silent; Seth Tisue for first adding sound to it; and James again for his further improvements, and for releasing the model under a Creative Commons License.

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

  • Wilensky, U. (2005). NetLogo Sound Machines model. http://ccl.northwestern.edu/netlogo/models/SoundMachines. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2005 Uri Wilensky. Includes code by James P. Steiner.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Comments and Questions

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

Click to Run Model

extensions [sound]

globals [
  selected    ;; lever that is currently selected
  dragged     ;; lever that is currently being dragged
]

breed [levers lever]
levers-own [
  neighbor1 neighbor2  ;; each holds an adjacent lever (or nobody)
  fixed?               ;; if true, lever only turns, never changes position
  spin                 ;; -1, 0, or 1
  len                  ;; this times SCALE slider equals size
  new-xcor new-ycor    ;; next values for xcor and ycor
  new-heading          ;; next value for heading
  xvel yvel            ;; x and y velocities
]

;;;
;;; SETUP PROCEDURES
;;;

to setup-begin
  clear-all
  set-default-shape levers "lever"
  create-ordered-levers num-levers [
    set heading 180
    set new-xcor 0
    set ycor ((who / num-levers) * world-height + min-pycor ) * -0.8
    set new-ycor ycor
    set fixed? false
    set len 0.5
    set neighbor1 turtle (who - 1)
    set neighbor2 turtle (who + 1)
  ]
  ask lever 0 [ set fixed? true ]
end 

to setup-dangle
  setup-begin
  ask turtle (num-levers - 4) [
    set len len * 2
    set spin 1
  ]
  setup-finish
end 

to setup-finish
  set selected last sort levers  ;; select last lever
  ask levers [ lever-display ]
  reset-ticks
end 

to setup-chaos-tentacle
  setup-begin
  ask levers
    [ set len (num-levers - who) * 0.1
      set spin (who mod 2) * 2 - 1
    ]
  ask first sort levers
    [ set new-xcor 0
      set new-ycor 0
      setxy 0 0
      set fixed? true
    ]
  setup-finish
end 

to setup-crazy-machine
  setup-begin
  ask levers
    [ ; choose random location, in the inner area of the world
      set new-xcor (random-float 1.6 - 0.8) * max-pxcor
      set new-ycor (random-float 1.6 - 0.8) * max-pycor
      setxy new-xcor new-ycor
      set fixed? (random 5 = 0)
      set spin one-of [-1 0 1]
      set len precision (0.5 + 0.5 * random 4) 1
      lever-display
    ]
  setup-finish
end 

;;;
;;; RUNTIME PROCEDURES
;;;

to go
  ask levers [ monitor-mouse ]
  ask levers [ lever! ]
  ask levers [ lever-display ]
  tick
end 

to lever!
  ifelse self = dragged
  [ ; if being dragged, then go there the mouse tells you
    set new-xcor mouse-xcor
    set new-ycor mouse-ycor
  ]
  [
    if not fixed?
    [ set xvel (xvel * f) + ((n1x2 - x1) + (n2x1 - x2)) * 0.5
      set yvel (yvel * f) + ((n1y2 - y1) + (n2y1 - y2)) * 0.5
      set yvel yvel - g * len
      set new-xcor xcor + xvel
      set new-ycor ycor + yvel
      if abs new-xcor > max-pxcor [ set xvel xvel * -0.99
                                    set new-xcor max-pxcor * sign new-xcor + xvel
                                    bonk! ycor ]
      if abs new-ycor > max-pycor [ set yvel yvel * -0.99
                                    set new-ycor max-pycor * sign new-ycor + yvel
                                    bonk! xcor ]
    ]
  ]
  ; calculate new heading of lever
  ; if node2 of neighbor1 is overlapping center, keep same heading
  ; otherwise, find heading to hook 2 of neighbor1
  let a 180 + heading
  let b heading
  if distancexy n1x2 n1y2 > 0
    [ set a 180 + towardsxy n1x2 n1y2 ]
  ; likewise hook 1 of neighbor2
  if distancexy n2x1 n2y1 > 0
    [ set b towardsxy n2x1 n2y1 ]
  ; use trig to take mean of a and b
  set new-heading atan (sin a + sin b)
                       (cos a + cos b)
                  + spin * spin-speed
end 

to lever-display
  setxy new-xcor new-ycor
  set heading new-heading
  set size 2 * scale * len
  let -s ""
  ifelse self = selected
  [ set -s "-s"
    let new-label (word "selected: " who " - " (precision len 2) " ")
    ask patch max-pxcor max-pycor [ set plabel new-label ]
    set label (word who " - " (precision len 2) " "  " ---->     ")
  ]
  [ set label "" ]
  set shape (word "lever"
                  ifelse-value fixed? ["-f"] [""]
                  item (spin + 1) ["-ws" "" "-cw"]
                  -s)
end 

;; lever procedures; these report the x and y coordinates
;; of this lever's hooks

to-report x1 report xcor - dx * scale * len end

to-report y1 report ycor - dy * scale * len end

to-report x2 report xcor + dx * scale * len end

to-report y2 report ycor + dy * scale * len end

;; lever procedures; these report the x and y coordinates
;; of our neighbor's hooks. if no neighbor, use own hook.

to-report n1x1 ifelse neighbor1 = nobody [ report x2 ] [ report [x1] of neighbor1 ] end

to-report n1y1 ifelse neighbor1 = nobody [ report y2 ] [ report [y1] of neighbor1 ] end

to-report n1x2 ifelse neighbor1 = nobody [ report x1 ] [ report [x2] of neighbor1 ] end

to-report n1y2 ifelse neighbor1 = nobody [ report y1 ] [ report [y2] of neighbor1 ] end

to-report n2x1 ifelse neighbor2 = nobody [ report x2 ] [ report [x1] of neighbor2 ] end

to-report n2y1 ifelse neighbor2 = nobody [ report y2 ] [ report [y1] of neighbor2 ] end

to-report n2x2 ifelse neighbor2 = nobody [ report x1 ] [ report [x2] of neighbor2 ] end

to-report n2y2 ifelse neighbor2 = nobody [ report y1 ] [ report [y2] of neighbor2 ] end

to-report sign [a]
  ifelse a = 0
    [ report 0 ]
    [ ifelse a < 0 [ report -1 ]
                   [ report 1 ] ]
end 

;;;
;;; SELECTION & DRAGGING PROCEDURES
;;;

to monitor-mouse
  let mouse-here? abs (mouse-xcor - xcor) < scale / 2 and
                  abs (mouse-ycor - ycor) < scale / 2
  ifelse mouse-here?
  [ if color != white [ set color white ] ]
  [ if color = white  [ set color item (who mod 14) base-colors ] ]
  ifelse mouse-down?
  [ if dragged = nobody and mouse-here?
    [ set dragged self
      set selected self
    ]
  ]
  [ set dragged nobody ]
end 

to select-lever [which-lever]
  let new lever (which-lever + [who] of selected)
  if new != nobody [ set selected new ]
end 

;;;
;;; SOUND PROCEDURES
;;;

to bonk! [coordinate]
  sound:play-note my-instrument (pitch coordinate) 90 0.05
end 

to-report pitch [coordinate]  ;; lever procedure
  report 16 + round (96 * (coordinate + max-pxcor) / world-width)
end 

to-report my-instrument  ;; lever procedure
  report item ((who + instrument) mod length sound:instruments)
              sound:instruments
end 


; Copyright 2005 Uri Wilensky. Includes code by James P. Steiner. 
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Sound Machines Download this version

Attached files

File Type Description Last updated
Sound Machines.png preview Preview for 'Sound Machines' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.