#!ruby -Ku # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2017/04/09 13:14:56 +0900> # # tinycolorsys.rb の動作テスト require 'dxruby' require_relative 'tinycolorsys' include TinyColorSys fnt = Font.new(28) v2 = 0.5 set_hls = true Window.loop do break if Input.keyPush?(K_ESCAPE) set_hls = !set_hls if Input.mousePush?(M_LBUTTON) v0 = Input.mousePosX.to_f / (Window.width - 1) v1 = Input.mousePosY.to_f / (Window.height - 1) v2 += (Input.keyDown?(K_UP))? (1.0 / 255.0) : 0 v2 -= (Input.keyDown?(K_DOWN))? (1.0 / 255.0) : 0 v0 = [[v0, 1.0].min, 0.0].max v1 = [[v1, 1.0].min, 0.0].max v2 = [[v2, 1.0].min, 0.0].max if set_hls h = v0 l = v1 s = v2 r, g, b = hls_to_rgb(h, l, s) h = (h * 360).to_i l = (l * 100).to_i s = (s * 100).to_i else r = (v0 * 255).to_i g = (v1 * 255).to_i b = (v2 * 255).to_i h, l, s = rgb_to_hls(r, g, b) h = (360 * h).to_i l = (100 * l).to_i s = (100 * s).to_i end Window.bgcolor = [r, g, b] col = (l < 50)? C_WHITE : C_BLACK msg = (set_hls)? "use HLS" : "use RGB" Window.drawFont(4, 4, msg, fnt, :color => col) Window.drawFont(4, 40, "RGB=#{r}, #{g}, #{b}", fnt, :color => col) Window.drawFont(4, 80, "HLS=#{h}, #{l}, #{s}", fnt, :color => col) Window.drawFont(4, 120, "(mouse x/y , Up/Down key)", fnt, :color => col) end