// // name: lotus.pde // // desc: // // info: bugs, blame and beratement -> <- // // => www.kiddphunk.com/experiments/ // // remember: andre the giant has a posse. // // todo: * nap // /////////////////////////////////////////////////////////////////////////////// int dimx = 800; // 700 int dimy = 80; // 700 int anchors = r(2, 10); // 3 int looplines = r(5, 20); // 10 int numflowers = r(1, 1); int seedcolor = r(0, 3); int lastx = 0; int lasty = 0; int nn = 1; int hcolor = 0; int bgcolor = 128; int currtype = 0; int curr = 1; int savedAnchors = 0; int filltype = 0; int CENTER_DIAMETER = 10; boolean paint = false; boolean pressed = false; boolean waiting = false; boolean gradient = false; boolean special = false; boolean addition = false; boolean permpoint = false; boolean permsdone = false; boolean autopilot = false; boolean concentric = false; boolean drawtri = false; boolean drawcircle = true; boolean drawlotus = false; boolean striation = true; boolean randcolor = true; color[] data; color bgc; int[] xs = new int[2000]; int[] ys = new int[2000]; String[] datacache = new String[2000]; int datasize = 0; Object ps = null; /////////////////////////////////////////////////////////////////////////////// void setup() { initSetup(); initialize(11, false); // 11 if (ps == null) { // ps = SimplePostscript.open("lotusblossoms.ps", 0, 0, dimx*2, dimy*2); // ps.setgray(0); // ps.setlinewidth(0.25); } } void initSetup() { bgc = color(115, 92, 171); dimx = dimy = 283; dimx = 850; data = new color[dimx*dimy]; size(dimx, dimy); framerate(100); setBack(); } void initialize(int type, boolean saveAnchors) { setVariables(type, saveAnchors); initReset(); } void initReset() { pickPoints(); nn = 1; for (int i=0; i dimy) ? dimx : dimy; int r2 = r(int(minn/6), int(minn/3)); if (drawlotus) { return int(r2/2); } if (r(0, 100) < 20) { return r2*2; } if (r(0, 100) < 20) { return r2/2; } if (r(0, 100) < 50) { return -1*r2; } else { return r2; } } boolean allBgX(int x, int y) { for (int i=x; i0; i--) { if (isFg(get(x, i))) { return f; } } return false; } color getColor(int x, int y) { if (isFg(gget(x, y))) { return gget(x, y); } if (!isFg(gget(x-1, y))) { return gget(x-1, y); } if (!isFg(gget(x, y-1))) { return gget(x, y-1); } if (!special) { if (!isFg(gget(x+1, y-1))) { return gget(x+1, y-1); } } boolean afg = false; if (filltype == 0) { afg = anotherFg(x, y); } if (filltype == 1) { afg = anotherFg2(x, y); } if (filltype == 2) { afg = anotherFg3(x, y); } if (!isFg(gget(x, y)) && isFg(gget(x-1, y)) && afg) { return getRandColor(x, y); } return bgc; } boolean anotherFg(int x, int y) { for (int i=x; i 0); } boolean anotherFg3(int x, int y) { int count = 0; int change = 0; for (int i=0; i dimx) { return bgc; } if (y < 0 || y > dimy) { return bgc; } return get(x, y); } color getRandColor(float x, float y) { int a = randc(); int b = randc(); int c = randc(); int maxc = 255; int sc = seedcolor; if (gradient) { // float top = (255*(1-y/dimy)); float top = (180*(1-y/dimy)); a = r(int(top), int(top-top/4)); b = r(int(top), int(top-top/4)); c = r(int(top), int(top-top/4)); } if (sc == 4) { maxc = r(128, 255); sc = r(0, 3); } if (sc == 0) { b = c; // if (gradient) { b = c = 50+r(0, 45); } } if (sc == 1) { a = c; // if (gradient) { a = c = 50+r(0, 45); } } if (sc == 2) { a = b; // if (gradienaaat) { a = b = 50+r(0, 45); } } if (sc == 3) { // noop - tutti-frutti } switch (sc) { case 0: a = maxc; break; // 128 case 1: b = maxc; break; // 128 case 2: c = maxc; break; // 128 } return color(a, b, c); } boolean isFg(color c) { return ((red(c) == hcolor) && (green(c) == hcolor) && (blue(c) == hcolor)); } boolean isBg(color c) { return ((red(c) == 115) && (green(c) == 92) && (blue(c) == 171)); } void go() { noFill(); stroke(hcolor, hcolor, hcolor); int x1 = randx(); int y1 = randy(); int x2 = randx(); int y2 = randy(); int x3 = randx(); int y3 = randy(); for (int a=1; a<=looplines; a++) { int xx1 = x1+off(); int yy1 = y1+off(); int xx2 = x2+off(); int yy2 = y2+off(); int xx3 = x3+off(); int yy3 = y3+off(); int r1 = r(5, 50); int r2 = r(5, 50); if (drawcircle) { ellipseMode(CENTER_DIAMETER); ellipse(xx1, yy1, r1, r1); ellipse(xx2, yy2, r2, r2); if (concentric) { ellipse(xx1, yy1, int(r1/2), int(r1/2)); ellipse(xx2, yy2, int(r2/2), int(r2/2)); } if (ps != null) { /* ps.setrgb(255, 255, 255); int v1 = xx1*2; int v2 = dimy*2-yy1*2; int v3 = xx2*2; int v4 = dimy*2-yy2*2; ps.circle(v1, v2, r1); ps.stroke(); ps.circle(v3, v4, r2); ps.stroke(); datacache[datasize++] = v1+" "+v2+" "+r1; datacache[datasize++] = v3+" "+v4+" "+r2; */ } } if (drawtri) { int divx = r(1, 4); int divy = r(1, 5); triangle(int(xx1/divx), int(yy1/divy), int(xx2/divx), int(yy2/divy), int(xx3/divx), int(yy3/divy)); } if (drawlotus) { bezier(xs[a%anchors], ys[a%anchors], xx1, yy1, xx2, yy2, xs[(a+1)%anchors], ys[(a+1)%anchors]); xs[looplines+a*nn] = xx1; ys[looplines+a*nn] = yy1; xs[looplines+a*(nn+1)] = xx2; ys[looplines+a*(nn+1)] = yy2; nn+=2; } } } void shiftLotusDown(boolean down) { nn = 1; int shift = (down) ? 5 : -5; for (int a=1; a<=looplines; a++) { ys[a%anchors] += shift; ys[looplines+a*nn] += shift; ys[looplines+a*(nn+1)] += shift; nn+=2; } if (waiting) { showData(); go2(false); } else { go2(true); } } void shiftLotusLeft(boolean left) { nn = 1; int shift = (left) ? -5 : 5; for (int a=1; a<=looplines; a++) { xs[a%anchors] += shift; xs[looplines+a*nn] += shift; xs[looplines+a*(nn+1)] += shift; nn+=2; } if (waiting) { showData(); go2(false); } else { go2(true); } } void sizeLotus(boolean shrink) { nn = 1; float shift = (shrink) ? 1.1 : .9; for (int a=1; a<=looplines; a++) { xs[a%anchors] *= shift; ys[a%anchors] *= shift; xs[looplines+a*nn] *= shift; ys[looplines+a*nn] *= shift; xs[looplines+a*(nn+1)] *= shift; ys[looplines+a*(nn+1)] *= shift; nn+=2; } if (waiting) { showData(); go2(false); } else { go2(true); } } void go2(boolean picked) { stroke(hcolor); if (picked) { nn = 1; background(bgc); stroke(hcolor); } for (int a=1; a<=looplines; a++) { int xx1 = xs[looplines+a*nn]; int yy1 = ys[looplines+a*nn]; int xx2 = xs[looplines+a*(nn+1)]; int yy2 = ys[looplines+a*(nn+1)]; bezier(xs[a%anchors], ys[a%anchors], xx1, yy1, xx2, yy2, xs[(a+1)%anchors], ys[(a+1)%anchors]); nn+=2; } } ///////////////////////////////////////////////////////////////////////////////