Author Topic: Optimize me plz.  (Read 3862 times)

0 Members and 1 Guest are viewing this topic.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Optimize me plz.
« on: October 09, 2011, 04:55:47 pm »
Ok, so i have a rotation routine.

Code: [Select]
:For(X,0,95)
:For(Y,0,63)
:cos(A)->D
:sin(A)->E
:If pxl-Test(X,Y)^r
:Pxl-on((X*D-(Y*E)//128,Y8D+(X-16*E)//128)
:END:END:END

And i do that for every pixel on screen.
Anyone know of a fast way to do this?
« Last Edit: October 09, 2011, 05:09:59 pm by Qwerty.55 »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Optimize me plz.
« Reply #1 on: October 09, 2011, 05:14:30 pm »
Code: [Select]
:cos(A)->D
:sin(A)->E
:For(X,0,95)
:For(Y,0,63)
:If pxl-Test(X,Y)^r
:Pxl-on(X-Y*E//128,Y8D+(X-16*E)//128)
:END:END:END

That's a bit more optimized, although I'm sure Runer could improve upon it.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Optimize me plz.
« Reply #2 on: October 09, 2011, 05:20:47 pm »
lol.  I was looking more for an optimization in concept.

Like it would be better to only test pixels above (lesser y value) than vertical shift.
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Optimize me plz.
« Reply #3 on: October 09, 2011, 05:32:39 pm »
If you didn't mind a 90 degree rotation, then this might be more optimized:

Code: [Select]
:For(A,0,95
:A^12->X
:A/8->Y
:Pt-On(X,Y,RotC(Pt-get(X,Y)))
:END
« Last Edit: October 09, 2011, 05:33:03 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Optimize me plz.
« Reply #4 on: October 09, 2011, 05:42:09 pm »
that will only turn 90 degrees though, correct :(
« Last Edit: October 09, 2011, 05:45:08 pm by Happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Optimize me plz.
« Reply #5 on: October 09, 2011, 05:49:33 pm »
Yes.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Optimize me plz.
« Reply #6 on: October 09, 2011, 07:48:52 pm »
I am good now, thanks for trying to help.
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Optimize me plz.
« Reply #7 on: October 09, 2011, 08:45:52 pm »
Instead of scanning the pixels in the back buffer and projecting them to the front buffer, you will get better results if you scan the front buffer and inverse-project from the back buffer.  This assures that every pixel is accounted for which won't happen if you do it the other way.

But as far as speed I don't think you can optimize more than that.  As Qwerty said, definitely pre-compute the sine and cosine before your for loops.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Optimize me plz.
« Reply #8 on: October 09, 2011, 08:48:51 pm »
Ok thanks, but i don't exactly get what inverse-project means.

Didn't realize i put them inside the loop :/.  Thank you very much for that.  Guess i need sleep.
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Optimize me plz.
« Reply #9 on: October 09, 2011, 08:55:53 pm »
Actually, it's better if you get rid of all the multiplication :P

Something like this (untested):
Code: [Select]
cos(A)*2→D
sin(A)*2→E
.Upper left corner (scaled by 256) in B,C
0→B
0→C
For(Y,0,63)
B-E→B→I
C+D→C→J
For(X,0,95)
If pxl-Test(I+D→I/256,J+E→J/256)r
pxl-On(X,Y)
End
End
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman