Jump to content

Math Help


.:HyPeX:.

Recommended Posts

Hello, i've got a question, how can i invert my text size?

To clarify these are my maths:

  
local text = "~HyPeX~ASdasdasd" 
local size = dxGetTextWidth(text,1,"default") 
local max = 100 
local size = size/max 
local tsize = size * -4+4 
outputConsole(tsize) 
  

So far, it works kinda good, but the sizes vary too much. I.e: big texts are excesively small and small texts are excesively big..

Link to comment
What exactly are you trying to do?

Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big.

I'm not sure how the math wouldbe, but you could use a while loop, something like this:

  
    local text = "~HyPeX~ASdasdasd" 
    local size = dxGetTextWidth(text,1,"default") 
    local tSize = 1; 
     
    if ( size < 100 ) then 
        while ( size < 100 ) do  
            tSize = tSize + 0.5; 
            size = dxGetTextWidth(text,tSize,"default") 
        end 
    elseif ( size > 100 ) then  
        while ( size > 100 ) then  
            tSize = tSize - 0.5; 
            size = dxGetTextWidth(text,tSize,"default") 
        end 
    end 
     
    outputConsole ( tSize ); 
  
  

Link to comment
What exactly are you trying to do?

Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big.

I'm not sure how the math wouldbe, but you could use a while loop, something like this:

  
    local text = "~HyPeX~ASdasdasd" 
    local size = dxGetTextWidth(text,1,"default") 
    local tSize = 1; 
     
    if ( size < 100 ) then 
        while ( size < 100 ) do  
            tSize = tSize + 0.5; 
            size = dxGetTextWidth(text,tSize,"default") 
        end 
    elseif ( size > 100 ) then  
        while ( size > 100 ) then  
            tSize = tSize - 0.5; 
            size = dxGetTextWidth(text,tSize,"default") 
        end 
    end 
     
    outputConsole ( tSize ); 
  
  

Would that work in a clientRender loop, or is it adviced to do it before?

Link to comment
If you don't use onClientRender, whenever the text changes the size won't be updated.

What i was asking was if it was ideal in performance terms, i could add a check to see if the text changes and then do the size update, my question was if it was worth the work.

(But i guess not so much since its client side stuff)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...