joemckay

Untitled

Oct 13th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. int pointNum = 1200;
  2. int rowNum = 20;
  3. PVector [] pointsArray = new PVector [pointNum];
  4. boolean shift;
  5. void setup() {
  6. size(400, 400, P3D);
  7. for (int i = 0; i <pointNum; i++) {
  8. if (i%rowNum == 0) { // shifts shifts other row over
  9. pointsArray[i] = new PVector((i % rowNum) * rowNum - width/2, (i / rowNum) * rowNum - height/2, random(20));
  10. } else {
  11. pointsArray[i] = new PVector((i % rowNum) * rowNum + rowNum/2 - width/2, (i / rowNum) * rowNum - height/2, random(20) );
  12. }
  13. }
  14. smooth();
  15. }
  16.  
  17. void draw() {
  18. background(200);
  19. pushMatrix();
  20. translate(width/2, height/2);
  21. rotateX(4.3);
  22. beginShape(TRIANGLES);
  23. shift = true;
  24. // for (int i = 0; i < pointNum; i++) {
  25. for (int i = 0; i < pointNum - (rowNum +1); i++) {
  26. if (i%rowNum == 0) { // every other row shifts over half way
  27. shift = !shift;
  28. }
  29. if ( (i +1) % rowNum != 0) { // keeps it from drawing from one side to the other
  30. vertex(pointsArray[i].x, pointsArray[i].y, pointsArray[i].z);
  31. vertex(pointsArray[i +1].x, pointsArray[i +1].y, pointsArray[i +1].z);
  32. if (shift == false) {
  33. vertex(pointsArray[i + rowNum].x, pointsArray[i +rowNum].y, pointsArray[i + rowNum].z );
  34. } else {
  35. vertex(pointsArray[i + rowNum +1].x, pointsArray[i +rowNum+1].y, pointsArray[i + rowNum+1].z);
  36. }
  37.  
  38. vertex(pointsArray[i +rowNum +1].x, pointsArray[i +rowNum + 1].y, pointsArray[i +rowNum + 1].z);
  39. vertex(pointsArray[i + rowNum].x, pointsArray[i +rowNum].y, pointsArray[i +rowNum].z);
  40. if (shift == false) {
  41. vertex(pointsArray[i + 1].x, pointsArray[i + 1].y, pointsArray[i + 1].z);
  42. } else {
  43. vertex(pointsArray[i].x, pointsArray[i].y, pointsArray[i].z);
  44. }
  45. }
  46. }
  47. endShape();
  48. popMatrix();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment