/* Kohonen Neural net demo. Sorts an image into it's constituent colours. This example can be adapted to sort all sorts of data into groups. Adapted from tutorial at: http://www.ai-junkie.com/ann/som/som1.html */ PFont font; PImage pic; Cortex cortex; Buttons [] button; int choice = -1; boolean go = false; void setup(){ size(640,640,P3D); pic = loadImage("1.gif"); cortex = new Cortex(); int col = #EEEEEE; button = new Buttons[2]; button[0] = new Buttons(128,400,64,20,col,"train",null); button[1] = new Buttons(192,400,64,20,col,"reset",null); font = loadFont("BitstreamVeraSans-Roman-48.vlw"); textFont(font,14); noStroke(); } void draw(){ image(pic,0,0,width,height); cortex.draw(); if (go) cortex.train(); for (int i = 0; i < button.length; i++){ button[i].draw(); } } void mousePressed(){ for(int i = 0; i < button.length; i++){ if(button[i].over()){ choice = i; } } switch(choice){ case 0: go = !go; break; case 1: cortex = new Cortex(); break; } }