Sha256: b40e2832093b04898400839a6e4ae72fb87435ce183d6fd57581e13aa0ce5429

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8
# frozen_string_literal: true
# Creating Colors (Homage to Albers).
#
require 'propane'

# Creating variables for colors that may be referred to
# in the program by their name, rather than a number.
class CreatingColors < Propane::App
  attr_reader :redder, :yellower, :orangish
  
  WEB = %w(#CC6600 #CC9900 #993300)

  def setup
    size 640, 360
    palette = web_to_color_array(WEB)
    @redder = palette[0]
    @yellower = palette[1]
    @orangish = palette[2]
    # These statements are equivalent to the statements above.
    # Programmers may use the format they prefer.

    # hex color as a String (NB quotes are required)
    @redder = palette[0]
    @yellower = palette[1]
    @orangish = palette[2]

    # @redder = color '#CC6600'
    # @yellower = color '#CC9900'
    # @orangish = color '#993300'

    # or alternatively as a hexadecimal

    # @redder = color 0xFFCC6600
    # @yellower = color 0xFFCC9900
    # @orangish = color 0xFF993300
    puts int_to_ruby_colors(palette)
  end

  def draw
    no_stroke
    background 51, 0, 0
    push_matrix
    translate 80, 80
    fill orangish
    rect 0, 0, 200, 200
    fill yellower
    rect 40, 60, 120, 120
    fill redder
    rect 60, 90, 80, 80
    pop_matrix
    push_matrix
    translate 360, 80
    fill redder
    rect 0, 0, 200, 200
    fill orangish
    rect 40, 60, 120, 120
    fill yellower
    rect 60, 90, 80, 80
    pop_matrix
  end
end

CreatingColors.new title: 'Homage to Albers'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
propane-0.7.0-java examples/regular/creating_colors.rb
propane-0.6.0-java examples/regular/creating_colors.rb