coordinates texture

About advanced scenes, and the Thyme scripting language used in Algodoo.

coordinates texture

Postby MyMan » Mon Sep 16, 2013 7:11 pm

Hi,
I want the x and y coordinates of a box to be shown on the box like a text.

It would be great if you could decrease the number so that there are only two numbers after the comma (for example 3,44 or -5,12) ;)
But that's not important.

I hope some of you can help me. :D
MyMan
 
Posts: 4
Joined: Mon Sep 16, 2013 6:59 pm

Re: coordinates texture

Postby electronicboy » Tue Sep 17, 2013 12:12 am

Easiest way to put text onto a object is to concatenate stings and variables.
This is done in the script menu, as so:

Code: Select all
{"x:" + pos(0) + "\ny:" + pos(1)}


\n is the newline character.

As for rounding, I think your best waiting for somebody else to come along, as I can't use the search feature as it pulls up a lot of rubbish which I'm clearing out (unapproved posts), but I'm sorta tethering a mobile connection, so it's not the best...
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: coordinates texture

Postby MyMan » Wed Sep 18, 2013 11:56 am

thank you very much!!!!!!!!!!!!!!!!!! :clap:
it's perfect :thumbup:
MyMan
 
Posts: 4
Joined: Mon Sep 16, 2013 6:59 pm

Re: coordinates texture

Postby Xray » Sat Sep 21, 2013 6:06 pm

When digital readouts are difficult to read because of jitter and too many decimal places, use this code to reduce the precision and smooth the jitter (the constant 10000 can be changed to change the digits of precision. The number of zeros == the number of decimal places)....

math.tofloat(math.toint((variable or equation) *10000)) / 10000

Examples:

1.
text = {"B: " + math.tofloat(math.toint((Scene.my.x2 - Scene.my.x1) *10000)) / 10000}

2.
_Force = math.tofloat(math.toint(((pos(0) - 1.5) * 40)*1000))/1000
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: coordinates texture

Postby Ivan » Sat Sep 21, 2013 10:02 pm

I would suggest to insert + 0.5 into the parameter for math.toint for better rounding because math.toint rounds to the first smaller integer. To make it shorter, math.tofloat can be replaced by a comma in the last number in the formula which will make it recognised as float.

math.toint((variable or equation) * 100 + 0.5) / 100.0
User avatar
Ivan
 
Posts: 203
Joined: Tue Oct 06, 2009 2:01 pm
Location: Croatia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests