2007/11/07
■[graphic]きょうのglitch

# HSYNC Glitch
# inspired by http://flickr.com/photos/mikrosopht, via hysysk
# 2007-11-06 t.koyachi
require "java"
include_class "processing.core.PApplet"
include_class "processing.core.PImage"
class Sketch < PApplet
def setup
_height = 160
_width = 160
size _width, _height
background 255
no_stroke
frameRate 3
imgsrc = loadImage('utamaru160_meagne.PNG')
# _height = imgsrc.height
# _width = imgsrc.width
loadPixels
last_line = imgsrc.height
num = Integer(rand(10)) + 1
interval = Integer(last_line / num)
timing = []
line = 0
num.times do |i|
line += Integer(rand(interval)) + 1
timing.push(line)
p "timing = #{line}"
end
tick = 1
offset = 0
last_effect = 'tick'
current_line = 0
_height.times do |y|
if timing[current_line] == y then
if last_effect == 'offset' then
tick = Integer(rand(100)) # - 5
p "y=#{y}, tick=#{tick}"
last_effect = 'tick'
else
offset = Integer(rand(20))
p "y=#{y}, offset=#{offset}"
last_effect = 'offset'
end
current_line += 1
end
_width.times do |x|
current_point = y * _width + x
src_point = current_point + tick * y + offset
if src_point >= _height * _width then
src_point = current_point - _width
end
pixels[current_point] = imgsrc.pixels[src_point]
end
end
updatePixels
end
end
JFrame = javax.swing.JFrame
def run applet
frame = JFrame.new applet.class.to_s
frame.content_pane.add applet
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
applet.init
frame.pack
frame.visible = true
end
if $0 == __FILE__
run Sketch.new
end
jrubyでprocessingのコードは(Processing by Ruby,その2)を参考にしました。
トラックバック - http://d.hatena.ne.jp/koyachi/20071107/1194413657
リンク元
- 45 http://reader.livedoor.com/reader/
- 24 http://hysysk.blogspot.com/2007/11/todays-glitch.html
- 21 http://d.hatena.ne.jp/
- 20 http://tako3.com/http://d.hatena.ne.jp/koyachi/
- 19 http://www.tumblr.com/dashboard
- 11 http://b.hatena.ne.jp/entrylist?sort=hot
- 11 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=GRF&q=CamStudio 音声&btnG=検索&lr=lang_ja
- 11 http://www.google.co.jp/search?sourceid=navclient&aq=t&hl=ja&ie=UTF-8&rlz=1T4GZHZ_jaJP228JP229&q=perl+best+practices
- 10 http://b.hatena.ne.jp/
- 10 http://www.google.co.jp/search?hl=ja&client=firefox&rls=org.mozilla:ja:official&hs=4dn&q=GoogleAdSense 内容 変更&btnG=検索&lr=lang_ja