# Maths again!

I did this to go in part of a photoshop script is this the proper way to go about this or is there a better method to do this math. Its not too important as this only happens the once in my script I just like to learn the proper way where possible. x is to be determined by the script.

``````set x to 8
set theLevels to {0} -- I need the leading zero too!
--
set thesplit to 255 / (x - 1)
repeat with f from 1 to (x - 1)
set ThisLevel to round (thesplit * f) rounding down
copy ThisLevel to end of theLevels
end repeat

-- {0, 36, 72, 109, 145, 182, 218, 255}
``````

I have no idea what you’re trying to accomplish, but this is a faster and more efficient way to do what you do have:
(I assume you want to divide 255 into 8 equal pieces to the nearest integer value)

``````set x to 8
set theLevels to {0} -- I need the leading zero too!
--
set thesplit to 255 / (x - 1)
repeat with f from 1 to (x - 1)
set the end of theLevels to (thesplit * f) div 1
end repeat

-- {0, 36, 72, 109, 145, 182, 218, 255}

``````

To have the first of these be “00”, they will all have to be text.

``````set x to 8
set theLevels to {"00"} -- I need the leading zero too!
--
set thesplit to 255 / (x - 1)
repeat with f from 1 to (x - 1)
set the end of theLevels to ((thesplit * f) div 1) as text
end repeat
``````

Adam, I am playing with a script that will take “x” the count of symbols in an illustrator file pass this to photoshop to posterize an image then photoshop reads the pixel vaules back to illustrator to create patterns based on the image if you know what i mean. The project is just for the learning process plenty of loops n stuff. 256 is the levels of the histogram. The script is working but very slow I was just looking at trimming down some of the proceesses to make it as efficient as possible. From what I can make out posterizing an image retains level 0 then splits the remaining image info across the other 255 levels. Your first option looks exactly what I wanted.