|
5 | 5 | # the mouse to zoom and set the density of the matrix by typing numbers 1-5. |
6 | 6 | # This program displays a series of lines with their heights corresponding to |
7 | 7 | # a color value read from an image. |
8 | | -ColoredExtrusion < Processing::App |
| 8 | +class ColoredExtrusion < Processing::App |
9 | 9 | def setup |
10 | 10 | sketch_title 'Colored Extrusion' |
11 | 11 | no_fill |
@@ -33,22 +33,20 @@ def draw |
33 | 33 | else |
34 | 34 | @sval -= 0.01 |
35 | 35 | end |
36 | | - @sval = constrain @sval, 1.0, 2.5 |
| 36 | + @sval = @sval.clamp(1.0, 2.5) |
37 | 37 | translate width / 2 + @nmx * @sval - 100, height / 2 + @nmy * @sval - 200, -50 |
38 | 38 | scale @sval |
39 | 39 | rotate_z PI / 9 - @sval + 1 |
40 | 40 | rotate_x PI / @sval / 8 - 0.125 |
41 | 41 | rotate_y @sval / 8 - 0.125 |
42 | 42 | translate -width / 2, -height / 2 |
43 | | - (0...@img.height).step(@res) do |y| |
44 | | - (0...@img.width).step(@res) do |x| |
45 | | - rr = red @img_pixels[y][x] |
46 | | - gg = green @img_pixels[y][x] |
47 | | - bb = blue @img_pixels[y][x] |
48 | | - tt = rr + gg + bb |
49 | | - stroke rr, gg, gg |
50 | | - line y, x, tt / 10 - 20, y, x, tt / 10 |
51 | | - end |
| 43 | + grid(@img.width, @img.height, @res, @res) do |x, y| |
| 44 | + rr = red @img_pixels[y][x] |
| 45 | + gg = green @img_pixels[y][x] |
| 46 | + bb = blue @img_pixels[y][x] |
| 47 | + tt = rr + gg + bb |
| 48 | + stroke rr, gg, gg |
| 49 | + line y, x, tt / 10 - 20, y, x, tt / 10 |
52 | 50 | end |
53 | 51 | end |
54 | 52 |
|
|
0 commit comments