|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require 'picrate' |
2 | 4 | # Earth model with bump mapping, specular texture and dynamic cloud layer. |
3 | 5 | # Adapted from the THREE.js tutorial to processing by Andres Colubri, |
4 | 6 | # translated to picrate by Martin Prout: |
5 | 7 | # http://learningthreejs.com/blog/2013/09/16/how-to-make-the-earth-in-webgl/ |
6 | 8 | class BlueMarble < Processing::App |
7 | | - attr_reader :earth, :clouds, :earth_shader, :cloud_shader, :earth_rotation |
| 9 | + attr_reader :cloud_shader, :clouds, :earth, :earth_shader, :earth_rotation |
8 | 10 | attr_reader :clouds_rotation, :target_angle |
9 | 11 |
|
10 | | - SHADERS = %w(EarthFrag.glsl EarthVert.glsl CloudFrag.glsl CloudVert.glsl).freeze |
11 | | - SHADER_NAME = %i(earth_frag earth_vert cloud_frag cloud_vert).freeze |
12 | | - IMAGES = %w(earthmap1k earthcloudmap earthcloudmaptrans earthbump1k earthspec1k).freeze |
13 | | - IMAGE_NAME = %i(earth_tex cloud_tex alpha_tex bump_map spec_map).freeze |
| 12 | + SHADER_NAME = %i[earth_frag earth_vert cloud_frag cloud_vert].freeze |
| 13 | + IMAGE_NAME = %i[earth_tex cloud_tex alpha_tex bump_map spec_map].freeze |
14 | 14 |
|
15 | 15 | def setup |
16 | 16 | sketch_title 'Blue Marble' |
17 | 17 | @earth_rotation = 0 |
18 | 18 | @clouds_rotation = 0 |
19 | | - glsl_files = SHADERS.map { |shade| data_path(shade) } |
20 | | - shaders = SHADER_NAME.zip(glsl_files.to_java(:string)).to_h |
21 | | - images = IMAGES.map { |img| load_image(data_path("#{img}.jpg")) } |
| 19 | + glsl_files = shader_paths.to_java(:string) |
| 20 | + shaders = SHADER_NAME.zip(glsl_files).to_h |
| 21 | + images = init_images |
22 | 22 | textures = IMAGE_NAME.zip(images).to_h |
23 | 23 | @earth_shader = load_shader(shaders[:earth_frag], shaders[:earth_vert]) |
24 | 24 | earth_shader.set('texMap', textures[:earth_tex]) |
@@ -55,6 +55,18 @@ def draw |
55 | 55 | @clouds_rotation += 0.001 |
56 | 56 | end |
57 | 57 |
|
| 58 | + def init_images |
| 59 | + %w[earthmap1k earthcloudmap earthcloudmaptrans earthbump1k earthspec1k].map do |img| |
| 60 | + load_image(data_path(format('%<name>s.jpg', name: img))) |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + def shader_paths |
| 65 | + %w[EarthFrag EarthVert CloudFrag CloudVert].map do |shader| |
| 66 | + data_path(format('%<name>s.glsl', name: shader)) |
| 67 | + end |
| 68 | + end |
| 69 | + |
58 | 70 | def settings |
59 | 71 | size(600, 600, P3D) |
60 | 72 | end |
|
0 commit comments