Math question regarding columns and rows
#1
Posted 28 July 2012 - 11:36 AM
Example:
Total Rows = 3
Total Columns = 3
Item Index = 5
Based on the example, we can picture out that it's a 3x3 grid and that the 5th item is in row 2 and column 2. What is the math formula to determine it's current row and column position?
#2
Posted 28 July 2012 - 11:44 AM
#3
Posted 28 July 2012 - 11:55 AM
Let's say there are 6 windows:
cols := Ceil(Sqrt(6))
rows := Ceil(Sqrt(6))
if (cols*(rows-1) >= 6)
rows--This should give me 3 columns and 2 rows, how would I know the current window's position in the grid.? Window 1 should be in the row 1 and column 1; Window 2 should be in row 1 column 2 ans so on...
#4
Posted 28 July 2012 - 02:01 PM
Total Rows = 3
Total Columns = 3
Item Index = 5
Based on the example, we can picture out that it's a 3x3 grid and that the 5th item is in row 2 and column 2.
What is the math formula to determine it's current row and column position?
TotalRows := 3 [color=#FF0000]; Not used[/color] TotalColumns := 3 ItemIndex := 5 Row := Ceil( ItemIndex / TotalColumns ) Col := ( C := Mod( ItemIndex, TotalColumns ) ) ? C : TotalColumns Msgbox % Row "," Col
#5
Posted 28 July 2012 - 02:54 PM
rows := 3
cols := 3
Item_Index := 5
pos_Cols =
pos_Rows = 1
Loop, % Item_Index
{
pos_Cols++
if pos_Cols > % cols
{
pos_Cols = 1
pos_Rows++
}
}
MsgBox, Column Pos: %pos_Cols%, Row Pos: %pos_Rows%
#6
Posted 28 July 2012 - 04:48 PM
Here is a very related code I created some time ago.
Change the variables var_TotalGrid and var_CellSize to test it.
----------------------------------------------------------------------------------------------
License: GNU AGPL v3.0 ( see the quick guide )
Please check: MasterFocus's Home Topic
This post's latest update: 03/september/2012
Latest code modification: 29/november/2010
----------------------------------------------------------------------------------------------
Script:
Grid Template
Description:
This template tries to find the best way to fit images inside a Gui (like a grid)
Additional info:
< none >
Changelog:
29/november/2010
• Initial version
Code:
; By MasterFocus
; Licensed under GNU AGPL v3
; Please see the following link for more information:
; http://www.autohotkey.com/community/viewtopic.php?p=554782#p554782
; Create a Gui to show the images
Gui, -Caption +Border
Gui, Color, White
Gui, Margin, 0, 0
var_TotalGrid := 8 ; total number of grid cells
var_CellSize := 100 ; side size (each cell is a square)
Loop, %var_TotalGrid% ; Define example pictures (in this case, just text really)
var_Image%A_Index% := "img " A_INDEX " here"
; Define some variables, just to keep track of them
var_ImgPerLine := var_Count := var_TempA := 0
var_TempB := var_TempC := var_TempMod := 0
; Calculate number of images per line
var_TempA := Sqrt(var_TotalGrid)
var_TempB := Floor(var_TempA)
var_TempC := !( var_TempA = var_TempB )
var_ImgPerLine := var_TempC + var_TempB
; the whole thing can be shortened, but I left these
; calculations (and the whole template) this way for readability
; Add pictures to the Gui
Loop, %var_TotalGrid%
{
Gui, Add, Picture, % "w" var_CellSize " h" var_CellSize
;. " gLABEL_WHEN_IMG_IS_CLICKED" ; currently unused
. " x" var_CellSize*(var_TempMod:=Mod(A_Index-1,var_ImgPerLine))
. " y" ( var_TempMod ? "p" : var_CellSize*(var_Count++) ) , % var_Image%A_Index%
}
; Show Gui, wait a little bit and exit
Gui, Show, AutoSize
Sleep, 4000
ExitApp
#7
Posted 29 July 2012 - 01:18 AM




