Jump to content



Photo

Drag


  • Please log in to reply
10 replies to this topic

#1 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 13 October 2006 - 04:40 AM

try this code:
require "draw"

function drawlevel(h)
local p=pict.screen()
p=pict.part(p,1,0,159,100)
draw.clear()
draw.pict(0,0,p)
draw.line(159,0,159,h)
end

t=0
showgraph()

while not(getkey()) do
t=t+.1
drawlevel(10+10*math.sin(t))
end

nothing happen when you press a key (not EXE), but if you tap and then drag the stylus ...

because of draw.update() i think.

#2 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 13 October 2006 - 04:58 AM

If you use this code:
require "draw"
showgraph()

function iif(con,a,b)
if con then return a else return b end
end

function drawlevel(h)
local p=pict.screen()
p=pict.part(p,4,0,159,200)
draw.clear()
draw.pict(0,0,p)
draw.line(156,0,156,h,1,4)
draw.line(156,200,156,h+50,1,4)
end

t=0
k=94

while not(testkey(K_EXE)) do
for i=1,50000 do end
t=t+iif(t>k,-t,.2)
drawlevel(75+50*math.sin(t/10)+10*math.sin(t))
end

It doesnt happen.

#3 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 October 2006 - 10:58 AM

Sorry, but what is supposed to happen here? :blink:
I can't see anything strange when I try to run it :huh:

Btw, you should write
while getkey()==nil do
instead of
while not(getkey()) do
because getkey() returns nil (and not false) if no key is pressed.
not(testkey(K_EXE)) is ok however.

#4 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 13 October 2006 - 01:47 PM

Try the first code, you will see what happen: when you drag the stylus the update function not works, DRAG IT. The screen wont draw correctly!

#5 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 October 2006 - 02:54 PM

Everything runs fine on my ClassPad :huh:
Anyone else could try? :unsure:

But I still don't see why the stylus would cause a problem, and why you talk about draw.update(), which is not used here...

#6 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 13 October 2006 - 03:19 PM

Sorry, the first code must be:
require "draw"
draw.onbuffer()

function drawlevel(h)
local p=pict.screen()
p=pict.part(p,1,0,159,100)
draw.clear()
draw.pict(0,0,p)
draw.line(159,0,159,h)
draw.update()
end

t=0
showgraph()

while not(getkey()) do
t=t+.1
drawlevel(10+10*math.sin(t))
end


#7 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 October 2006 - 04:25 PM

Now I see what you mean... And indeed there is a problem :blink:
Thanks, I'll investigate ;)

#8 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 14 October 2006 - 12:21 AM

The next ver should add a function iif.

#9 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 14 October 2006 - 08:42 AM

Using iif() is a good idea, however it would not be a good idea to create a C++ function for it, because calling this function would be slower than executing it :rolleyes:
I think it's not a big deal to write it again in your programs ;)

#10 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 14 October 2006 - 12:50 PM

Slow! Really! Maybe because that function must calc all a and b, but how about check con before parse a or b.

#11 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 14 October 2006 - 05:16 PM

No, it would be slow because of the operations needed to call a C++ function, which are heavier than a call to a simple Lua function ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users