π
<-

## LUA Progress bar

Pour TI-Nspire OS 3.0 ou ultérieur.

### LUA Progress bar

Hi there

I'm working on a project where I need to find the distance between up to 2000 points in 3D space.
It takes a lot of time on the nSpire CX calculator, so I wanted to make a progress bar, showing how far it was in the process.

Code: Select all
function getMaxDist()   maxDist = 0   for i = 1,molTable["nAtoms"] do      for j = 1,molTable["nAtoms"] do         local dist = math.sqrt((molTable[i]["x"] - molTable[j]["x"])^2  +  (molTable[i]["y"] - molTable[j]["y"])^2  +  (molTable[i]["z"] - molTable[j]["z"])^2)         if dist > maxDist then            maxDist = dist         end      end   endend

It's not finished, but you get the idea.

But I'm not able to update the screen while I'm inside the loop.
It only updates once it has finished.

Is there any possible way to make a loading bar in LUA on the nSpire CX?

regards
Frederik

FrederikTheisen

Niveau 2: MI2 (Membre Initié)
Level up: 13.3%

Posts: 4
Joined: 30 Oct 2014, 02:01
Gender:
Calculator(s):

### Re: LUA Progress bar

I don't know.
Why will you do a progress bar?

Ti64CLi++Modo

Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 4%

Posts: 3353
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender:
Calculator(s):
Class: MP
GitHub: Ti64CLi

### Re: LUA Progress bar

1) Ton algorithme de recherche est inefficace : tu fais 2 fois plus de boulot que nécessaire. Tu peux t'arrêter à j = i-1 dans ta 2ème boucle puisque la distance de i à j est la même que celle de j à i.
2) Tu devrais localiser les fonctions que tu utilises souvent, comme la fonction "math.sqrt".
3) Encore mieux, tu devrais créer une fonction qui renvoie la distance entre 2 atomes, directement...

1) Your search algorithm is inefficient : you work twice as needed. You can stop your second loop at j=i-1 as the distance between i and j is the same as the distance between j and i.
2) You should localize the functions used very often, as for "math.sqrt".
3) Even better, you should create a function returning the distance between 2 atoms, directly...

Niveau 15: CC (Chevalier des Calculatrices)
Level up: 49.6%

Posts: 5501
Joined: 11 Mar 2008, 00:00
Location: Lyon
Gender:
Calculator(s):

### Re: LUA Progress bar

Salut Bisam
pourquoi parle-tu en français alors qu'il ne comprends peut-être pas le français.

Ti64CLi++Modo

Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 4%

Posts: 3353
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender:
Calculator(s):
Class: MP
GitHub: Ti64CLi

### Re: LUA Progress bar

J'ai répondu en français ET en anglais...

Niveau 15: CC (Chevalier des Calculatrices)
Level up: 49.6%

Posts: 5501
Joined: 11 Mar 2008, 00:00
Location: Lyon
Gender:
Calculator(s):

### Re: LUA Progress bar

Je ne vois pas d'anglais pourtant.

Ti64CLi++Modo

Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 4%

Posts: 3353
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender:
Calculator(s):
Class: MP
GitHub: Ti64CLi

### Re: LUA Progress bar

Regarde mieux !

Niveau 15: CC (Chevalier des Calculatrices)
Level up: 49.6%

Posts: 5501
Joined: 11 Mar 2008, 00:00
Location: Lyon
Gender:
Calculator(s):

### Re: LUA Progress bar

a oui mais mon ordinateur bug et donc des fois il cache les liens.

Ti64CLi++Modo

Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 4%

Posts: 3353
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender:
Calculator(s):
Class: MP
GitHub: Ti64CLi

### Re: LUA Progress bar

Hi, I once messed around with progressbars using coroutines. I tried to use that principle with your algorithm (and I optimized it a bit ) and it seems to work:
Code: Select all
function getMaxDist()   local sqrt = math.sqrt   local maxDist = 0   local dist   local nAtoms = molTable["nAtoms"]   for i = 1,nAtoms-1 do      for j = i+1,nAtoms do         dist = sqrt((molTable[i]["x"] - molTable[j]["x"])^2  +  (molTable[i]["y"] - molTable[j]["y"])^2  +  (molTable[i]["z"] - molTable[j]["z"])^2)         if dist > maxDist then            maxDist = dist         end      end      coroutine.yield(i/(nAtoms-1))   endendCRgetMaxDist=coroutine.create(getMaxDist)local progress=0local finished=falsetimer.start(0.01)function on.timer()    platform.window:invalidate()    _, progress = coroutine.resume(CRgetMaxDist)    if progress==1 then        timer.stop()        finished=true    endendfunction on.paint(gc)    if finished then        gc:drawString("finished",50,50)    else        gc:fillRect(0,100,318*progress,10)    endend

Edit: It's now optimized, so that it measures the distanced between the same 2 points only once
Last edited by Jens_K on 30 Oct 2014, 20:43, edited 1 time in total.

Jens_K

Niveau 0: MI (Membre Inactif)
Level up: 0%

Posts: 7
Joined: 16 Oct 2014, 11:07
Gender:
Calculator(s):

### Re: LUA Progress bar

Wow, thanks a bunch!
I'm going to work on this once I get home.

I know that the code is not optimized (not checking double will be a nice fix for sure).
Though many o the constants are declared (as local) outside the code snippet i shared (program is currently 700 lines + 8000 lines database)

I'm not familiar with the coroutine 'function', but I hope that it will address the problem.

FrederikTheisen

Niveau 2: MI2 (Membre Initié)
Level up: 13.3%

Posts: 4
Joined: 30 Oct 2014, 02:01
Gender:
Calculator(s):

Next

### Who is online

Users browsing this forum: No registered users and 3 guests

-
Search
-
Featured topics
1234
-
For more contests, prizes, reviews, helping us pay the server and domains...

Discover the the advantages of a donor account !

-
Stats.
505 utilisateurs:
>490 invités
>9 membres
>6 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)

-
Other interesting websites
Texas Instruments Education
Global | France
(English / Français)
Banque de programmes TI
ticalc.org
(English)
La communauté TI-82
tout82.free.fr
(Français)