Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
61
Task/Plasma-effect/Ruby/plasma-effect.rb
Normal file
61
Task/Plasma-effect/Ruby/plasma-effect.rb
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
attr_reader :buffer, :palette, :r, :g, :b, :rd, :gd, :bd, :dim
|
||||
|
||||
def settings
|
||||
size(600, 600)
|
||||
end
|
||||
|
||||
def setup
|
||||
sketch_title 'Plasma Effect'
|
||||
frame_rate 25
|
||||
@r = 42
|
||||
@g = 84
|
||||
@b = 126
|
||||
@rd = true
|
||||
@gd = true
|
||||
@bd = true
|
||||
@dim = width * height
|
||||
@buffer = Array.new(dim)
|
||||
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
|
||||
if rd
|
||||
@r -= 1
|
||||
@rd = false if r.negative?
|
||||
else
|
||||
@r += 1
|
||||
@rd = true if r > 128
|
||||
end
|
||||
if gd
|
||||
@g -= 1
|
||||
@gd = false if g.negative?
|
||||
else
|
||||
@g += 1
|
||||
@gd = true if g > 128
|
||||
end
|
||||
if bd
|
||||
@b -= 1
|
||||
@bd = false if b.negative?
|
||||
else
|
||||
@b += 1
|
||||
@bd = true if b > 128
|
||||
end
|
||||
@palette = (0..127).map do |col|
|
||||
s1 = sin(col * Math::PI / 25)
|
||||
s2 = sin(col * Math::PI / 50 + Math::PI / 4)
|
||||
color(r + s1 * 128, g + s2 * 128, b + s1 * 128)
|
||||
end
|
||||
dim.times do |idx|
|
||||
pixels[idx] = palette[(buffer[idx] + frame_count) & 127]
|
||||
end
|
||||
update_pixels
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue