|
| 1 | +#!/usr/bin/env jruby -v -W2 |
| 2 | +# frozen_string_literal: true |
| 3 | +require 'propane' |
| 4 | +# Iconic ruby-processing example for Propane |
| 5 | +class MethodChaining < Propane::App |
| 6 | + load_library :hype |
| 7 | + include_package 'hype' |
| 8 | + |
| 9 | + def settings |
| 10 | + size(640, 640) |
| 11 | + end |
| 12 | + |
| 13 | + def setup |
| 14 | + sketch_title('Method Chaining') |
| 15 | + H.init(self) |
| 16 | + H.background(color('#242424')) |
| 17 | + rect1 = HRect.new(100) |
| 18 | + rect1.rounding(10) # set corner rounding |
| 19 | + rect1.stroke_weight(6) # set stroke weight |
| 20 | + rect1.stroke(color('#000000'), 150) # set stroke color and alpha |
| 21 | + rect1.fill(color('#FF6600')) # set fill color |
| 22 | + rect1.anchor_at(H::CENTER) # set where anchor point is / key point for rotation and positioning |
| 23 | + rect1.rotation(45) # set rotation of the rect |
| 24 | + rect1.loc(100, height / 2) # set x and y location |
| 25 | + H.add(rect1) |
| 26 | + |
| 27 | + # here's the same code / with method chaining |
| 28 | + |
| 29 | + rect2 = HRect.new(100) |
| 30 | + rect2.rounding(10) |
| 31 | + .stroke_weight(6) |
| 32 | + .stroke(color('#000000'), 150) |
| 33 | + .fill(color('#FF9900')) |
| 34 | + .anchor_at(H::CENTER) |
| 35 | + .rotation(45) |
| 36 | + .loc(247, height / 2) |
| 37 | + H.add(rect2) |
| 38 | + |
| 39 | + # here's the same code / minus the hard returns and indentation (tabs are bad) |
| 40 | + |
| 41 | + rect3 = HRect.new(100) |
| 42 | + rect3.rounding(10).stroke_weight(6).stroke(color('#000000'), 150).fill(color('#FFCC00')).anchor_at(H::CENTER).rotation(45).loc(394, height / 2) |
| 43 | + H.add(rect3) |
| 44 | + |
| 45 | + H.draw_stage # paint the stage |
| 46 | + |
| 47 | + # here is the non HYPE version / basic processing syntax |
| 48 | + |
| 49 | + push_matrix |
| 50 | + stroke_weight(6) |
| 51 | + stroke(color('#000000'), 150) |
| 52 | + fill(color('#FF3300')) |
| 53 | + translate(width - 100, (height / 2)) |
| 54 | + rotate(45.radians) |
| 55 | + rect(0, 0, 100, 100, 10, 10, 10, 10) |
| 56 | + pop_matrix |
| 57 | + stroke_weight(1) |
| 58 | + stroke(color('#0095a8')) |
| 59 | + line(0, height / 2, width, height / 2) |
| 60 | + end |
| 61 | +end |
| 62 | + |
| 63 | +MethodChaining.new |
0 commit comments