Alis Blog Processing and EEG



For this Processing sketch, we are going to start with a simple but beautiful generative design by Matt Pearson and modify the sketch to inject the Attention and Meditation values derived from the Mindset Mobile Headset.

Neurosky Mindwave Processing Sketch 03a

If we look at the source code, we are going to see that the randomness and noise applied to the lines that are drawn in every frame, make this generative pattern more and more interesting as the sketch runs.

//================================= global vars
int _num = 10;
float _angnoise, _radiusnoise;
float _xnoise, _ynoise;
float _angle = -PI/2;
float _radius = 100;
float _strokeCol = 254;
//================================= init
void setup() {
size(500, 500);
_angnoise = random(10);
_radiusnoise = random(10);
_xnoise = random(10);
_ynoise = random(10);
void clearBackground() {
//================================= frame loop
void draw() {
_radiusnoise += 0.005;
_radius = (noise(_radiusnoise) * 550) +1;
_angnoise += 0.005;
_angle += (noise(_angnoise) * 6) - 3;
if (_angle > 360) { _angle -= 360; }
if (_angle < 0) { _angle += 360; }
// wobble centre
_xnoise += 0.01;
_ynoise += 0.01;
float centreX = width/2 + (noise(_xnoise) * 100) - 50;
float centreY = height/2 + (noise(_ynoise) * 100) - 50;
float rad = radians(_angle);
float x1 = centreX + (_radius * cos(rad));
float y1 = centreY + (_radius * sin(rad));
// opposite
float opprad = rad + PI;
float x2 = centreX + (_radius * cos(opprad));
float y2 = centreY + (_radius * sin(opprad));
_strokeCol += _strokeChange;
if (_strokeCol > 254) { _strokeChange *= -1; }
if (_strokeCol < 0) { _strokeChange *= -1; }
stroke(_strokeCol, 60);
line(x1, y1, x2, y2);
int _strokeChange = -1;
//================================= interaction
void mousePressed() { clearBackground(); }


To explain a bit more, in every frame there is a line drawn. The rotation, the length and the lightness of the line are driven by the randomness and noise functions. As the visualization of the sketch evolves, new patterns start to emerge on the canvas.

Neurosky Mindwave Processing Sketch 03b

Now it is time to modify the sketch, simplify it temporarily and use the A/M Values to see the effect of them over the patterns generated. The first thing that we will do is to disable the wobble effect.

size(500, 500);
float centreX = width/2;
float centreY = height/2;


Neurosky Mindwave Processing Sketch 03b

Then we copy and paste the needed code from sketch 02 and initialize Neurosky in Processing.

Neurosky Mindwave Processing Sketch 03b

Just to see if the system is working, before any further modification, we are going to test the headset and connection. It is always a good idea to test the headset first with a simple sketch or the default Brainwave Visualizer program. Another point is when the Brainwave Visualizer is running in the background, the initial starting time of the sketch becomes faster as the Bluetooth connection will already be active.

Neurosky Mindwave Processing Sketch 03b

As we run the sketch, we get no error messages or warnings. We did not make any connection between the generated lines and the EEG device yet.

To make the first connection, we relate the radius of the lines with the attention value. The higher values of Attention will be translated as long lines and vice versa. We will also observe the attention value from the Brainwave Visualizer.

The second step is to relate the stroke color of the line with the Meditation level.

//_strokeCol += _strokeChange;
//if (_strokeCol &gt; 254) { _strokeChange *= -1; }
//if (_strokeCol &lt; 0) { _strokeChange *= -1; }
stroke(120,floor(meditation*(2.55)),120, 90);
line(x1, y1, x2, y2);


So higher Meditation levels will be represented by green and lower levels with purple. Higher Attention levels will be visualized by long lines and lower levels with short lines.

Neurosky Mindwave Processing Sketch 03b

This was only one way of injecting Attention and Meditation levels into any given sketch. By playing with and modifying the code, new ideas and sketches may appear based on the foundation discussed above.

You are welcome to share the sketches you come up with, as a comment to this post.

The final sketch file can be downloaded from here.