ok, sweet, thanks philo - the crashes appeared to be something to do with OpenGL.
so, here is the basis of the code, which does exactly what I want - #happy
now I just need to add it to my bigger sketch, should be easy enough now i understand the principles.
does a kinda alright effect too, when you run the code and press and hold any key :)
Thanks for the pointers, much appreciated!
S
- import processing.opengl.*;
- Vertex v[];
- Pixar pix[];
- boolean updateRecord;
- long change = 0;
- void setup(){
- size(screen.width, screen.height,OPENGL);
- pix = new Pixar[width*height];
- for(int i=0; i< width*height; i++){
- pix[i]=new Pixar(0,0,0);
- }
- v=new Vertex[4];
- for(int i=0; i< 4; i++){
- float x = random(0,width);
- float y = random(0,height);
- v[i]=new Vertex(x,y);
- }
- }
- void draw(){
- background(0);
- view(255,0,0,125);
- if(millis()-change>100){
- for(int i=0; i< 4; i++){
- float x = random(0,width);
- float y = random(0,height);
- v[i]=new Vertex(x,y);
- }
- updateRecord = true;
- change = millis();
- }
- }
- void view(int a, int b, int c, int d){
- normShape(a,b,c,d);
- offlineShape(a,b,c,d);
- }
- void normShape(int a, int b, int c, int d){
- beginShape();
- fill(a,b,c,d);
- noStroke();
- for(int i=0; i<4; i++) {
- if((v[i].x>0)&&(v[i].y>0)){
- vertex(v[i].x,v[i].y);
- }}
- endShape(CLOSE);
- }
- void offlineShape(int a, int b, int c, int d){
- color seen = color(a,b,c,d);
- PGraphics offline = createGraphics(width, height, P2D);
- offline.beginDraw();
- offline.beginShape();
- offline.fill(seen);
- offline.noStroke();
- for(int i=0; i<4; i++) {
- if((v[i].x>0)&&(v[i].y>0)){
- offline.vertex(v[i].x,v[i].y);
- }}
- offline.endShape(CLOSE);
- offline.endDraw();
-
- offline.loadPixels();
- loadPixels();
- if (updateRecord){
- for (int i = 0; i < offline.pixels.length; i++) {
- color check = offline.pixels[i];
- if(check != 0){
- pix[i].x = i % width;
- pix[i].y = i / width;
- pix[i].count++;
- }}
- updateRecord = false;
- }
-
- if(keyPressed){
- for (int i = 0; i < offline.pixels.length; i++) {
- if (pix[i].count>0){
- int sat = 255;
- int hugh = 0;
- int specstart = 110;
- int specend = 30;
- if(pix[i].cool){ hugh = specstart + pix[i].count; sat = 255;}
- if (pix[i].medium){ hugh = (specstart + pix[i].count) - 255 ; sat = 255;}
- if(pix[i].hot){ hugh = specend; sat = 255-(pix[i].count - (255-specstart)+specend);}
-
- if(sat <0) sat = 0;
- if((hugh>254)&&(pix[i].cool)){ pix[i].cool = false; pix[i].medium = true;}
- else if((hugh>specend)&&(pix[i].medium)){ pix[i].medium = false; pix[i].hot = true;}
-
- colorMode(HSB);
- color record = color(hugh, sat, 255);
- pixels[i] = record;
- colorMode(RGB);
- }}}
-
- offline.updatePixels();
- updatePixels();
- }
- class Vertex{
- float x,y;
- Vertex(float x, float y){
- this.x = x;
- this.y = y;
- }
- void set(float x, float y){
- this.x = x;
- this.y = y;
- }}
-
- class Pixar{
- boolean cool = true;
- boolean medium = false;
- boolean hot = false;
- int x,y;
- int count;
- Pixar(int a, int b, int c){
- x = a;
- y = b;
- count = c;
- }
- }