Author Topic: Fastest way to render random points and lines?  (Read 4157 times)

0 Members and 1 Guest are viewing this topic.

Offline CalcMax

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +0/-0
  • TI-84+SE for play, NSpire CX CAS for hard work
    • View Profile
Fastest way to render random points and lines?
« on: January 15, 2017, 07:38:13 am »
Could someone tell me what the best way to randomly generate lines,points,pixels,etc... on a TI-84+ in TI-BASIC? I have gone through many different attempts and it usually involved taking and modding a portion of Hex2Sprite and then adding quite a bit of my own code to randomize coordinates (randInt operations) and draw what I need (I think my code is the slow part, but the programs are too long to post here.). Is there an alternative method to mine or is this the fastest I can get without attempting to OC my calc to 25-30MHz?
Feel free to download any of my programs:
http://www.ticalc.org/archives/files/authors/115/11518.html

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Fastest way to render random points and lines?
« Reply #1 on: January 15, 2017, 09:27:27 am »
Of course assembly would be way faster, but have you tried the standard built in Pxl-On(, Pxl-Off(, Pxl-Change(, Pt-On(, Pt-Off(, Pt-Change(, Line(, and Circle( commands? Also, if you include an extra argument for Circle( of {i it will perform faster (i being the imaginary i).

If you haven't tried Axe yet, I urge you to try that if you want much faster graphics. Just be warned that Axe works a lot closer to assembly, so you can't just press [ON] to break out of infinite loops. For example, if you do While 1:End, you will need to pull a battery and get a RAM clear.

Edit: Also, if you want a pixel based circle (instead of TIs point-based), I think KermM wrote an entirely TI-BASIC routine that performs faster than TIs.

Offline CalcMax

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +0/-0
  • TI-84+SE for play, NSpire CX CAS for hard work
    • View Profile
Re: Fastest way to render random points and lines?
« Reply #2 on: January 15, 2017, 10:18:33 am »
Well,here is the code of a program that should appear in soon on ticalc.org along with another one (all in one package):
Code: [Select]
NAME:CALCIMG

AxesOff
ClrDraw
ClrHome
Goto 1
Lbl 1
ClrHome
ClrDraw
"0"->Str4
I+28->C:J->U
length(Str4
Ans/(3+2(Ans>29)+4(Ans>29->Z
If min(Ans!={8,16,32
Then
ClrHome
"ACBCEFEFBCBCCECBCACACACACACCACA989898964317979BCCECECECECECECCACACACACACCECACEC9797979797979779797979797979797979779797979797979797979797979797CCACAFFFDFCACCDCCACACCBCBCCBCBFECBCBCCBCECBCCBCBCBCBFFEFBCECBCBC97797977979797979797964646799497676313461616161616464997989898989898989898897997646466464631331313131313466466464979977979979797979797979CBCEFBCCECCCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBC9797ABDEACDCCACACACBCCBC56565656565565656565"->Str4
ClrHome
32->Z
End
For(B,1,length(Str4
inString("123456789ABCDEF",sub(Str4,B,1
If 4<Ans
Pt-On(U-5-randInt(1,5),C-5-randInt(3,10
Line(U-randInt(0,9),C-randInt(0,8),3,2
If 4<8fPart(Ans/8
C+4->C
U+(C=I+Z->U
If C=I+Z:I->C:End
ClrDraw
ClrHome
Menu("More?","Yes",1,"No",2)
Lbl 2
ClrDraw
ClrHome
DelVar Str4
DelVar B
DelVar C
DelVar I
DelVar J
DelVar U
DelVar Y
DelVar Z
Stop
If I were to make a fast version of this program, what should I do? I am currently using KermMartian's book to learn TI-BASIC, but I am still stuck. Also, I assume running this on a TI84+CSE would surely be a horrendously crappy experience (try it yourself if you have a CSE).

Edit (Eeems): added code tags
« Last Edit: January 15, 2017, 03:06:27 pm by Eeems »
Feel free to download any of my programs:
http://www.ticalc.org/archives/files/authors/115/11518.html

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Fastest way to render random points and lines?
« Reply #3 on: January 15, 2017, 05:06:41 pm »
You look good for the most part!
The clrHome's aren't necessary. The GoTo 1 isn't needed either, since the program just passes over them.
The delVar's aren't really needed anyway. It would be a good idea to delete the strings, but the letter vars don't matter.
You could probably do something to compress str4... it is pretty huge.
I'm not exactly sure what you are trying to accomplish, but would this work?
Code: [Select]
For(X,0,500)
If randInt(0,1):Then
Line(randInt(Xmin,Xmax),randInt(Ymin,Ymax),randInt(Xmin,Xmax),randInt(Ymin,Ymax))
Else
Pt-On(randInt(Xmin,Xmax),randInt(Ymin,Ymax))
End
End
That should generate random lines and points on the screen.
I'm still around... kind of.

Offline CalcMax

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +0/-0
  • TI-84+SE for play, NSpire CX CAS for hard work
    • View Profile
Re: Fastest way to render random points and lines?
« Reply #4 on: January 16, 2017, 06:04:00 am »
Thanks alot. Already started building a new program from this. This is so much better and faster than my bloatcode.
Feel free to download any of my programs:
http://www.ticalc.org/archives/files/authors/115/11518.html