Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. void setup() {
  2. size(500, 500, P3D);
  3. colorMode(HSB, 360, 100, 100);
  4. noStroke();
  5. }
  6.  
  7. void draw() {
  8. background(0, 0, 0);
  9. lights();
  10. pushMatrix();
  11. translate(width/2, height/2, -300);
  12. fill(0,0,50);
  13. sphere(30);
  14. rotateY(frameCount*0.01);
  15. rotateZ(frameCount*0.005);
  16. rotateX(frameCount*0.001);
  17. pushMatrix();
  18. fill(0, 100, 100);
  19. translate(150, 0, 0);
  20. box(300, 10, 10);
  21. translate(200, 0, 0);
  22. rotateZ(PI/2);
  23. drawCylinder(0, 30, 50, 3);
  24. popMatrix();
  25. pushMatrix();
  26. fill(120, 100, 100);
  27. translate(0, 150, 0);
  28. box(10, 300, 10);
  29. translate(0, 200, 0);
  30. rotateX(-PI);
  31. drawCylinder(0, 30, 50, 3);
  32. popMatrix();
  33. pushMatrix();
  34. fill(240, 100, 100);
  35. translate(0, 0, 150);
  36. box(10, 10, 300);
  37. translate(0, 0, 200);
  38. rotateX(-PI/2);
  39. drawCylinder(0, 30, 50, 3);
  40. popMatrix();
  41. popMatrix();
  42. }
  43.  
  44. void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
  45. float angle = 0;
  46. float angleIncrement = TWO_PI / sides;
  47. beginShape(QUAD_STRIP);
  48. for (int i = 0; i < sides + 1; ++i) {
  49. vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
  50. vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
  51. angle += angleIncrement;
  52. }
  53. endShape();
  54.  
  55. // If it is not a cone, draw the circular top cap
  56. if (topRadius != 0) {
  57. angle = 0;
  58. beginShape(TRIANGLE_FAN);
  59.  
  60. // Center point
  61. vertex(0, 0, 0);
  62. for (int i = 0; i < sides + 1; i++) {
  63. vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
  64. angle += angleIncrement;
  65. }
  66. endShape();
  67. }
  68.  
  69. // If it is not a cone, draw the circular bottom cap
  70. if (bottomRadius != 0) {
  71. angle = 0;
  72. beginShape(TRIANGLE_FAN);
  73.  
  74. // Center point
  75. vertex(0, tall, 0);
  76. for (int i = 0; i < sides + 1; i++) {
  77. vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
  78. angle += angleIncrement;
  79. }
  80. endShape();
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement