Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mtn.visuals;
- import java.util.Iterator;
- import wblut.hemesh.modifiers.*;
- import wblut.hemesh.creators.*;
- import wblut.hemesh.*;
- import oscP5.*;
- import processing.core.PApplet;
- @SuppressWarnings("serial")
- public class Kalimba extends processing.core.PApplet {
- //Meshes
- HE_Mesh[][] meshes;
- int curMesh = 0;
- int numRows = 8;
- int numCols = 7;
- float rotateAmount = 0;
- float rotateMax = .15f;
- boolean readyDraw = false;
- float maxVertexDistance = 400;
- float vertexDistance = 0;
- float maxPerspectiveWidth = 5000;
- float perspectiveWidth;
- float maxBendAmount = 1000;
- float bendAmount;
- int[][] buttons;
- // presentation
- int bgcolor = color(0,0,0); // background color
- int shapecolor; // shape color
- boolean facesOn = true; // toggle display of faces
- boolean edgesOn = true; // toggle display of edges
- float shapeHue = 57; // default hue
- float shapeSaturation = 100; // default saturation
- float shapeBrightness = 96; // default brightness
- float[][] shapeTransparency; // default transparency
- int[][] counter;
- float ax,ay;
- boolean clock = false;
- //OSC
- int oscPort = 7400;
- OscP5 oscP5;
- public static void main(String args[]) {
- PApplet.main(new String[] { "mtn.visuals.Kalimba" });
- }
- public void setup(){
- size(1024,768,OPENGL);
- meshes = new HE_Mesh[numCols][numRows];
- counter = new int[numCols][numRows];
- shapeTransparency = new float[numCols][numRows];
- buttons = new int[numCols][numRows];
- noStroke();
- oscP5 = new OscP5(this,oscPort);
- createDots();
- }
- void createDots()
- {
- for(int j=0;j<numRows;j++)
- for(int k=0;k<numCols;k++)
- {
- createDot(k, j);
- }
- }
- void createDot(int col, int row)
- {
- HEC_Creator creator;
- float x;
- float y;
- x = col * (width / numCols);
- y = row * (height / numRows);
- creator=new HEC_Sphere(this).setRadius(6).setUFacets(7).setVFacets(7).setCenter(x,y,-200);
- meshes[col][row]=new HE_Mesh(creator);
- shapeTransparency[col][row] = 255;
- }
- public void draw(){
- //camera(mouseX, mouseY, 120.0, 50.0, 50.0, 0.0, 0.0, 1.0, 0.0);
- background(bgcolor);
- rotateX(random(0,rotateAmount));
- rotateY(random(0,rotateAmount));
- lights();
- colorMode(RGB,255,255,255,255);
- HE_Selection selection;
- Iterator <HE_Face> fItr;
- HE_Face f;
- for(int j=0;j<numRows;j++)
- for(int k=0;k<numCols;k++)
- {
- colorMode(RGB,255,255,255,255);
- shapecolor = color(240, 20, 240, shapeTransparency[k][j]);
- fill(shapecolor);
- pushMatrix();
- if(buttons[k][j] == 1)
- {
- //Vertex Expansion
- selection = new HE_Selection();
- fItr = meshes[k][j].fItr();
- while (fItr.hasNext()) { f = fItr.next(); if (random(100) < 4) { selection.add(f); } }
- meshes[k][j].modifySelected(new HEM_VertexExpand().setDistance(random(0, (8-j) * 10)),selection);
- if(--counter[k][j] <= 0)
- {
- buttons[k][j] = 0;
- }
- }
- else
- {
- createDot(k, j);
- counter[k][j] = 0;
- }
- meshes[k][j].drawFaces();
- meshes[k][j].drawEdges();
- popMatrix();
- }
- /*
- for(int i =0;i<meshesCreated;i++)
- {
- counter[i]++;
- pushMatrix();
- translate(counter[i]*8,0);
- colorMode(HSB,360,100,100,100);
- //shapecolor = color(shapeHue, shapeSaturation, shapeBrightness, shapeTransparency);
- colorMode(RGB,255,255,255,255);
- shapecolor = color(0, 0, 0, shapeTransparency[i]);
- fill(shapecolor);
- if(shapeTransparency[i] > 0)
- {
- meshes[i].drawFaces();
- meshes[i].drawEdges();
- }
- popMatrix();
- }
- void drawMesh()
- {
- if(meshesCreated < numMeshes)meshesCreated++;
- counter[curMesh] = 0;
- //Vertex Expansion
- HE_Selection selection = new HE_Selection();
- Iterator <HE_Face> fItr = meshes[curMesh].fItr();
- HE_Face f;
- while (fItr.hasNext()) { f = fItr.next(); if (random(100) < 3) { selection.add(f); } }
- meshes[curMesh].modifySelected(new HEM_VertexExpand().setDistance(vertexDistance),selection);
- curMesh++;
- if(curMesh >= numMeshes)curMesh = 0;
- }
- */
- //this.finished = true;
- }
- public void mousePressed()
- {
- System.out.println("sdfsdf");
- }
- void oscEvent(OscMessage msg) {
- if(msg.checkAddrPattern("/mtn/note") && msg.get(1).intValue() != 0)
- {
- int row = (msg.get(1).intValue() - 1) / 16;
- int col = msg.get(0).intValue() - 48;
- //TODO: not sure why looper is also sending higher note values
- if(col < 8 && row < 8)
- {
- buttons[col][row] = 1;
- counter[col][row] = 20;
- }
- }
- else if(msg.checkAddrPattern("/mtn/param"))
- {
- if(msg.get(0).intValue() == 5)
- {
- rotateAmount = ((float)msg.get(1).intValue() / 127.0f) * rotateMax;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment