π
<-
Chat plein-écran
[^]

LUA Progress bar

Pour TI-Nspire OS 3.0 ou ultérieur.

LUA Progress bar

Message non lude FrederikTheisen » 30 Oct 2014, 11:14

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.

Here is the code for the loading:
Code: Tout sélectionner
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
   end
end


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
Avatar de l’utilisateur
FrederikTheisen
Niveau 2: MI2 (Membre Initié)
Niveau 2: MI2 (Membre Initié)
Prochain niv.: 13.3%
 
Messages: 4
Inscription: 30 Oct 2014, 02:01
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: LUA Progress bar

Message non lude Ti64CLi++ » 30 Oct 2014, 11:26

I don't know.
Why will you do a progress bar?
Image
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: LUA Progress bar

Message non lude Bisam » 30 Oct 2014, 11:32

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...
Avatar de l’utilisateur
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Prochain niv.: 69.6%
 
Messages: 5665
Inscription: 11 Mar 2008, 00:00
Localisation: Lyon
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: LUA Progress bar

Message non lude Ti64CLi++ » 30 Oct 2014, 11:50

Salut Bisam
pourquoi parle-tu en français alors qu'il ne comprends peut-être pas le français.
Image
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: LUA Progress bar

Message non lude Bisam » 30 Oct 2014, 11:52

J'ai répondu en français ET en anglais...
Avatar de l’utilisateur
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Prochain niv.: 69.6%
 
Messages: 5665
Inscription: 11 Mar 2008, 00:00
Localisation: Lyon
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: LUA Progress bar

Message non lude Ti64CLi++ » 30 Oct 2014, 11:55

Je ne vois pas d'anglais pourtant.
Image
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: LUA Progress bar

Message non lude Bisam » 30 Oct 2014, 11:56

Regarde mieux !
Avatar de l’utilisateur
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Prochain niv.: 69.6%
 
Messages: 5665
Inscription: 11 Mar 2008, 00:00
Localisation: Lyon
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: LUA Progress bar

Message non lude Ti64CLi++ » 30 Oct 2014, 14:11

a oui mais mon ordinateur bug et donc des fois il cache les liens.
Image
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: LUA Progress bar

Message non lude Jens_K » 30 Oct 2014, 14:35

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: Tout sélectionner
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))
   end
end

CRgetMaxDist=coroutine.create(getMaxDist)
local progress=0
local finished=false

timer.start(0.01)
function on.timer()
    platform.window:invalidate()
    _, progress = coroutine.resume(CRgetMaxDist)
    if progress==1 then
        timer.stop()
        finished=true
    end
end

function on.paint(gc)
    if finished then
        gc:drawString("finished",50,50)
    else
        gc:fillRect(0,100,318*progress,10)
    end
end


Edit: It's now optimized, so that it measures the distanced between the same 2 points only once ;)
Dernière édition par Jens_K le 30 Oct 2014, 20:43, édité 1 fois.
Avatar de l’utilisateur
Jens_K
Niveau 0: MI (Membre Inactif)
Niveau 0: MI (Membre Inactif)
Prochain niv.: 0%
 
Messages: 7
Inscription: 16 Oct 2014, 11:07
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: LUA Progress bar

Message non lude FrederikTheisen » 30 Oct 2014, 17:12

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.
Avatar de l’utilisateur
FrederikTheisen
Niveau 2: MI2 (Membre Initié)
Niveau 2: MI2 (Membre Initié)
Prochain niv.: 13.3%
 
Messages: 4
Inscription: 30 Oct 2014, 02:01
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Suivante

Retourner vers Nspire-Lua

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 15 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1372 utilisateurs:
>1341 invités
>26 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)