Millisecond Forums

set position in pixels using expression

https://forums.millisecond.com/Topic26595.aspx

By thv - 3/25/2019

Hello,
I am trying to make 16 circles appear in an evenly spaced 4x4 grid in the center of the screen, and I need to make this appear similarly on different screens (i.e. it can be larger or smaller, but should always show up as as circles in a square grid, not as ovals in a rectangle grid). 
I can accomplish this by setting the canvas aspect ratio to (1,1) but then the rest of my task looks weird.

Therefore I have set the aspect ratio to 4,3, and tried to do the following, which does not display anything. 
It looks like what is wrong is that I am trying to give my circles a value in pixels for position and thinks it is a percent (the default), but I could not make my expressions give me a value in pixels.
(e.g. as a test case, /circle_col1_pos = (300px) works, but when i try to include math and the 'px' text in my expression it doesn't work /circle_col1_pos = ((300+1)px)

Any help on how to get this to work would be appreciated.
Thanks! 
Thalia

<expressions>
/circle_size = display.canvasheight/30

/circle_row1_pos = ((display.canvasheight/2) + expressions.circle_size*1)
/circle_row2_pos =(display.canvasheight/2) + expressions.circle_size*1
/circle_row3_pos =(display.canvasheight/2) + expressions.circle_size*(-1)
/circle_row4_pos =(display.canvasheight/2) + expressions.circle_size*(-2)

/circle_col1_pos = ((display.canvasheight/2) + expressions.circle_size*2)
/circle_col2_pos =(display.canvasheight/2) + expressions.circle_size*1
/circle_col3_pos =(display.canvasheight/2) + expressions.circle_size*(-1)
/circle_col3_pos =(display.canvasheight/2) + expressions.circle_size*(-2)
</expressions>

<shape circle1>
/ shape = circle
/ size = (expressions.circle_size,expressions.circle_size)
/ position = (expressions.circle_row1_pos,expressions.circle_col1_pos)
/ color = blue
</shape>

(and so on to create circle2, etc)



By Dave - 3/25/2019

thv - Monday, March 25, 2019
Hello,
I am trying to make 16 circles appear in an evenly spaced 4x4 grid in the center of the screen, and I need to make this appear similarly on different screens (i.e. it can be larger or smaller, but should always show up as as circles in a square grid, not as ovals in a rectangle grid). 
I can accomplish this by setting the canvas aspect ratio to (1,1) but then the rest of my task looks weird.

Therefore I have set the aspect ratio to 4,3, and tried to do the following, which does not display anything. 
It looks like what is wrong is that I am trying to give my circles a value in pixels for position and thinks it is a percent (the default), but I could not make my expressions give me a value in pixels.
(e.g. as a test case, /circle_col1_pos = (300px) works, but when i try to include math and the 'px' text in my expression it doesn't work /circle_col1_pos = ((300+1)px)

Any help on how to get this to work would be appreciated.
Thanks! 
Thalia

<expressions>
/circle_size = display.canvasheight/30

/circle_row1_pos = ((display.canvasheight/2) + expressions.circle_size*1)
/circle_row2_pos =(display.canvasheight/2) + expressions.circle_size*1
/circle_row3_pos =(display.canvasheight/2) + expressions.circle_size*(-1)
/circle_row4_pos =(display.canvasheight/2) + expressions.circle_size*(-2)

/circle_col1_pos = ((display.canvasheight/2) + expressions.circle_size*2)
/circle_col2_pos =(display.canvasheight/2) + expressions.circle_size*1
/circle_col3_pos =(display.canvasheight/2) + expressions.circle_size*(-1)
/circle_col3_pos =(display.canvasheight/2) + expressions.circle_size*(-2)
</expressions>

<shape circle1>
/ shape = circle
/ size = (expressions.circle_size,expressions.circle_size)
/ position = (expressions.circle_row1_pos,expressions.circle_col1_pos)
/ color = blue
</shape>

(and so on to create circle2, etc)




The reason nothing is being displayed is that those expressions return a numerical value that has no unit (such as pixels, i.e. px), because the property involved has no unit. The way to go about this would be something like this:

<expressions>
/circle_size = 1px * (display.canvasheight/30)

/circle_row1_pos = 1px * ((display.canvasheight/2) + expressions.circle_size*1)
...
</expressions>

Basically, the first term in the respective expression determines the unit for the overall result.
By thv - 3/26/2019

Dave - Monday, March 25, 2019
thv - Monday, March 25, 2019
Hello,
I am trying to make 16 circles appear in an evenly spaced 4x4 grid in the center of the screen, and I need to make this appear similarly on different screens (i.e. it can be larger or smaller, but should always show up as as circles in a square grid, not as ovals in a rectangle grid). 
I can accomplish this by setting the canvas aspect ratio to (1,1) but then the rest of my task looks weird.

Therefore I have set the aspect ratio to 4,3, and tried to do the following, which does not display anything. 
It looks like what is wrong is that I am trying to give my circles a value in pixels for position and thinks it is a percent (the default), but I could not make my expressions give me a value in pixels.
(e.g. as a test case, /circle_col1_pos = (300px) works, but when i try to include math and the 'px' text in my expression it doesn't work /circle_col1_pos = ((300+1)px)

Any help on how to get this to work would be appreciated.
Thanks! 
Thalia

<expressions>
/circle_size = display.canvasheight/30

/circle_row1_pos = ((display.canvasheight/2) + expressions.circle_size*1)
/circle_row2_pos =(display.canvasheight/2) + expressions.circle_size*1
/circle_row3_pos =(display.canvasheight/2) + expressions.circle_size*(-1)
/circle_row4_pos =(display.canvasheight/2) + expressions.circle_size*(-2)

/circle_col1_pos = ((display.canvasheight/2) + expressions.circle_size*2)
/circle_col2_pos =(display.canvasheight/2) + expressions.circle_size*1
/circle_col3_pos =(display.canvasheight/2) + expressions.circle_size*(-1)
/circle_col3_pos =(display.canvasheight/2) + expressions.circle_size*(-2)
</expressions>

<shape circle1>
/ shape = circle
/ size = (expressions.circle_size,expressions.circle_size)
/ position = (expressions.circle_row1_pos,expressions.circle_col1_pos)
/ color = blue
</shape>

(and so on to create circle2, etc)




The reason nothing is being displayed is that those expressions return a numerical value that has no unit (such as pixels, i.e. px), because the property involved has no unit. The way to go about this would be something like this:

<expressions>
/circle_size = 1px * (display.canvasheight/30)

/circle_row1_pos = 1px * ((display.canvasheight/2) + expressions.circle_size*1)
...
</expressions>

Basically, the first term in the respective expression determines the unit for the overall result.

Perfect, thanks!!