Archive for January, 2009

Audiovisual relationships

Monday, January 26th, 2009

The last session on Audiovisual relationships covered topics in sound/image relationships, sound in film, cognition, perception and meaning.

Here’s a link to more information on the double flash illusion, including Quicktime demos.

Double Flash Illusion

In addition, check out this demo of the “McGurk Effect”, which is a good example of how sound affects vision. You won’t believe it at first.

There’s a great deal of information on “cross-modal interaction” (when “sense” information gets combined). Here’s a link to a book that’s in the college library – Audiovision: Sound on Screen by Michel Chion.

This is a great book and well worth reading. It should be pointed out that it was published in 1994, before sound-image illusion research was popularised. He’s a composer, film-maker and philosopher – not a scientist.

PDF Download    Send article as PDF to

A worked example of the Boids program

Wednesday, January 21st, 2009

Here is my worked example of the Boids program. I’ve rewritten it to demonstrate the use of PVectors
Marco

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
 
// a class for representing Craig Reynolds' Boids
class Boid
{
  // the position and the velocities of boids
  // are represented as vectors
  PVector Pos;
  PVector Vel;
 
  // boids have a size
  float Size = 10;
 
  // we limit the maximum speed of a boid
  float maxSpd = 3;
 
  // this is how close Boids can get to eachother
  // before they start avoiding
  float distance_threshold = 40;
 
  // the relative weightings of all
  // the behaviours
  float separation_weight = 0.1;
  float alignment_weight = 0.1;
  float cohesion_weight = 0.01;
  float following_weight = 0.1;
 
  // the constructor, set up the member variables
  Boid()
  {
     Pos = new PVector(random(Size, width-Size),random(Size, height-Size));
     Vel = new PVector(random(-2, 2), random(-2, 2));
  }
 
  // make sure that boids bounce off the edges of
  // the screen
  void wall()
  {
    // because the Boid's velocity might have changed since it went off
    // screen it might be heading back anyway
    // so we check if the Boid is off screen and is heading further
    // off screen, if so we reverse its velocity
 
     if (Pos.x < Size && Vel.x < 0)
       Vel.x = - Vel.x;
     if (Pos.x > width - Size && Vel.x > 0)
       Vel.x = - Vel.x;
     if (Pos.y < Size && Vel.y < 0)
       Vel.y = - Vel.y;
     if (Pos.y > height - Size && Vel.y > 0)
       Vel.y = - Vel.y;
  }
 
  // follow the mouse pointer
  // give the Boid some velocity in the direction
  // of the mouse pointer
  // (the magnitude of this velocity is given
  // by the weighting of this behaviour)
  PVector following()
  {
      // get the mouse position as a vector
      PVector mouse = new PVector(mouseX, mouseY);
 
      // get the relative position and normalise it
      PVector diff = PVector.sub(mouse, Pos);
      diff.normalize();
 
      // this normalised position is the velocity we
      // add on (the magnitude is constant and given by the weighting)
      return diff;
  }
 
  // get the boid to move away from nearby boids
  // checks if any boids are nearer than a threshold
  // if so it finds the nearest one and steers away
  PVector separation()
  {
     // this is the change we'll make to the velocity
     PVector vel_change = new PVector(0, 0);
 
     // we use this to find the nearest boid
     float minDistance = 1000;
 
     // search all other boids
     for (int i = 0; i < boids.length; i++)
     {
       // make sure you don't avoid yourself
       // "this" represents the current object
        if (boids[i] == this)
          continue;
 
        // work out the relative position of the boid
        PVector diff = PVector.sub(boids[i].Pos, Pos);
        // the magnitude is the distance between boids
        float d = diff.mag();
 
        // if the distand is less than the threshold
        if (d < distance_threshold)
        {
           // scale the distnace by the
           // distance_threshold, so that
           // the separation values are high
           d = d/distance_threshold;
 
           // if the distance is less than the shortest
           // distance you've already found
            if (d < minDistance)
            {
 
 
              // set diff's length to be equal to
              // the inverse square distance
              // the minus sign means it's in the
              // opposite direction from the other
              // boid
              diff.normalize();
              diff.mult(-1.0/(d*d));
 
              // set the avoidance velocity to diff
              vel_change.set(diff);
              // set the minimum found distance to this one
              minDistance = d;
 
 
              // comment the two last lines and uncomment this one
              // to get a different effect
              //vel_change.add(diff);
            }
        }
     }
     return vel_change;
  }
 
