|
| 1 | +#!/usr/bin/env jruby |
| 2 | +# frozen_string_literal: true |
| 3 | +require 'propane' |
| 4 | +# takes quite a long time to render |
| 5 | + |
| 6 | +class RandomGrid < Propane::App |
| 7 | + PALETTE = %w(#74AED7 #FFE4F3 #FEE597).freeze |
| 8 | + COULEURS = %i(ciel pinking yolk).freeze |
| 9 | + STEP = 84 |
| 10 | + attr_reader :shapes, :web |
| 11 | + |
| 12 | + def settings |
| 13 | + size 2400, 6372, P2D |
| 14 | + end |
| 15 | + |
| 16 | + def setup |
| 17 | + sketch_title 'Random Grid' |
| 18 | + @web = COULEURS.zip(web_to_color_array(PALETTE)).to_h |
| 19 | + no_stroke |
| 20 | + shapeOne = createShape(ELLIPSE, 0, 0, 20, 20) |
| 21 | + shapeOne.setFill(web[:pinking]) |
| 22 | + shapeTwo = createShape(GROUP) |
| 23 | + one = createShape(ELLIPSE, 42, 42, 20, 20) |
| 24 | + one.setFill(web[:pinking]) |
| 25 | + two = createShape(ELLIPSE, 21, 21, 20, 20) |
| 26 | + one.setFill(web[:yolk]) |
| 27 | + shapeTwo.addChild(one) |
| 28 | + shapeTwo.addChild(two) |
| 29 | + shapeThree = createShape(GROUP) |
| 30 | + base = createShape(ELLIPSE, 0, 0, 20, 20) |
| 31 | + base.setFill(web[:pinking]) |
| 32 | + three = createShape(ELLIPSE, 21, 21, 20, 20) |
| 33 | + three.setFill(web[:pinking]) |
| 34 | + four = createShape(ELLIPSE, 42, 42, 20, 20) |
| 35 | + four.setFill(web[:yolk]) |
| 36 | + shapeThree.addChild(base) |
| 37 | + shapeThree.addChild(three) |
| 38 | + shapeThree.addChild(four) |
| 39 | + shapeFour = createShape(GROUP) |
| 40 | + five = createShape(ELLIPSE, 0, 0, 20, 20) |
| 41 | + five.setFill(web[:pinking]) |
| 42 | + six = createShape(ELLIPSE, 21, 21, 20, 20) |
| 43 | + six.setFill(web[:pinking]) |
| 44 | + seven = createShape(ELLIPSE, 42, 42, 20, 20) |
| 45 | + seven.setFill(web[:pinking]) |
| 46 | + eight = createShape(ELLIPSE, 63, 63, 20, 20) |
| 47 | + eight.setFill(web[:yolk]) |
| 48 | + shapeFour.addChild(five) |
| 49 | + shapeFour.addChild(six) |
| 50 | + shapeFour.addChild(seven) |
| 51 | + shapeFour.addChild(eight) |
| 52 | + @shapes = [shapeOne, shapeTwo, shapeThree, shapeFour] |
| 53 | + end |
| 54 | + |
| 55 | + def draw |
| 56 | + background(web[:ciel]) # Sky blue |
| 57 | + grid(width, height, STEP, STEP) do |col, row| |
| 58 | + push_matrix |
| 59 | + translate col, row |
| 60 | + rkey = rand(0..6) |
| 61 | + shape(shapes[rkey]) if rkey < 4 |
| 62 | + pop_matrix |
| 63 | + end |
| 64 | + save(data_path('random.png')) |
| 65 | + no_loop |
| 66 | + end |
| 67 | +end |
| 68 | + |
| 69 | +RandomGrid.new |
0 commit comments