Plasma effect: Difference between revisions

no edit summary
m (Phix/pGUI)
No edit summary
Line 1,477:
 
[http://www.dropbox.com/s/gdioouv328m2d60/PlasmaEffect.jpg?dl=0 Plasma effect]
 
 
=={{header|Ruby}}==
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language
<lang ruby>
attr_reader :buffer, :palette, :r, :g, :b, :rd, :gd, :bd
 
def settings
size(600, 600)
end
 
def setup
sketch_title 'Plasma'
frame_rate 15
@r = 42
@g = 84
@b = 126
@buffer = Array.new(width * height)
grid(width, height) do |x, y|
buffer[x + y * width] = (
(
(128 + (128 * sin(x / 32.0))) +
(128 + (128 * cos(y / 32.0))) +
(128 + (128 * sin(Math.hypot(x, y) / 32.0)))
) / 4
).to_i
end
load_pixels
end
 
def draw
@rd = true if r > 128
if rd
@r -= 1
else
@r += 1
end
@rd = false if r.negative?
@gd = true if g > 128
if gd
@g -= 1
else
@g += 1
end
@gd = false if g.negative?
@bd = true if b > 128
if bd
@b -= 1
else
@b += 1
end
@bd = false if b.negative?
@palette = (0..128).map do |col|
s_1 = sin(col * Math::PI / 25)
s_2 = sin(col * Math::PI / 50 + Math::PI / 4)
color(r + s_1 * 128, g + s_2 * 128, b + s_1 * 128)
end
 
buffer.length.times do |i|
pixels[i] = palette[(buffer[i] + frame_count) & 127]
end
update_pixels
end
 
</lang>
 
=={{header|Scala}}==
Anonymous user