|
| 1 | +#!/usr/bin/env jruby -v -w |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +require 'propane' |
| 5 | + |
| 6 | +class VeraMolnar < Propane::App |
| 7 | + # Creative Coding |
| 8 | + # # # # # |
| 9 | + # Vera Molnar – 25 Squares |
| 10 | + # # # # # |
| 11 | + # Interpretation by Martin Vögeli |
| 12 | + # Converted to JRubyArt Martin Prout |
| 13 | + # # # # # |
| 14 | + # Based on code by Indae Hwang and Jon McCormack |
| 15 | + # |
| 16 | + |
| 17 | + def settings |
| 18 | + size(600, 600) |
| 19 | + end |
| 20 | + |
| 21 | + def setup |
| 22 | + sketch_title '25 Squares' |
| 23 | + rect_mode(CORNER) |
| 24 | + no_stroke |
| 25 | + frame_rate(1) # set the frame rate to 1 draw call per second |
| 26 | + end |
| 27 | + |
| 28 | + def draw |
| 29 | + background(180) # clear the screen to grey |
| 30 | + grid_size = 5 # rand(3..12) # select a rand number of squares each frame |
| 31 | + gap = 5 # rand(5..50) # select a rand gap between each square |
| 32 | + # calculate the size of each square for the given number of squares and gap between them |
| 33 | + cellsize = (width - (grid_size + 1) * gap) / grid_size |
| 34 | + # calculate shadow offset |
| 35 | + offset_x = cellsize / 16.0 |
| 36 | + offset_y = cellsize / 16.0 |
| 37 | + grid_size.times do |i| |
| 38 | + grid_size.times do |j| |
| 39 | + # fill(140, 180) # shadow |
| 40 | + # rect(gap * (i + 1) + cellsize * i + offset_x, gap * (j + 1) + cellsize * j + offset_y, cellsize, cellsize) |
| 41 | + if rand(0..5) > 4 |
| 42 | + fill(color('#a11220'), 180.0) # Note how to create transparent fill with web color JRubyArt |
| 43 | + else |
| 44 | + fill(color('#884444'), 180.0) |
| 45 | + end |
| 46 | + rect(gap * (i + 1) + cellsize * i + rand(-5..5), gap * (j + 1) + cellsize * j + rand(-5..5), cellsize, cellsize) |
| 47 | + end |
| 48 | + end |
| 49 | + # save your drawings when you press keyboard 's' continually |
| 50 | + if (key_pressed? && key == 's') |
| 51 | + save_frame('######.jpg') |
| 52 | + end |
| 53 | + end #end of draw |
| 54 | +end # class |
| 55 | + |
| 56 | +VeraMolnar.new |
0 commit comments