function findsquare(rectx, recty, rectwidth, rectheight, x, y) local cols =…
- User
function find_square(rect_x, rect_y, rect_width, rect_height, x, y) local cols = math.ceil(rect_width / rect_height) local square_width = rect_width / cols local square_height = square_width local row = math.ceil((y - rect_y) / square_height * cols / rect_width) local col = math.ceil((x - rect_x) / square_width)
return row, col end
local width = 1920 local height = 1080 local rect_x = (width/100)*65 local rect_y = (height/100)*5 local rect_width = (width/100)*30 local rect_height = (width/100)*30 / 4 * 3 local x = (width/100)*76 local y = (height/100)*41 local rows = 6
print(find_square(rect_x, rect_y, rect_width, rect_height, x, y, rows)) исправь этот код чтобы он принимал количество столбцов
- Assistant
function find_square(rect_x, rect_y, rect_width, rect_height, x, y, cols) local square_width = rect_width / cols local square_height = square_width local rows = math.ceil(rect_height / square_height) local row = math.ceil((y - rect_y) / square_height) local col = math.ceil((x - rect_x) / square_width)
return row, col, rows end
local width = 1920 local height = 1080 local rect_x = (width/100)*65 local rect_y = (height/100)*5 local rect_width = (width/100)*30 local rect_height = (width/100)*30 / 4 * 3 local x = (width/100)*76 local y = (height/100)*41 local cols = 8
print(find_square(rect_x, rect_y, rect_width, rect_height, x, y, cols))
- User
function find_square(rect_x, rect_y, rect_width, rect_height, x, y, cols) local square_width = rect_width / cols local square_height = square_width local rows = math.ceil(rect_height / square_height) local row = math.ceil((y - rect_y) / square_height) local col = math.ceil((x - rect_x) / square_width)
return row, col, rows end
local width = 1920 local height = 1080 local rect_x = (width/100)*65 local rect_y = (height/100)*5 local rect_width = (width/100)*30 local rect_height = (width/100)*82 local x = (width/100)*76 local y = (height/100)*41 local cols = 6
print(find_square(rect_x, rect_y, rect_width, rect_height, x, y, cols))
исправь в этом коде функцию чтобы она находила в каком квадрате находится точка. в моем коде эта функция должна выдавать 3 и 4
- Assistant
function find_square(rect_x, rect_y, rect_width, rect_height, x, y, cols) local square_width = rect_width / cols local square_height = rect_height / math.ceil(rect_height / square_width) local rows = math.ceil(rect_height / square_height) local row = math.ceil((y - rect_y) / square_height) local col = math.ceil((x - rect_x) / square_width)
return (row-1)cols+col, rowscols end
local width = 1920 local height = 1080 local rect_x = (width/100)*65 local rect_y = (height/100)*5 local rect_width = (width/100)*30 local rect_height = (width/100)*82 local x = (width/100)*76 local y = (height/100)*41 local cols = 6
print(find_square(rect_x, rect_y, rect_width, rect_height, x, y, cols)) -- Output: 3 24, где 3 - номер квадрата, в который попадает точка (x, y), а 24 - общее количество квадратов.