Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Last active August 30, 2017 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obelisk68/2eb4d70c2c83a89f43f187590847af8a to your computer and use it in GitHub Desktop.
Save obelisk68/2eb4d70c2c83a89f43f187590847af8a to your computer and use it in GitHub Desktop.
円が降ってくる(スクリーンセーバーもどき)
require 'oekaki'
Width, Height = if ARGV.size == 2
ARGV.map(&:to_i)
else
[1000, 700]
end
Max_r, Min_r = 40, 10
ColorMax = 65535
MaxNum = 60
class Circle
def initialize(ob)
@slot = ob
@width, @height = Width, Height
renewal
@y = rand(@height)
end
attr_reader :height
attr_writer :y
def renewal
@width, @height = @slot.get_window_size
@max_r = rand(Max_r - Min_r) + Min_r
@x = rand(@width)
@y = -rand(@max_r)
@color = [rand(ColorMax), rand(ColorMax), rand(ColorMax)]
@fall_step = 1 + rand * 3
@r = 1
@r_step = rand * 0.2 + 0.8
end
def paint
@slot.color(@color[0], @color[1], @color[2])
@slot.circle(true, @x, @y, @r)
@y += @fall_step
@r += @r_step
@r_step *= -1 if @r > @max_r or @r < 1
renewal if @y > @height + Max_r
true
end
end
Oekaki.app width: Width, height: Height, resizable: true do
circles = []
MaxNum.times {circles << Circle.new(self)}
black = color(0, 0, 0)
draw do
clear
end
timer(60) do
clear(black)
circles.each(&:paint)
end
window_changed do
clear(black)
circles.each do |c|
c.renewal
c.y = rand(c.height)
c.paint
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment