2

Here, I am trying to convert some POV-Ray code to Python. I'm using the VAPORY module. Especially, the part scale <4/3,1,1>*1.75 and pigment{ color rgb<1,1,1>*1.1 } is highly confusing. Can't figure out how to add *1.75 and *1.1 into the Python code.

PURE POV-RAY CODE:

box { <-0.04,-0.04,0>,< 1.03, 1.04, 0.01>   
      // 1st layer: White
      texture{ 
        pigment{ color rgb<1,1,1>*1.1 } 
        finish{ phong 1}
      } // ------------------------------ 
      // 2nd layer: image_map
      texture{
        pigment{
          image_map{ jpeg "Image_gamma_0.jpg"  
          // maps an image on the xy plane from <0,0,0> to <1,1,0> (aspect ratio 1:1)
          // accepted types: gif, tga, iff, ppm, pgm, png, jpeg, tiff, sys
          map_type 0 // 0=planar, 1=spherical, 2=cylindrical, 5=torus
          interpolate 2 // 0=none, 1=linear, 2=bilinear, 4=normalized distance
          once //
         } // end of image_map
       } //  end of pigment
     } // end of texture

     scale <4/3,1,1>*1.75
     rotate<  0, 0,0>
     translate<-1.5,0.1,-2>
} // end of box //

VAPORY CODE:

# box with layered textures
box = Box ([-0.04, -0.04, 0], [1.03, 1.04, 0.01],
           # 1st layer: White
           Texture(
               Pigment('color', [0, 0, 1]),
               Finish('phong', 1)
               ), # End of 1st layer ------------------------------
           # 2nd layer: image_map
           Texture(
               Pigment(
                   ImageMap(
                       'jpeg', 
                       '"Image_gamma_0.jpg"',
                       'gamma', 2.0,
                       'map_type', 0,
                       'interpolate', 2,
                       'once'
                       ), # end of image_map
                   ), # end of pigment
               ), # end of texture
           'scale', [4/3, 1, 1],
           'translate', [-1.5, 0.1, -2]
           ) # end of box # -----------------------
Vadim Landa
  • 2,784
  • 5
  • 23
  • 33
Anay Bose
  • 880
  • 1
  • 14
  • 24
  • 'scale', [i*1.75 for i in [4/3, 1, 1]] List comprehension. Vapory does not seem to have a vector class that would make things like this easier. Actually, a true vector type in Python would be nice to have. – ingo Sep 28 '18 at 09:45

1 Answers1

1

You can use numpy for the vector operation:
A python list [] corresponds to the POV-Ray vector <>
A numpy array supports the scalar multiplication you want (*x )

  1. Make a numpy array from your list
  2. Multiply array
  3. Convert array to list

Like this:

import numpy as np
print(list(np.array([1,2,3])*2.5)) 

result: [2.5, 5.0, 7.5]

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
aku
  • 11
  • 1