Global stroke width change?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Global stroke width change?

Post by heyvern »

I have all the info... I just don't have the skills.

This is the code for a shape named "1" on a 4 point box with a stroke width of "5". The highlighted line is the stroke width in the file format.

The document height is 540px. That highlighted number times... approximately 540 equals practically... uh... 5. This is consistent with stroke widths and pixel heights of projects.

Neither number (the stroke or the pixel height) is the "exact" number... but is so close as to not make a spit of difference... but could be a problem trying to... change this by typing in a number or changing all the "5" widths to "7" or something like that. It is always... like... instead of 5... 4.99986...
Instead of "540" it would be something like... 539.99808001536.

Code: Select all

		shapes 1
			"1" false true true true
				4
					0 0
					0 1
					0 2
					0 3
				""
					false
					[
						keys 1
							0 0 0.1 0.5 1 1 1 1
					]

Code: Select all

					false 0.009259

Code: Select all

					false
					[
						keys 1
							0 0 0.1 0.5 1 0.129412 0.129412 1
					]
					""
					false
					6.283185
					0.25
					true
					-1
					-1
					-1
				""
				""
-vern
myles
Posts: 821
Joined: Sat Aug 21, 2004 3:32 am
Location: Australia, Victoria, Morwell
Contact:

Post by myles »

Hello Vern,

ahh, the wonders of floating point inaccuracy.

Partly because infinite or even long decimal fractions cannot be represented in the very finite storage allocated to each floating point number on the computer, partly because humans work in base 10 and computers work in base 2 - for example, I believe it is impossible to exactly represent 0.1 in binary, just as it is impossible to accurately represent 1/3 in decimal format (0.33333333333333333333333333333333333333...etc).

You could use a look-up table tailored to your document height, but that seems rather clunky.

How about something like this (taken from the Lua users wiki):

Code: Select all

Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> decimal_points = 6
> line_width = 5
> project_height = 240
> somenumber=tonumber(string.format("%."..decimal_points.."f", line_width/project_height))
>
> =somenumber
0.020833
>


> project_height = 540
> somenumber=tonumber(string.format("%."..decimal_points.."f", line_width/projec
t_height))
>
> =somenumber
0.009259

Regards, Myles.
"Quote me as saying I was mis-quoted."
-- Groucho Marx
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

Sometimes I feel Moho's internal floating point is float (4 bytes long) and not double (8 bytes). That's why it is not so accurate. I am talking about the internal values (ie. the values of the keys in the animated channels) but Lua using double for the numbers.
- - - Fazek
Post Reply