Advertisement
Guest User

Hemisphere attempt

a guest
Feb 16th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. float angle = 0.0;
  2.  
  3. void setup() {
  4. size(600, 600, P3D);
  5. }
  6.  
  7. void draw() {
  8. background(255);
  9.  
  10. translate(width/2, height/2);
  11.  
  12. rotateX(angle);
  13. rotateY(angle);
  14.  
  15. drawHemisphere(new PVector(HALF_PI, 0, 0), 100, 60, 60);
  16.  
  17. angle += 0.01;
  18. }
  19.  
  20. void drawHemisphere(PVector rot, float radius, float slicesA, float slicesB) {
  21. float a, b, x, y, z, da, db;
  22.  
  23. da = TWO_PI / slicesA;
  24. db = HALF_PI / slicesB;
  25.  
  26. rotateX(rot.x);
  27. rotateY(rot.y);
  28. rotateZ(rot.z);
  29.  
  30. noStroke();
  31. fill(0, 255, 0, 127);
  32. beginShape(QUAD_STRIP);
  33.  
  34. for (b=0; b < HALF_PI; b += db) {
  35.  
  36. for (a=0; a < TWO_PI+da; a += da) {
  37. x = cos(a) * cos(b) * radius;
  38. y = sin(a) * cos(b) * radius;
  39. z = sin(b) * radius;
  40.  
  41. vertex(x, y, z);
  42.  
  43. x = cos(a) * cos(b+db) * radius;
  44. y = sin(a) * cos(b+db) * radius;
  45. z = sin(b+db) * radius;
  46.  
  47. vertex(x, y, z);
  48. }
  49.  
  50. }
  51.  
  52. endShape();
  53.  
  54.  
  55. rotateZ(-rot.z);
  56. rotateY(-rot.y);
  57. rotateX(-rot.x);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement