Last active
June 9, 2017 07:52
-
-
Save monkstone/40944916940eff071a2a7bb661779170 to your computer and use it in GitHub Desktop.
Using Create Graphics and Grid methods propane
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env jruby | |
# frozen_string_literal: false | |
require 'propane' | |
class GridDemo < Propane::App | |
attr_reader :tile # attr_accessor is frowned on in ruby circles | |
def settings | |
size(700, 100) | |
end | |
def setup | |
sketch_title 'Grid Demo' | |
@tile = create_graphics(50, 50) | |
background(0) | |
end | |
def draw | |
run_tile | |
grid(width, height, 50, 50) do |x, y| # exclusively JRubyArt and propane method | |
image(tile, x, y) | |
end | |
end | |
def run_tile | |
x = rand(20..tile.width-20) | |
y = rand(20..tile.height-20) | |
tile.begin_draw | |
tile.no_stroke | |
tile.fill(0, 20) | |
tile.rect(0, 0, tile.width, tile.height) | |
tile.fill(255) | |
tile.ellipse(x, y, 10, 10) | |
tile.end_draw | |
end | |
end | |
GridDemo.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment