buzz_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
buzz_examples [2016/09/02 13:46] – [Square Pattern Formation] ilpincybuzz_examples [2018/03/18 22:58] (current) root
Line 1: Line 1:
 ====== Buzz Example Gallery ====== ====== Buzz Example Gallery ======
  
-===== Generic examples ====== +===== Calculation of a Distance Gradient =====
- +
-==== Calculation of a Distance Gradient ====+
  
 The aim of this code is to have a group of robots form a distance gradient from a source. The aim of this code is to have a group of robots form a distance gradient from a source.
Line 42: Line 40:
 </code> </code>
  
-==== Hexagonal Pattern Formation ====+===== Hexagonal Pattern Formation =====
  
 Hexagonal patterns can be formed in a simple way by mimicking particle interaction. A simple model of particle interaction is the [[https://en.wikipedia.org/wiki/Lennard-Jones_potential|Lennard-Jones potential]], which we use in the following code in a slightly modified way. Instead of the big exponents (12 and 6), we use the exponents 4 and 2, which give us smaller but more manageable numbers. Hexagonal patterns can be formed in a simple way by mimicking particle interaction. A simple model of particle interaction is the [[https://en.wikipedia.org/wiki/Lennard-Jones_potential|Lennard-Jones potential]], which we use in the following code in a slightly modified way. Instead of the big exponents (12 and 6), we use the exponents 4 and 2, which give us smaller but more manageable numbers.
Line 77: Line 75:
   var accum = neighbors.map(lj_vector).reduce(lj_sum, math.vec2.new(0.0, 0.0))   var accum = neighbors.map(lj_vector).reduce(lj_sum, math.vec2.new(0.0, 0.0))
   if(neighbors.count() > 0)   if(neighbors.count() > 0)
-    math.vec2.scale(accum, neighbors.count())+    math.vec2.scale(accum, 1.0 / neighbors.count())
   # Move according to vector   # Move according to vector
   goto(accum.x, accum.y)   goto(accum.x, accum.y)
Line 96: Line 94:
 </code> </code>
  
-==== Square Pattern Formation ====+===== Square Pattern Formation =====
  
 To form square lattice, we can build upon the previous example. The insight is to notice that, in a square lattice, we can color the nodes forming the lattice with two shades, e.g., red and blue, and then mimic the [[http://www.metafysica.nl/turing/nacl_complex_motif_4.gif|crystal structure of kitchen salt]]. In this structure, if two nodes have different colors, they stay at a distance //D//; if they have the same color, they stay at a distance //D// * sqrt(2). To form square lattice, we can build upon the previous example. The insight is to notice that, in a square lattice, we can color the nodes forming the lattice with two shades, e.g., red and blue, and then mimic the [[http://www.metafysica.nl/turing/nacl_complex_motif_4.gif|crystal structure of kitchen salt]]. In this structure, if two nodes have different colors, they stay at a distance //D//; if they have the same color, they stay at a distance //D// * sqrt(2).
  
-With this idea in mind, the following script divided the robots in two swarms: those with an even id and those with an odd id. Then, using ''neighbors.kin()'' and ''neighbors.nonkin()'', the robots can distinguish which distance to pick and calculate the correct interaction vector.+With this idea in mind, the following script divides the robots in two swarms: those with an even id and those with an odd id. Then, using ''neighbors.kin()'' and ''neighbors.nonkin()'', the robots can distinguish which distance to pick and calculate the correct interaction vector.
  
 <code buzz square.bzz> <code buzz square.bzz>
Line 139: Line 137:
   accum = neighbors.nonkin().map(lj_vector_nonkin).reduce(lj_sum, accum)   accum = neighbors.nonkin().map(lj_vector_nonkin).reduce(lj_sum, accum)
   if(neighbors.count() > 0)   if(neighbors.count() > 0)
-    math.vec2.scale(accum, neighbors.count())+    math.vec2.scale(accum, 1.0 / neighbors.count())
   # Move according to vector   # Move according to vector
   goto(accum.x, accum.y)   goto(accum.x, accum.y)
Line 162: Line 160:
 } }
 </code> </code>
- 
-===== Wheeled-robot Specific ===== 
- 
-TODO 
- 
-===== Flying-robot Specific ===== 
- 
-TODO 
  • buzz_examples.1472823962.txt.gz
  • Last modified: 2016/09/02 13:46
  • by ilpincy