math.randomseed(sys.Datetime().milliseconds)`
local ui = require "ui"
local picture= {}
local alpha= {}
local speed= {}
local balls= 6
local win = ui.Window("Ball Hit", 1000, 700)
local buton= ui.Button(win,"Click Move!", 20, 20, 100, 50)
horizantal_1= ui.Picture(win, "Resim_Icon/YatayCizgi.png", 130,30)
horizantal_2= ui.Picture(win, "Resim_Icon/YatayCizgi.png", 130,640)
vertical_1= ui.Picture(win, "Resim_Icon/DuseyCizgi.png", 130,40)
vertical_2= ui.Picture(win, "Resim_Icon/DuseyCizgi.png", 970,40)
win:show()
decided = false
function alpha_Random(_i, _j)
return math.rad(math.random(_i, _j))
end
function control(_x, _y, _i)
if _x <= 140 then
alpha[_i]= math.rad(math.random(0,180))
end
if _x >= 935 then
alpha[_i]= math.rad(math.random(180,360))
end
if _y <= 42 then
alpha[_i]= math.rad(math.random(90,270))
end
if _y >= 605 then
alpha[_i]= math.rad(math.random(270,360))
end
end
function buton:onClick()
if decided == false then
decided = true
buton.text= "Click Stop!"
for i=1, balls do -- top sayisi
alpha[i]= alpha_Random(0, 360)
picture[i]= ui.Picture(win, "Resim_Icon/top_32x32.png", math.random(200, 850), math.random(100, 500))
speed[i]= math.random(2, 18)
end
else
decided = false
buton.text= "Click Move!"
for i=1, #picture do
ui.remove(picture[i])
end
end
end
repeat
if decided == true then
for i=1, balls do
picture[i].x = picture[i].x + speed[i]*math.sin(alpha[i])
picture[i].y = picture[i].y - speed[i]*math.cos(alpha[i])
control(picture[i].x, picture[i].y, i)
end
end
ui.update()
until not win.visible