  // keep the boids together
  // move the boid to the average position
  // of the flock
  PVector cohesion()
  {
     // find the average position
 
     // start at 0, 0
     PVector average = new PVector(0,0);
     // go through all the boids
     for (int i = 0; i < boids.length; i++)
     {
       // check you aren't testing yourself
        if (boids[i] == this)
          continue;
 
        // divide the position by the number of biods (minus you)
        // and add it to the average
        average.add(PVector.div(boids[i].Pos, float(boids.length-1)));
 
     }
     // the velocity change is proportional
     // to the difference between the average and your current
     // position
     return PVector.sub(average, Pos);
  }
 
  // get all the boids going in roughly the same direction
  // change the boids velocity so it is nearer the average
  // velocity
  // works the same as cohension but with velocities
  PVector alignment()
  {
    // calculate the average velocity
    // works the same as above
     PVector average = new PVector(0,0);
     for (int i = 0; i < boids.length; i++)
     {
        if (boids[i] == this)
          continue;
 
        average.add(PVector.div(boids[i].Vel, float(boids.length-1)));
 
     }
     // the velocity change is proportional to the difference
     // between the average and the current velocity
     return PVector.sub(average, Vel);
  }
 
  // update teh boids position
  // do all the above behaviours
  // and add their velocities proportional to their
  /// weightings
  void update()
  {
 
    // Add the result of each behaviour to the velocity
    // multiply it by its weighting before adding it
    Vel.add(PVector.mult(following(),  following_weight));
    Vel.add(PVector.mult(alignment(),  alignment_weight));
    Vel.add(PVector.mult(cohesion(),   cohesion_weight));
    Vel.add(PVector.mult(separation(), separation_weight));
 
 
    // the wall behaviour bounces it off the edges
    wall();
 
    // make sure that the speed doesn't exceed
    // the maximum
 
    // the speed is the magnitude of the velocity
    float speed = Vel.mag();
    // if its more than the max set it to the max
    if (speed > maxSpd)
    {
      // set the magnitude of Vel to maxSpd
      Vel.normalize();
      Vel.mult(maxSpd);
    }
 
     // add the current velocity to the postion
     Pos.add(Vel);
  }
 
 // draw the boid
 void draw()
 {
    strokeWeight(4);
    ellipseMode(CENTER);
    ellipse(Pos.x, Pos.y, Size, Size);
 }
 
}
 
// declare the array of boids
Boid boids[];
 
void setup()
{
  size(500, 500);
 
  // create a new array of boids
  boids = new Boid[40];
 
  // put a new boid object in each place in
  // the array
  for (int i = 0; i < boids.length; i++)
   {
     boids[i] = new Boid();
   }
}
 
void draw()
{
 background(255);
 // update and then draw each boid
 for (int i = 0; i < boids.length; i++)
 {
    boids[i].update();
    boids[i].draw();
 }
}
Create PDF    Send article as PDF to

Creative Computing lecture term 2 week 1

Wednesday, January 14th, 2009

CC_wk11.ppt CC_wk11.doc
Hi,
here are the notes from today’s lecture (and some that will form part of next weeks).
Marco

PDF Download    Send article as PDF to

Creativity on the BBC

Monday, January 12th, 2009

The BBC news website has some great videos up at the moment that are relevant to Creative Computing.

First, a film about creativity

news.bbc.co.uk/1/hi/england/devon/7824071.stm

Secondly, a great installation on Glastonbury Tor

news.bbc.co.uk/1/hi/england/7824531.stm

Take a look.

PDF Download    Send article as PDF to