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