lib/crystalcell/povray/triangle.rb in crystalcell-0.0.6 vs lib/crystalcell/povray/triangle.rb in crystalcell-0.1.0

- old
+ new

@@ -1,17 +1,33 @@ #! /usr/bin/env ruby # coding: utf-8 -class Mageo::Triangle +class CrystalCell::Povray::Triangle < Mageo::Triangle + + attr_accessor :color, :transmit + + def initialize(vec0, vec1, vec2, color, transmit = nil) + super(vec0, vec1, vec2) + @color = color + @transmit = transmit + end + # povray 形式の文字列を返す。 # color は Float による配列。通常、0〜1の範囲。 - def to_pov(color) + def to_pov v = self.vertices - result = "polygon { 4, " + sprintf("<%7.4f, %7.4f, %7.4f>, ", v[0][0], v[0][1], v[0][2]) + - sprintf("<%7.4f, %7.4f, %7.4f>, ", v[1][0], v[1][1], v[1][2]) + - sprintf("<%7.4f, %7.4f, %7.4f>, ", v[2][0], v[2][1], v[2][2]) + - sprintf("<%7.4f, %7.4f, %7.4f> " , v[0][0], v[0][1], v[0][2]) + - "pigment { color rgb <1, 0, 0> } }" + result = sprintf("triangle{<%f,%f,%f>,<%f,%f,%f>,<%f,%f,%f>", + *@vertices[0], *@vertices[1], *@vertices[2]) + result += sprintf(" pigment {color rgb<%f,%f,%f>", *@color) + result += sprintf(" transmit %f", @transmit) if @transmit + result += "}}" + #result = sprintf("triangle{<%f,%f,%f>,<%f,%f,%f>,<%f,%f,%f> " + + # "pigment {color rgb<%f,%f,%f>}}", + # *@vertices[0], *@vertices[1], *@vertices[2], *@color) + # return result end -end + def dump(io) + io.puts self.to_pov + end +end