// MESHY by Golan Levin // Originally developed in October 1998 (C++) // Processing version November 2006 // golan at flong dot com import processing.opengl.*; boolean bUseOpenGL = true; int nPaths; int nActual; int nFilledPaths; int currentPathIndex; float currentSample; int framesSinceMouseUp; final int mult = 4; final int meshElementSpacing = 5*mult; final int nBezSamples = 75*mult; final float diamondScale = 0.003625f * mult; final int nResamples = 75; final int nFadeoutFrames = 80; boolean prevMouseDownState; boolean mouseIsDown; float prevMillis = 0; float splineStrength = 10.0F; final float bias = 6.0F; Vector pathArray[]; Vector pathBezArray[]; Vec3f drawArray[][]; float bt[]; float bt2[]; float bt3[]; float onemt[]; float onemt2[]; float onemt3[]; float bto2[]; float bt2o[]; PFont fonty; boolean begun = false; boolean showInfo = false; long begunTime; //--------------------------------------------------------- void setup(){ if (bUseOpenGL){ size(720, 480, OPENGL); } else{ size(720, 480, P3D); } fonty = loadFont("Garamond-Italic-24.vlw"); textFont(fonty, 24); textAlign (CENTER); handleInit(); } void handleInit(){ mouseIsDown = prevMouseDownState = false; currentPathIndex = 0; nFilledPaths = 0; nPaths = 2; nActual = 6; currentSample = 0; framesSinceMouseUp = 0; pathArray = new Vector[nActual]; pathBezArray = new Vector[nActual]; drawArray = new Vec3f[nActual][nResamples]; precomputeBezierArrays(); for(int i = 0; i < nActual; i++){ pathArray[i] = new Vector(100); pathBezArray[i] = new Vector(500); for(int p =0; p3){ for (int i=1; i 0){ int fromIndex = 0; int toIndex = 0; int otherIndex = 0; int offset = -1; if(mouseIsDown){ offset = 0; } fromIndex = ((currentPathIndex - 1) + offset + nPaths) % nPaths; toIndex = (currentPathIndex + offset + nPaths) % nPaths; drawStem(pathBezArray[toIndex]); if(toIndex % 2 == 1) { drawStem(pathBezArray[fromIndex]); } if(nFilledPaths != 1 || currentPathIndex != 1) { int num = nPaths - 1; if(nFilledPaths < nPaths){ num = currentPathIndex; } for(int i=0; i<=num; i++) { fromIndex = ((i - 1) + offset + nPaths) % nPaths; toIndex = (i + offset + nPaths) % nPaths; if(toIndex % 2 == 1){ Vec3f fromArray[] = drawArray[fromIndex]; Vec3f toArray[] = drawArray[toIndex]; if(nPaths == 2 || currentPathIndex != (fromIndex - offset) % nPaths) { drawMesh(fromArray, toArray); } } } } } else { for (int p = 0; p <= nFilledPaths; p++) { drawStem(pathBezArray[p]); } } } //---------------------------------------------------------- void drawFades(){ if (bUseOpenGL){ noStroke(); noSmooth(); float wf = width*0.075; float hf = height*0.0333; beginShape(QUADS); fill(0,0,0, 255); vertex(0,0); vertex(0,height); fill(0,0,0, 0); vertex(wf,height-hf); vertex(wf,hf); fill(0,0,0, 255); vertex(0,0); vertex(width,0); fill(0,0,0, 0); vertex(width-wf,hf); vertex(wf,hf); fill(0,0,0, 255); vertex(width,0); vertex(width,height); fill(0,0,0, 0); vertex(width-wf,height); vertex(width-wf,0); fill(0,0,0, 255); vertex(0,height); vertex(width,height); fill(0,0,0, 0); vertex(width-wf,height-hf); vertex(wf,height-hf); endShape(); } } //--------------------------------------------- void drawIntro(){ float py = height*(1-0.618); if (!begun){ fill(255); if (showInfo){ text("Meshy by Golan Levin, 1998-2006", width/2, height/2 ); } else { text("Meshy by Golan Levin, 1998-2006", width/2, py - 30); text("Draw two marks to begin", width/2, py); } noFill(); } else { float dur = 1000; float dif = (float)(millis() - begunTime); if (dif < dur){ float c = 1.0 - dif/dur; fill(c*255); if (showInfo){ text("Meshy by Golan Levin, 1998-2006", width/2, height/2); } else { text("Meshy by Golan Levin, 1998-2006", width/2, py - 30); text("Draw two marks to begin", width/2, py); } noFill(); } } } //------------------------------------------------------------ void mouseMoved (){ mouseIsDown = false; } void mouseReleased(){ Vector path = pathArray[currentPathIndex]; Vector bPath = pathBezArray[currentPathIndex]; addPointToVector(path, mouseX, mouseY); Vec3f resamplePath[] = drawArray[currentPathIndex]; calculateBezierPath(currentPathIndex); resampleVector(bPath, resamplePath); nFilledPaths++; currentPathIndex = nFilledPaths % nPaths; framesSinceMouseUp = 0; mouseIsDown = false; } //======================================================= void createStarter(){ float rads[] = { 0.08, 0.11 }; for (int c=0; c<2; c++){ Vector path = pathArray[currentPathIndex]; Vector bPath = pathBezArray[currentPathIndex]; float cx = width * 0.5; float cy = height * 0.618; float r = height * rads[c]; float rotang = c*0.1; float fullRound = TWO_PI * (float)(nResamples+1)/(float)nResamples; for (int i=0; i= neededSpace){ float remainder = ASL; float px = lower.x + neededSpace * dx; float py = lower.y + neededSpace * dy; float pz = lower.z + Dz / 2.0F; if(p < nResampledPoints) { resampledPath[p].set(px, py, pz); remainder -= neededSpace; p++; } int nPtsToDo = (int)(remainder / RSL); for(int d = 0; d < nPtsToDo; d++) { px += RSLdx; py += RSLdy; if(p < nResampledPoints) { resampledPath[p].set(px, py, pz); remainder -= RSL; p++; } } prevRemainder = remainder; } else{ prevRemainder += ASL; } } } } void drawStem(Vector path) { if(framesSinceMouseUp < nFadeoutFrames) { int nSegs = path.size(); if(nSegs > 1){ float col = (float)Math.max(0, nFadeoutFrames - framesSinceMouseUp) / (float)nFadeoutFrames; beginShape(LINES); for(int i = 0; i < (nSegs = path.size()); i++) { Vec3f pt = (Vec3f)path.elementAt(i); float c = ((float)i / (float)nSegs) * col; float x1 = pt.x; float y1 = pt.y; stroke(c*c*255.0f); vertex(x1, y1); vertex(x1+1, y1+1); } endShape(); } } } //---------------------------------------------------------- void drawMesh(Vec3f fromArray[], Vec3f toArray[]){ float sizef = 0.5F; float c = 0.0F; int spacing = meshElementSpacing; int nbsm1 = nBezSamples-1; int nrsm1 = nResamples-1; noFill(); if (bUseOpenGL){ smooth(); } int roundSamp = round(currentSample); float pulse = 1; if (begun==false){ pulse = 0.05 + 0.70*(0.5*(1.0 + cos(PI + millis()/1800.0))); } float nrsm1f = (float)nrsm1; float splBreath = 2.5*sin(millis()/6000.0); beginShape(QUADS); for(int i=0; i