π
<-

Problème programme en Lua (Harlem Shake)

Pour TI-Nspire OS 3.0 ou ultérieur.

Problème programme en Lua (Harlem Shake)

Unread postby davidElmaleh » 06 Oct 2013, 21:09

Code: Select all
w=platform.window:width()
h=platform.window:height()
local s
function on.paint(gc)
    gc:fillRect(0,0,w,h)
    gc:setColorRGB(255,255,255)
    gc:drawLine(0,25,w,25)
    for i=0,25,0.1 do gc:setColorRGB(3*i,3*i,3*i) gc:drawLine(0,i,w,i) end
    s = scratchpad(gc)
    s:paint(gc)
end
function on.enterKey() timer.start(1) end
-------------------------------------------------------Scratchpad
scratchpad = class()
function scratchpad:init(gc)
    wscratchpad=gc:getStringWidth("Scratchpad")
    hscratchpad=gc:getStringHeight("Scratchpad")
    self.xpos = w/4 - wscratchpad/2
    self.ypos = 25 + hscratchpad
end
function scratchpad:paint(gc)
    self.taille=11
    gc:setFont("sansserif","b",self.taille)
    gc:setColorRGB(80,80,255)
    gc:drawString("Scratchpad",self.xpos,self.ypos)
end
function scratchpad:doTheHarlemShake()
    if self.taille~=3 then self.taille = self.taille-0.5 else self.taille=self.taille+5 end
    if self.xpos~=w/4 - wscratchpad/2-40 then self.xpos = self.xpos - 2 end
    if self.ypos~=25 + hscratchpad+40 then self.ypos = self.ypos + 2 end
    platform.window:invalidate()
end
function on.timer()
    s:doTheHarlemShake()
    platform.window:invalidate()
end


Voici un code en lua
problème, quand j'appuye sur entrée, rien ne se passe pk?
Image
User avatar
davidElmalehProgrammeur
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 19.6%
 
Posts: 409
Images: 9
Joined: 14 Oct 2012, 23:30
Location: Paris 19
Gender: Male
Calculator(s):
MyCalcs profile
Class: PSI*

Re: Problème programme en Lua (Harlem Shake)

Unread postby Adriweb » 06 Oct 2013, 21:30

- L'objet window n'est pas encore initiliasé quand tu l'appelle
- utilise on.resize
- tu te rends compte que tu appelle le constructeur de la classe scratchpad à chaque paint ... ?
- pour setFont : value must be 6 to 255
- faire une init de classe ayant besoin d'un gc ... c'est pas bien :P Mais bon, au pire tu peux utiliser platform.withGC() si tu veux faire tourner ca en 3.2+, sinon, platform.gc() avec ce qu'il faut derriere.

Bref (pas testé, mais bon, si ya une erreur ca doit pas etre bien compliqué :P) :

Code: Select all
function on.resize(ww,hh)
    w,h = ww,hh
end

function on.paint(gc)
    gc:fillRect(0,0,w,h)
    gc:setColorRGB(255,255,255)
    gc:drawLine(0,25,w,25)
    for i=0,25,0.1 do gc:setColorRGB(3*i,3*i,3*i) gc:drawLine(0,i,w,i) end
    s:paint(gc)
end

function on.enterKey()
    timer.stop()
    timer.start(0.05)
end

function on.timer()
    s:doTheHarlemShake()
    platform.window:invalidate()
end

-------------------------------------------------------Scratchpad
Scratchpad = class()

function Scratchpad:init()
    self.taille = 11
end

function Scratchpad:paint(gc)
    gc:setFont("sansserif","b",self.taille)
    local str = "Scratchpad"
    wscratchpad, hscratchpad = gc:getStringWidth(str), gc:getStringHeight(str)
    self.xpos, self.ypos = w/4 - wscratchpad/2, 25 + hscratchpad
    gc:setColorRGB(80,80,255)
    gc:drawString(str,self.xpos,self.ypos)
end

