Author Topic: Optimized Routine: Set Up Friendly Graph Window  (Read 9068 times)

0 Members and 1 Guest are viewing this topic.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Optimized Routine: Set Up Friendly Graph Window
« on: May 30, 2010, 03:37:58 pm »
I did a long time ago. I experimented a lot to get this optimized routine. I added this to TI|BD some time after discover...
And because I see unoptimized versions of this in lots of programs, I decided to share on the forums.
I still need to spread this optimized version through other entries of the wiki.

Here's the code:
Code: [Select]
//// Prepare graph screen to be used in TI-BASIC
StoreGDB 0 // save the current graph screen, user friendly
FnOff         // we don't want functions to bloat
PlotsOff      // plots too
GridOff        // rare but just in case
AxesOff      // no axes please :)
// miss here the coordinates setup...

///main code

RecallGDB 0 // restore the graph screen, user friendly
DelVar GDB0 // clean up

//The following code sets up an integer square window with (0,0) in the center:
:ZStandard
:ZInteger

//An integer window with (0,0) in the bottom left corner
:ZStandard
:84→Xmin
:72→Ymax
:ZInteger

//An integer window with (0,0) in the top left corner
:ZStandard
:84→Xmin
:-72→Ymax
:ZInteger

And a alternate version of preserving user setting with a few drawbacks:
Code: [Select]
ZoomSto // store the zoom
FnOff         // we don't want functions to bloat
PlotsOff      // plots too
GridOff        // rare but just in case
AxesOff      // no axes please :)
// miss here the coordinates setup...

///main code

// restore
ZoomRcl  // restore the zoom
AxesOn  

Maybe ZPrevious could be used for further optimization. I need to test. Tested. It is not great use for restoring graphics setting after more than 1 command that changes the graph settings.


For curiosity here's the good old straightforward but larger code:
Code: [Select]
:0→Xmin:94→Xmax
:0→Ymin:62→Ymax
can be
:0→Xmin:1→ΔX
:0→Ymin:1→ΔY

Good use!
« Last Edit: June 09, 2010, 10:14:00 am by Galandros »
Hobbing in calculator projects.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #1 on: May 30, 2010, 11:39:38 pm »
I still remember seeing this before. That was interesting. Did it work on every calc OSes, though? I think I recall this failed before when I tried the :0→Xmin:1→ΔX stuff

That said, for the Y part, I don't really like this much, though, because generally people will want Y coordinates to look similar to if they used Pxl-On or Text(). I prefer having -62->Ymin:0->Ymax instead of 0->Ymin:-62->Ymax. I think it might cause programs to grow in file size, though, so if you really want to optimize your programs, you might have to adapt to the inverted coordinates instead
« Last Edit: May 30, 2010, 11:42:45 pm by DJ Omnimaga »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #2 on: May 31, 2010, 12:07:45 am »
-62->Ymin:0->Ymax

Thats the window setting i use as well ^^ I find its most useful when mixing window based drawing and screen based drawing.  haha i remember when i used to use the Integer window setting, and i had to do math in order to draw accurately ;D

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #3 on: May 31, 2010, 12:51:12 am »
I usually use 0->Ymin:62->Ymax... Nowadays, some of the inverted coordinates comes natural and the harder ones I just need to subtract the number from 62...  I don't like working with negatives too much :P
« Last Edit: May 31, 2010, 12:51:40 am by jsj795 »


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #4 on: May 31, 2010, 03:27:28 am »
I use the 2 setups you are discussing. It just depends on the program I use. The conversion on Y for the -62->Ymin:0->Ymax  is just -Y.
For the other you do something like 62-Y.

And in movement/physics things you have the change the code accordingly to the setup.
Hobbing in calculator projects.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #5 on: May 31, 2010, 11:51:31 am »
Code: [Select]
:ZStandard
:84→Xmin
:-72→Ymax
:ZInteger

Wow, that is optimized. Thanks.

Thats the window setting i use as well ^^ I find its most useful when mixing window based drawing and screen based drawing.  haha i remember when i used to use the Integer window setting, and i had to do math in order to draw accurately ;D

Me too. And before that, I just left the window in ZStandard and tried to work with the decimals. It was horrible.

EDIT: Especially for a game like checkers.
« Last Edit: May 31, 2010, 12:36:00 pm by Deep Thought »




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #6 on: May 31, 2010, 12:29:33 pm »
Indeed. Some of my old games use Zstandard but only because everything involving drawing doesn't need much pixel precision. Still hectic at times, though.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #7 on: June 01, 2010, 05:36:38 pm »
What's worse and what I did until I figured out how to use GDB's is to use the window as is. That code got messy quickly.
A pixel Y,X (such as used with Pxl-On) becomes Xmin+^X*X,Ymax-^Y*Y (yes I'm using carets for deltas) and conversion back is even uglier, with rounding involved. *shudder*
But then I learned about GDB's, and I became happier. :)
Also, nice code, Galandros
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #8 on: June 01, 2010, 05:48:05 pm »
I assume GDBs stored all graph equations and window settings, right?

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #9 on: June 01, 2010, 06:14:01 pm »
Yeah, they do, which can be useful if you need to draw an equation for some reason...
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #10 on: June 01, 2010, 07:58:43 pm »
cool, thanks for the info. Are they generally smaller too?

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #11 on: June 01, 2010, 08:05:12 pm »
cool, thanks for the info. Are they generally smaller too?
They can be, just remember it's one more thing (like a pic) that must be included with your program. =/

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #12 on: June 01, 2010, 09:03:15 pm »
Yeah true :S

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #13 on: June 02, 2010, 01:57:02 pm »
Indeed. Some of my old games use Zstandard but only because everything involving drawing doesn't need much pixel precision. Still hectic at times, though.
A pixel Y,X (such as used with Pxl-On) becomes Xmin+^X*X,Ymax-^Y*Y (yes I'm using carets for deltas) and conversion back is even uglier, with rounding involved. *shudder*
In my early TI-BASIC coding I tried to code a program to convert any graphs setting to another. I will give it a try again but I believe there is rounding issues that throw away the use. The idea is to ease convert old code to the code in Friendly Graphics Settings.

I shared exactly to make everyone save a few bytes (not that important but in TI-BASIC we turn many times in optimization freaks) and also for the curiosity of existing a even smaller alternative. ^^ I also like the alternative movement code seen in TI|BD.
Hobbing in calculator projects.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Optimized Routine: Set Up Friendly Graph Window
« Reply #14 on: June 09, 2010, 10:15:11 am »
Maybe ZPrevious could be used for further optimization.
Checked. It is not great use for restoring graphics setting after more than 1 command that changes the graph settings.

It can be used during your mathematical equations view, though.
« Last Edit: June 09, 2010, 10:15:28 am by Galandros »
Hobbing in calculator projects.