Guest User

Untitled

a guest
Oct 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. package mtn.visuals;
  2.  
  3. import java.util.Iterator;
  4.  
  5. import wblut.hemesh.modifiers.*;
  6. import wblut.hemesh.creators.*;
  7. import wblut.hemesh.*;
  8. import oscP5.*;
  9. import processing.core.PApplet;
  10.  
  11. @SuppressWarnings("serial")
  12. public class Kalimba extends processing.core.PApplet {
  13. //Meshes
  14. HE_Mesh[][] meshes;
  15. int curMesh = 0;
  16. int numRows = 8;
  17. int numCols = 7;
  18. float rotateAmount = 0;
  19. float rotateMax = .15f;
  20.  
  21. boolean readyDraw = false;
  22. float maxVertexDistance = 400;
  23. float vertexDistance = 0;
  24. float maxPerspectiveWidth = 5000;
  25. float perspectiveWidth;
  26. float maxBendAmount = 1000;
  27. float bendAmount;
  28. int[][] buttons;
  29.  
  30. // presentation
  31. int bgcolor = color(0,0,0); // background color
  32. int shapecolor; // shape color
  33. boolean facesOn = true; // toggle display of faces
  34. boolean edgesOn = true; // toggle display of edges
  35. float shapeHue = 57; // default hue
  36. float shapeSaturation = 100; // default saturation
  37. float shapeBrightness = 96; // default brightness
  38. float[][] shapeTransparency; // default transparency
  39. int[][] counter;
  40. float ax,ay;
  41. boolean clock = false;
  42. //OSC
  43. int oscPort = 7400;
  44. OscP5 oscP5;
  45.  
  46. public static void main(String args[]) {
  47. PApplet.main(new String[] { "mtn.visuals.Kalimba" });
  48. }
  49.  
  50. public void setup(){
  51. size(1024,768,OPENGL);
  52. meshes = new HE_Mesh[numCols][numRows];
  53. counter = new int[numCols][numRows];
  54. shapeTransparency = new float[numCols][numRows];
  55. buttons = new int[numCols][numRows];
  56. noStroke();
  57. oscP5 = new OscP5(this,oscPort);
  58. createDots();
  59. }
  60.  
  61. void createDots()
  62. {
  63. for(int j=0;j<numRows;j++)
  64. for(int k=0;k<numCols;k++)
  65. {
  66. createDot(k, j);
  67. }
  68. }
  69.  
  70.  
  71. void createDot(int col, int row)
  72. {
  73. HEC_Creator creator;
  74. float x;
  75. float y;
  76. x = col * (width / numCols);
  77. y = row * (height / numRows);
  78. creator=new HEC_Sphere(this).setRadius(6).setUFacets(7).setVFacets(7).setCenter(x,y,-200);
  79. meshes[col][row]=new HE_Mesh(creator);
  80. shapeTransparency[col][row] = 255;
  81. }
  82.  
  83. public void draw(){
  84. //camera(mouseX, mouseY, 120.0, 50.0, 50.0, 0.0, 0.0, 1.0, 0.0);
  85. background(bgcolor);
  86. rotateX(random(0,rotateAmount));
  87. rotateY(random(0,rotateAmount));
  88. lights();
  89. colorMode(RGB,255,255,255,255);
  90.  
  91. HE_Selection selection;
  92. Iterator <HE_Face> fItr;
  93. HE_Face f;
  94.  
  95.  
  96. for(int j=0;j<numRows;j++)
  97. for(int k=0;k<numCols;k++)
  98. {
  99.  
  100. colorMode(RGB,255,255,255,255);
  101. shapecolor = color(240, 20, 240, shapeTransparency[k][j]);
  102. fill(shapecolor);
  103. pushMatrix();
  104. if(buttons[k][j] == 1)
  105. {
  106. //Vertex Expansion
  107. selection = new HE_Selection();
  108. fItr = meshes[k][j].fItr();
  109. while (fItr.hasNext()) { f = fItr.next(); if (random(100) < 4) { selection.add(f); } }
  110. meshes[k][j].modifySelected(new HEM_VertexExpand().setDistance(random(0, (8-j) * 10)),selection);
  111. if(--counter[k][j] <= 0)
  112. {
  113. buttons[k][j] = 0;
  114. }
  115. }
  116. else
  117. {
  118. createDot(k, j);
  119. counter[k][j] = 0;
  120. }
  121. meshes[k][j].drawFaces();
  122. meshes[k][j].drawEdges();
  123.  
  124. popMatrix();
  125. }
  126.  
  127. /*
  128. for(int i =0;i<meshesCreated;i++)
  129. {
  130. counter[i]++;
  131. pushMatrix();
  132. translate(counter[i]*8,0);
  133. colorMode(HSB,360,100,100,100);
  134. //shapecolor = color(shapeHue, shapeSaturation, shapeBrightness, shapeTransparency);
  135. colorMode(RGB,255,255,255,255);
  136. shapecolor = color(0, 0, 0, shapeTransparency[i]);
  137. fill(shapecolor);
  138. if(shapeTransparency[i] > 0)
  139. {
  140. meshes[i].drawFaces();
  141. meshes[i].drawEdges();
  142. }
  143. popMatrix();
  144. }
  145.  
  146.  
  147. void drawMesh()
  148. {
  149. if(meshesCreated < numMeshes)meshesCreated++;
  150. counter[curMesh] = 0;
  151.  
  152.  
  153.  
  154. //Vertex Expansion
  155. HE_Selection selection = new HE_Selection();
  156. Iterator <HE_Face> fItr = meshes[curMesh].fItr();
  157. HE_Face f;
  158. while (fItr.hasNext()) { f = fItr.next(); if (random(100) < 3) { selection.add(f); } }
  159. meshes[curMesh].modifySelected(new HEM_VertexExpand().setDistance(vertexDistance),selection);
  160.  
  161. curMesh++;
  162. if(curMesh >= numMeshes)curMesh = 0;
  163. }
  164. */
  165.  
  166.  
  167. //this.finished = true;
  168.  
  169. }
  170.  
  171. public void mousePressed()
  172. {
  173. System.out.println("sdfsdf");
  174.  
  175.  
  176. }
  177.  
  178.  
  179. void oscEvent(OscMessage msg) {
  180.  
  181. if(msg.checkAddrPattern("/mtn/note") && msg.get(1).intValue() != 0)
  182. {
  183.  
  184. int row = (msg.get(1).intValue() - 1) / 16;
  185. int col = msg.get(0).intValue() - 48;
  186. //TODO: not sure why looper is also sending higher note values
  187. if(col < 8 && row < 8)
  188. {
  189. buttons[col][row] = 1;
  190. counter[col][row] = 20;
  191. }
  192. }
  193. else if(msg.checkAddrPattern("/mtn/param"))
  194. {
  195. if(msg.get(0).intValue() == 5)
  196. {
  197. rotateAmount = ((float)msg.get(1).intValue() / 127.0f) * rotateMax;
  198. }
  199. }
  200.  
  201. }
  202.  
  203. }
Add Comment
Please, Sign In to add comment