function Scratchpad:doTheHarlemShake()
    if self.taille~=6 then self.taille = self.taille-0.5 else self.taille=self.taille+5 end
    if self.xpos~=w/4 - wscratchpad/2-40 then self.xpos = self.xpos - 2 end
    if self.ypos~=25 + hscratchpad+40 then self.ypos = self.ypos + 2 end
    platform.window:invalidate()
end

s = Scratchpad()


MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14837
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: Problème programme en Lua (Harlem Shake)

Unread postby AnToX98 » 07 Oct 2013, 11:16

C'est quoi que tu veux faire exactement :p
Faire un harlem shake du scratchpad ?
User avatar
AnToX98Premium
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 75.5%
 
Posts: 1022
Images: 15
Joined: 19 May 2013, 16:54
Location: Paris, France
Gender: Male
Calculator(s):
MyCalcs profile
Class: 1ere S

Re: Problème programme en Lua (Harlem Shake)

Unread postby davidElmaleh » 07 Oct 2013, 21:47

Oui, c'est exactement ca. Mais pas seulement du scratchpad :p
Image
User avatar
davidElmalehProgrammeur
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 19.6%
 
Posts: 409
Images: 9
Joined: 14 Oct 2012, 23:30
Location: Paris 19
Gender: Male
Calculator(s):
MyCalcs profile
Class: PSI*

Re: Problème programme en Lua (Harlem Shake)

Unread postby davidElmaleh » 07 Oct 2013, 21:48

J'ai un problème avec un autre code. Le voici :
Code: Select all
w=platform.window:width()
h=platform.window:height()

--------------------------------------------------------Scratchpad
scratchpad = class()

function scratchpad:init()
    self.pic=image.new("blabla...")
    self.width=image.width(self.pic)
    self.height=image.height(self.pic)
    self.xpos=w/4-self.width/2
    self.ypos=25+self.height/2
end

function scratchpad:paint(gc)
    gc:drawImage(self.pic,self.xpos,self.ypos)
end

function scratchpad:doTheHarlemShake()
    if angle_s<=45 then image.rotate(self.pic,angle_s) end
    platform.window:invalidate()
end
--------------------------------------------------------

s=scratchpad()
angle_s=0

function on.paint(gc)
    gc:fillRect(0,0,w,h)
    gc:setColorRGB(255,255,255)
    gc:drawLine(0,25,w,25)
    for i=0,25,0.1 do gc:setColorRGB(3*i,3*i,3*i) gc:drawLine(0,i,w,i) end
    s:paint(gc)
end

function on.enterKey()
    timer.stop()
    timer.start(0.1)
end

function on.timer()
    angle_s=angle_s+1
    s:doTheHarlemShake()
    platform.window:invalidate()
end
Image
User avatar
davidElmalehProgrammeur
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 19.6%
 
Posts: 409
Images: 9
Joined: 14 Oct 2012, 23:30
Location: Paris 19
Gender: Male
Calculator(s):
MyCalcs profile
Class: PSI*

Re: Problème programme en Lua (Harlem Shake)

Unread postby Adriweb » 07 Oct 2013, 22:57

Hum... tu as vu mon code .... ?
TU refais certaines memes erreurs que j'ai corrigé.

(window non initialisé)

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14837
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: Problème programme en Lua (Harlem Shake)

Unread postby davidElmaleh » 07 Oct 2013, 23:00

Non, finalement j'ai trouvé le problème:
au lieu d'écrire self.pic = image.rotate(self.pic,angle_s)
je n'écrivais seulement image.rotate(self.pic,angle_s)
Image
User avatar
davidElmalehProgrammeur
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 19.6%
 
Posts: 409
Images: 9
Joined: 14 Oct 2012, 23:30
Location: Paris 19
Gender: Male
Calculator(s):
MyCalcs profile
Class: PSI*


Return to Nspire-Lua

Who is online

Users browsing this forum: ClaudeBot [spider] and 3 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
2398 utilisateurs:
>2344 invités
>46 membres
>8 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)