|
| 1 | +#!/usr/bin/env jruby |
| 2 | +require 'propane' |
| 3 | + |
| 4 | +# Based on a sketch by Javi F Gorostiza |
| 5 | +# https://openprocessing.org/sketch/432548 |
| 6 | +class PsychedelicNoise < Propane::App |
| 7 | + load_library :generator |
| 8 | + attr_reader :img, :colors, :remap1, :remap2 |
| 9 | + |
| 10 | + def setup |
| 11 | + sketch_title 'Psychedelic Noise Pattern' |
| 12 | + color_mode(RGB, 1.0) |
| 13 | + @theta = 0 |
| 14 | + @phi = 0 |
| 15 | + # the dimensions of the image are twice the dimentions of |
| 16 | + # the canvas to add antialiasing when the image is reduced |
| 17 | + @img = create_image(2 * width, 2 * height, RGB) |
| 18 | + @colors = (0..255).map { color(rand, rand, rand) } |
| 19 | + end |
| 20 | + |
| 21 | + |
| 22 | + def draw |
| 23 | + # fill the array with rand colors |
| 24 | + # create pattern |
| 25 | + img.load_pixels |
| 26 | + iwidth = img.width |
| 27 | + iheight = img.height |
| 28 | + |
| 29 | + grid(iwidth, iheight) do |x, y| |
| 30 | + # map x and y to angles between 0 and TWO_PI |
| 31 | + theta = map1d(x, 0..iwidth, 0..TWO_PI) |
| 32 | + phi = map1d(y, 0..iheight, 0..TWO_PI) |
| 33 | + generator = Generator.new(phi, theta) |
| 34 | + # apply noise twice and use the equivalent color on the pallete |
| 35 | + img.pixels[x + y * iwidth] = colors[generator.noisef(frame_count / 5)] |
| 36 | + end |
| 37 | + img.update_pixels |
| 38 | + # display pattern |
| 39 | + image(img, 0, 0, width, height) # the image is reduce to the size of the canvas to make it smooth |
| 40 | + end |
| 41 | + |
| 42 | + def key_pressed |
| 43 | + save(data_path('image.png')) |
| 44 | + end |
| 45 | + |
| 46 | + def settings |
| 47 | + size(500, 500) |
| 48 | + end |
| 49 | +end |
| 50 | + |
| 51 | +PsychedelicNoise.new |
0 commit comments