rupov 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ *.pov
2
+ *.swp
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
7
+ vendor/*
8
+ output/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rupov.gemspec
4
+ gemspec
@@ -0,0 +1,31 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :test
5
+
6
+ desc "unit tests"
7
+ task :test do
8
+ exec 'bundle exec rspec test/**/*'
9
+ end
10
+
11
+ EXAMPLE_NAMES = Dir['examples/*.rb'].map{|n|n.gsub(/examples\/([a-z_]+)\.rb/,'\1')}
12
+
13
+ WIDTH = 800
14
+ HEIGHT = 600
15
+ QUALITY = 11
16
+
17
+ directory 'output'
18
+
19
+ EXAMPLE_NAMES.each do |name|
20
+ task "output/#{name}.pov" => [ 'output', "examples/#{name}.rb" ] do
21
+ sh "ruby examples/#{name}.rb > output/#{name}.pov"
22
+ end
23
+ task "output/#{name}.png" => "output/#{name}.pov"do
24
+ sh "povray +Ooutput/#{name}.png +FP -D Antialias=1 Width=#{WIDTH} Height=#{HEIGHT} Quality=#{QUALITY} output/#{name}.pov"
25
+ end
26
+ end
27
+
28
+ task :example_png_files => EXAMPLE_NAMES.map{|n|"output/#{n}.png"}
29
+
30
+ desc "Build all example scenes"
31
+ task :examples => :example_png_files
@@ -0,0 +1,36 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ class GrassBlade < RuPov::Objects::FiniteSolidPrimitives::SphereSweep
5
+ @@grassColour = RuPov::DataTypes::Vector::RGB.new( 0, 0.7, 0)
6
+ @@grassTexture = RuPov::Textures::Texture.new do |texture|
7
+ texture << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::ColourRGB.new( @@grassColour ) )
8
+ end
9
+ def initialize( length, baseRadius, curve, segments)
10
+ @@grassColour.g = rand*0.4 + 0.2
11
+ @@grassColour.r = rand*0.2
12
+ degrees = 0
13
+ sweep = [ RuPov::DataTypes::Vector::XYZ.new(0,0,0), baseRadius ]
14
+ 0.upto(segments) do |segment|
15
+ x = Math::sin( degrees )*(segment*length/segments)
16
+ y = Math::cos( degrees )*(segment*length/segments)
17
+ degrees += ((curve*(rand*0.6+0.6))/segments)*Math::PI/180
18
+ sweep << RuPov::DataTypes::Vector::XYZ.new(x,y,0)
19
+ sweep << (segments-segment)*baseRadius/segments
20
+ end
21
+ super(sweep,'b_spline')
22
+ self << @@grassTexture.to_s # render in place
23
+ yield(self) if block_given? and self.class == GrassBlade
24
+ end
25
+ end
26
+
27
+ puts Scene.new
28
+
29
+ (1..1000).each do |num|
30
+ GrassBlade.new( 0.8+rand*0.4, 0.005, 25+rand*20, 10) do |blade|
31
+ blade << RuPov::Methods::Rotate.new( RuPov::DataTypes::Vector::XYZ.new(0,rand*90+110,0) )
32
+ blade << RuPov::Methods::Translate.new( RuPov::DataTypes::Vector::XYZ.new(rand*1.5-0.75,0,rand*1.5-0.75) )
33
+ puts blade
34
+ end
35
+ end
36
+
@@ -0,0 +1,15 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::CSG::Difference.new() { |diff|
6
+ diff << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
7
+ RuPov::DataTypes::Vector::XYZ.new( -0.15, 0.5, -0.15), 0.45 ) { |sphere|
8
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
9
+ }
10
+ diff << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
11
+ RuPov::DataTypes::Vector::XYZ.new( 0.15, 0.7, 0.15), 0.45 ) { |sphere|
12
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Red" ) )
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::CSG::Intersection.new() { |intersect|
6
+ intersect << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
7
+ RuPov::DataTypes::Vector::XYZ.new( -0.15, 0.5, -0.15), 0.45 ) { |sphere|
8
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
9
+ }
10
+ intersect << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
11
+ RuPov::DataTypes::Vector::XYZ.new( 0.15, 0.7, 0.15), 0.45 ) { |sphere|
12
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Red" ) )
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,17 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::CSG::Merge.new() { |merge|
6
+ merge << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
7
+ RuPov::DataTypes::Vector::XYZ.new( -0.15, 0.5, -0.15), 0.45 ) { |sphere|
8
+ sphere << RuPov::Textures::Pigments::SolidColour.new(
9
+ RuPov::Methods::Colour.new( "Yellow" ) )
10
+ }
11
+ merge << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
12
+ RuPov::DataTypes::Vector::XYZ.new( 0.15, 0.7, 0.15), 0.45 ) { |sphere|
13
+ sphere << RuPov::Textures::Pigments::SolidColour.new(
14
+ RuPov::Methods::ColourRGBT.new( RuPov::DataTypes::Vector::RGBT.new( 1,0,0,0.8 ) ) )
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::CSG::Union.new() { |union|
6
+ union << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
7
+ RuPov::DataTypes::Vector::XYZ.new( -0.15, 0.5, -0.15), 0.45 ) { |sphere|
8
+ sphere << RuPov::Textures::Pigments::SolidColour.new(
9
+ RuPov::Methods::Colour.new( "Yellow" ) )
10
+ }
11
+ union << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
12
+ RuPov::DataTypes::Vector::XYZ.new( 0.15, 0.7, 0.15), 0.45 ) { |sphere|
13
+ sphere << RuPov::Textures::Pigments::SolidColour.new(
14
+ RuPov::Methods::ColourRGBT.new( RuPov::DataTypes::Vector::RGBT.new( 1,0,0,0.8 ) ) )
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,108 @@
1
+ class Scene < RuPov::Group
2
+ class Wall < RuPov::Group
3
+ include RuPov
4
+ include Objects
5
+ include InfiniteSolidPrimitives
6
+ include Textures
7
+ include Pigments
8
+ include Methods
9
+ def initialize( rotate, translate )
10
+ super()
11
+ entireWall = CSG::Union.new() { |entireWall|
12
+ entireWall << Plane.new( DataTypes::Vector::XYZ.new(0,0,-1),0 ) { |wall|
13
+ wall << Texture.new() { |texture|
14
+ texture << SolidColour.new( Colour.new( DataTypes::Vector::RGB.new(1,0.95,0.9) ) )
15
+ texture << Normal.new() { |normal|
16
+ normal << MultiValue.new([0.4],'crackle')
17
+ normal << MultiValue.new([0.05],'scale')
18
+ }
19
+ texture << Finish.new() { |finish|
20
+ finish << MultiValue.new([0.5],'phong')
21
+ finish << MultiValue.new([0.5],'roughness')
22
+ }
23
+ }
24
+ }
25
+
26
+ entireWall << CSG::Difference.new() { |sideboard|
27
+ sideboard_miniblock = FiniteSolidPrimitives::Box.new(
28
+ DataTypes::Vector::XYZ.new(-50,0.6,0.15),
29
+ DataTypes::Vector::XYZ.new( 50,0.751,0.31) )
30
+
31
+ sideboard << FiniteSolidPrimitives::Box.new(
32
+ DataTypes::Vector::XYZ.new(-50,0,0),
33
+ DataTypes::Vector::XYZ.new( 50,0.75,0.3) )
34
+ sideboard << CSG::Difference.new() { |sideboard_cutout|
35
+ sideboard_cutout << sideboard_miniblock
36
+ sideboard_cutout << CSG::Intersection.new() { |sideboard_cutoutinner|
37
+ sideboard_cutoutinner << sideboard_miniblock
38
+ sideboard_cutoutinner << FiniteSolidPrimitives::Cylinder.new(
39
+ DataTypes::Vector::XYZ.new(-50,0.6,0.15),
40
+ DataTypes::Vector::XYZ.new( 50,0.6,0.15), 0.15 )
41
+ }
42
+ }
43
+
44
+ sideboard << Texture.new() { |texture|
45
+ texture << Pigment.new() { |pigment|
46
+ pigment << "P_WoodGrain3A"
47
+ pigment << Base.new("colour_map") { |colourmap|
48
+ colourmap << "M_Teak"
49
+ }
50
+ pigment << Scale.new( 0.75 )
51
+ pigment << Rotate.new( DataTypes::Vector::XYZ.new(2,85,5) )
52
+ pigment << Translate.new( DataTypes::Vector::XYZ.new(100,200,300) )
53
+ }
54
+ }
55
+ }
56
+ entireWall << Rotate.new( rotate )
57
+ entireWall << Translate.new( translate )
58
+ }
59
+
60
+ self << entireWall
61
+ end
62
+ end
63
+
64
+ include RuPov
65
+ include Objects
66
+ include InfiniteSolidPrimitives
67
+ include Textures
68
+ include Pigments
69
+ include Methods
70
+ def initialize
71
+ super()
72
+ self << Include.new('colors.inc')
73
+ self << Include.new('woods.inc')
74
+ self << Include.new('teak.map')
75
+ global_settings = Base.new('global_settings') { |this|
76
+ # XXX Uncomment the line below to activate radiosity
77
+ # this << Base.new('radiosity')
78
+ }
79
+ self << global_settings
80
+
81
+ self << Camera::Basic.new(
82
+ Location.new( RuPov::DataTypes::Vector::XYZ.new(1,1.75,2) ),
83
+ LookAt.new( RuPov::DataTypes::Vector::XYZ.new(0,0.75,0) ) )
84
+
85
+ self << LightSources::PointLight.new(
86
+ RuPov::DataTypes::Vector::XYZ.new( 5,5,2 ), Colour.new( "White" ) )
87
+
88
+ floor = Plane.new( RuPov::DataTypes::Vector::XYZ.new( 0,1,0 ), 0) { |this|
89
+ this << Texture.new() { |this|
90
+ this << Checker.new( Colour.new( "White" ), Colour.new( "Blue" ) )
91
+ this << Scale.new( 1.7 )
92
+ this << Finish.new() { |this|
93
+ this << "reflection { 0.3 }"
94
+ }
95
+ }
96
+ }
97
+ self << floor
98
+
99
+ self << Wall.new(
100
+ RuPov::DataTypes::Vector::XYZ.new( 0,0,0),
101
+ RuPov::DataTypes::Vector::XYZ.new(0,0,-2) )
102
+ self << Wall.new(
103
+ RuPov::DataTypes::Vector::XYZ.new( 0,90,0),
104
+ RuPov::DataTypes::Vector::XYZ.new(-2,0,0) )
105
+
106
+ yield(self) if block_given? and self.class == Scene
107
+ end
108
+ end
@@ -0,0 +1,12 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FinitePatchPrimitives::Disc.new(
6
+ RuPov::DataTypes::Vector::XYZ.new( 0,0.5,0),
7
+ RuPov::DataTypes::Vector::XYZ.new(0,1,0),
8
+ 0.7,
9
+ 0.2) { |disc|
10
+ disc << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
11
+ }
12
+ }
@@ -0,0 +1,23 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FinitePatchPrimitives::Polygon.new(
6
+ [ RuPov::DataTypes::Vector::XY.new( 0,0 ),
7
+ RuPov::DataTypes::Vector::XY.new( 0,6 ),
8
+ RuPov::DataTypes::Vector::XY.new( 4,6 ),
9
+ RuPov::DataTypes::Vector::XY.new( 4,3 ),
10
+ RuPov::DataTypes::Vector::XY.new( 1,3 ),
11
+ RuPov::DataTypes::Vector::XY.new( 1,0 ),
12
+ RuPov::DataTypes::Vector::XY.new( 0,0 ),
13
+ RuPov::DataTypes::Vector::XY.new( 1,4 ),
14
+ RuPov::DataTypes::Vector::XY.new( 1,5 ),
15
+ RuPov::DataTypes::Vector::XY.new( 3,5 ),
16
+ RuPov::DataTypes::Vector::XY.new( 3,4 ),
17
+ RuPov::DataTypes::Vector::XY.new( 1,4 )
18
+ ] ) { |polygon|
19
+ polygon << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
20
+ polygon << RuPov::Methods::MultiValue.new( [0.2], "scale" )
21
+ polygon << RuPov::Methods::MultiValue.new( [RuPov::DataTypes::Vector::XYZ.new( 0,225,0 )], "rotate" )
22
+ }
23
+ }
@@ -0,0 +1,17 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Blob.new( 0.5 ) { |blob|
6
+ blob << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
7
+ RuPov::DataTypes::Vector::XYZ.new( -0.15, 0.5, -0.15), 0.45 ) { |sphere|
8
+ sphere << 1 # It's blob strength
9
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
10
+ }
11
+ blob << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
12
+ RuPov::DataTypes::Vector::XYZ.new( 0.15, 0.7, 0.15), 0.45 ) { |sphere|
13
+ sphere << 1 # It's blob strength
14
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Red" ) )
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,10 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Box.new(
6
+ RuPov::DataTypes::Vector::XYZ.new( -0.5,0,-0.5 ),
7
+ RuPov::DataTypes::Vector::XYZ.new( 0.5,1, 0.5 ) ) { |box|
8
+ box << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Cone.new(
6
+ RuPov::DataTypes::Vector::XYZ.new(0,0,0), 0.6,
7
+ RuPov::DataTypes::Vector::XYZ.new(0,1,0), 0.3 ) { |cone|
8
+ cone << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Cylinder.new(
6
+ RuPov::DataTypes::Vector::XYZ.new( 0,0,0),
7
+ RuPov::DataTypes::Vector::XYZ.new(0,1,0),
8
+ 0.5 ) { |cylinder|
9
+ cylinder << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
10
+ }
11
+ }
@@ -0,0 +1,17 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Lathe.new(
6
+ [
7
+ RuPov::DataTypes::Vector::XY.new( 0,0 ),
8
+ RuPov::DataTypes::Vector::XY.new( 1,1 ),
9
+ RuPov::DataTypes::Vector::XY.new( 2,3 ),
10
+ RuPov::DataTypes::Vector::XY.new( 2,4 ),
11
+ RuPov::DataTypes::Vector::XY.new( 2,5 ),
12
+ RuPov::DataTypes::Vector::XY.new( 0,4.75 )
13
+ ] ) { |lathe|
14
+ lathe << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
15
+ lathe << RuPov::Methods::MultiValue.new( [0.2], 'scale' )
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Prism.new(
6
+ 0,1,
7
+ [
8
+ RuPov::DataTypes::Vector::XY.new( 3,5 ),
9
+ RuPov::DataTypes::Vector::XY.new(-3,5 ),
10
+ RuPov::DataTypes::Vector::XY.new(-5,0 ),
11
+ RuPov::DataTypes::Vector::XY.new(-3,-5 ),
12
+ RuPov::DataTypes::Vector::XY.new( 3,-5 ),
13
+ RuPov::DataTypes::Vector::XY.new( 5,0 ),
14
+ RuPov::DataTypes::Vector::XY.new( 3,5 )
15
+ ] ) { |prism|
16
+ prism << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
17
+ prism << RuPov::Methods::Scale.new( 0.15 )
18
+ prism << RuPov::Methods::Translate.new( RuPov::DataTypes::Vector::XYZ.new(-0.2,0,-0.2) )
19
+ }
20
+ }
@@ -0,0 +1,17 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::SurfaceOfRevolution.new(
6
+ [
7
+ RuPov::DataTypes::Vector::XY.new( 0,0 ),
8
+ RuPov::DataTypes::Vector::XY.new( 1,1 ),
9
+ RuPov::DataTypes::Vector::XY.new( 2,3 ),
10
+ RuPov::DataTypes::Vector::XY.new( 2,4 ),
11
+ RuPov::DataTypes::Vector::XY.new( 2,5 ),
12
+ RuPov::DataTypes::Vector::XY.new( 0,4.75 )
13
+ ] ) { |sor|
14
+ sor << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
15
+ sor << RuPov::Methods::MultiValue.new( [0.2], 'scale' )
16
+ }
17
+ }
@@ -0,0 +1,10 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::Sphere.new(
6
+ RuPov::DataTypes::Vector::XYZ.new( 0, 0.5, 0),
7
+ 0.45 ) { |sphere|
8
+ sphere << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
9
+ }
10
+ }
@@ -0,0 +1,16 @@
1
+ require 'rupov'
2
+ require "./#{File.dirname(__FILE__)}/include/genericscene"
3
+
4
+ puts Scene.new() { |scene|
5
+ scene << RuPov::Objects::FiniteSolidPrimitives::SphereSweep.new(
6
+ [ RuPov::DataTypes::Vector::XYZ.new( 0, -0.1, 0), 0.1,
7
+ RuPov::DataTypes::Vector::XYZ.new( 0, 0, 0), 0.1,
8
+ RuPov::DataTypes::Vector::XYZ.new( -0.5, 0.25, 0), 0.075,
9
+ RuPov::DataTypes::Vector::XYZ.new( -0.5, 0.5, 0.5), 0.05,
10
+ RuPov::DataTypes::Vector::XYZ.new( 0.5, 0.75, 0.5), 0.025,
11
+ RuPov::DataTypes::Vector::XYZ.new( 0.5, 1, -0.5), 0.001,
12
+ RuPov::DataTypes::Vector::XYZ.new( 0, 1, 0), 0
13
+ ], 'b_spline' ) { |spheresweep|
14
+ spheresweep << RuPov::Textures::Pigments::SolidColour.new( RuPov::Methods::Colour.new( "Yellow" ) )
15
+ }
16
+ }