PERL   35

spheres

Guest on 10th June 2022 01:27:13 PM

  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use OpenGL::Simple qw(:all);
  5. use OpenGL::Simple::GLUT qw(:all);
  6. use OpenGL::Simple::Viewer;
  7.  
  8. my ($slices,$stacks)=(32,32);
  9.  
  10. glutInit;
  11.  
  12. my $v = new OpenGL::Simple::Viewer(
  13.         draw_geometry => sub {
  14.  
  15.                 drawSphere(0,0,0, 1.0, [1,1,1]);
  16.  
  17.                 my $S1P = 0.732051;
  18.                 my $S1R = 0.267949;
  19.                 my $S1C = [ 0.5, 1.0, 0.5 ];
  20.  
  21.                 drawSphere(-$S1P, $S1P, $S1P,$S1R,$S1C);
  22.                 drawSphere(-$S1P, $S1P, -$S1P,$S1R,$S1C);
  23.                 drawSphere(-$S1P, -$S1P, $S1P,$S1R,$S1C);
  24.                 drawSphere(-$S1P, -$S1P, -$S1P,$S1R,$S1C);
  25.                 drawSphere($S1P, -$S1P, $S1P,$S1R,$S1C);
  26.                 drawSphere($S1P, -$S1P, -$S1P,$S1R,$S1C);
  27.                 drawSphere($S1P, $S1P, $S1P,$S1R,$S1C);
  28.                 drawSphere($S1P, $S1P, -$S1P,$S1R,$S1C);
  29.  
  30.                 my $S2X = 0.29215776558 ;
  31.                 my $S2Y = 0.81329768066 ;
  32.                 my $S2R = 0.18670231934 ;
  33.                 my $S2C = [1.0, 1.0, 0.5];
  34.  
  35.                 drawSphere($S2X, $S2Y, $S2Y, $S2R,$S2C);
  36.                 drawSphere($S2Y, $S2X, $S2Y, $S2R,$S2C);
  37.                 drawSphere($S2Y, $S2Y, $S2X, $S2R,$S2C);
  38.                 drawSphere(-$S2X, $S2Y, $S2Y, $S2R,$S2C);
  39.                 drawSphere(-$S2Y, $S2X, $S2Y, $S2R,$S2C);
  40.                 drawSphere(-$S2Y, $S2Y, $S2X, $S2R,$S2C);
  41.                 drawSphere($S2X, -$S2Y, $S2Y, $S2R,$S2C);
  42.                 drawSphere($S2Y, -$S2X, $S2Y, $S2R,$S2C);
  43.                 drawSphere($S2Y, -$S2Y, $S2X, $S2R,$S2C);
  44.                 drawSphere(-$S2X, -$S2Y, $S2Y, $S2R,$S2C);
  45.                 drawSphere(-$S2Y, -$S2X, $S2Y, $S2R,$S2C);
  46.                 drawSphere(-$S2Y, -$S2Y, $S2X, $S2R,$S2C);
  47.                 drawSphere($S2X, $S2Y, -$S2Y, $S2R,$S2C);
  48.                 drawSphere($S2Y, $S2X, -$S2Y, $S2R,$S2C);
  49.                 drawSphere($S2Y, $S2Y, -$S2X, $S2R,$S2C);
  50.                 drawSphere(-$S2X, $S2Y, -$S2Y, $S2R,$S2C);
  51.                 drawSphere(-$S2Y, $S2X, -$S2Y, $S2R,$S2C);
  52.                 drawSphere(-$S2Y, $S2Y, -$S2X, $S2R,$S2C);
  53.                 drawSphere($S2X, -$S2Y, -$S2Y, $S2R,$S2C);
  54.                 drawSphere($S2Y, -$S2X, -$S2Y, $S2R,$S2C);
  55.                 drawSphere($S2Y, -$S2Y, -$S2X, $S2R,$S2C);
  56.                 drawSphere(-$S2X, -$S2Y, -$S2Y, $S2R,$S2C);
  57.                 drawSphere(-$S2Y, -$S2X, -$S2Y, $S2R,$S2C);
  58.                 drawSphere(-$S2Y, -$S2Y, -$S2X, $S2R,$S2C);
  59.  
  60.  
  61.                 glColor(0,1,0);
  62.                 glutWireCube(2.0);
  63.  
  64.         },
  65. );
  66.  
  67. glLineWidth(3.0);
  68.  
  69. glutMainLoop;
  70.  
  71.  
  72. sub drawSphere {
  73.         my ($x,$y,$z,$r,$c) = @_;
  74.         glPushMatrix;
  75.                 glTranslate($x,$y,$z);
  76.                 glColor(@$c);
  77.                 glutSolidSphere($r,$slices,$stacks);
  78.         glPopMatrix;
  79. }

Raw Paste


Login or Register to edit or fork this paste. It's free.