// occludingEdge_002 // by Phil Ayres // Two classes of occluding figures with differing attributes. // Qualitative time-based differences can be generated simply by altering the population sizes. // 04 November 2006 // Adapted from 'Brownian Motion' & 'Buttons' examples by REAS PopCtrlButton cullCtrl1, growCtrl1, cullCtrl2, growCtrl2; //, plusCtrl1, minusCtrl2, plusCtrl2; color currentcolor; boolean locked = false; PFont font; int popMax = 1000; int show = popMax/5; int show2 = popMax/10; int popInc = popMax/100; int lowRange = 15; int upRange = 25; int radius = 20; int xposCtrl; int yposCtrl; int default_fill = 255; int counter = 0; boolean initMsg = false; float[] ellR = new float[popMax]; float[] ax = new float[popMax]; float[] ay = new float[popMax]; float[] ellR2 = new float[popMax]; float[] bx = new float[popMax]; float[] by = new float[popMax]; void setup() { size(400, 300); xposCtrl = 15; yposCtrl = (height - 15); framerate(60); font = loadFont("TrebuchetMS-14.vlw"); textFont(font); int x = xposCtrl; int y = yposCtrl; int size = 12; boolean sign = false; color buttoncolor = color(255); color highlight = color(180); ellipseMode(CENTER); cullCtrl1 = new PopCtrlButton(x, y, size, buttoncolor, highlight, sign); x = xposCtrl + 20; y = yposCtrl; size = 12; sign = true; buttoncolor = color(255); highlight = color(180); growCtrl1 = new PopCtrlButton(x, y, size, buttoncolor, highlight, sign); x = xposCtrl + 90; y = yposCtrl; size = 12; sign = false; buttoncolor = color(255); highlight = color(245, 227, 67); cullCtrl2 = new PopCtrlButton(x, y, size, buttoncolor, highlight, sign); x = xposCtrl + 110; y = yposCtrl; size = 12; sign = true; buttoncolor = color(255); highlight = color(245, 227, 67); growCtrl2 = new PopCtrlButton(x, y, size, buttoncolor, highlight, sign); } void draw() { background(244); updatePops(); if (!initMsg) { counter++; float val = float(counter)/popMax * 255.0 + 40; fill(val); text("just seeding populations...", 220, height - 10); if (counter >= popMax) { initMsg = true; } } for(int ip2=0; ip2= popMax) { show = popMax; } else { show += popInc; } } else if(cullCtrl2.pressed()) { currentcolor = cullCtrl2.basecolor; if (show2 < popInc) { show2 = 0; } else { show2 -= popInc; } } else if(growCtrl2.pressed()) { currentcolor = growCtrl2.basecolor; if (show2 >= popMax) { show2 = popMax; } else { show2 += popInc; } } } } class Button { int x, y; int size; color basecolor, highlightcolor; color currentcolor; boolean over = false; boolean pressed = false; void update() { if(over()) { currentcolor = highlightcolor; } else { currentcolor = basecolor; } } boolean pressed() { if(over) { locked = true; return true; } else { locked = false; return false; } } boolean over() { return true; } void display() { } } class PopCtrlButton extends Button { boolean sign; PopCtrlButton(int ix, int iy, int isize, color icolor, color ihighlight, boolean iSign) { x = ix; y = iy; size = isize; sign = iSign; basecolor = icolor; highlightcolor = ihighlight; currentcolor = basecolor; } boolean over() { if( overPopCtrl(x, y, size) ) { over = true; return true; } else { over = false; return false; } } void display() { stroke(0); fill(currentcolor); smooth(); ellipse(x, y, size, size); fill(0); if (sign) { text("+", x-3, y+5); } else { text("-", x-2, y+4); } resetFill(); } } boolean overPopCtrl(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } void resetFill() { fill(default_fill); }