Author Topic: Filling the Lines  (Read 5358 times)

0 Members and 1 Guest are viewing this topic.

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Filling the Lines
« on: March 14, 2012, 11:43:59 am »
I'm attempting to make a different kind-of flashlight test...
Two lines start from the middle of the screen and stretch out to the points (0,63) and (95,63) "Keep in mind that they both start at (44,28)"
How would I fill the space in between these lines? "Like a flashlight" :D
I included a word document for a pic if you need to see it...
(I'm not home atm :P)

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Filling the Lines
« Reply #1 on: March 14, 2012, 12:02:20 pm »
Maybe something like this would work:
Code: [Select]
0->B
For a,28,63
B+1->B
Pxlline A,44,A,44+B
Pxlline A,44,A,44-B
Endfor
This works on my Ti-89 basic. If you edit it slightly it'll probably work for you.

EDIT: I made a mistake(also x and y are switched I think)
Better code:
Code: [Select]
0->B
For a,0,95
B+1->B
Pxlline 28,44,63,B(You might have to swap the x with y so it's 44,28,B,63)
Endfor
« Last Edit: March 14, 2012, 12:25:24 pm by Stefan Bauwens »


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Filling the Lines
« Reply #2 on: March 14, 2012, 12:23:07 pm »
If the beam doesn't need to be rotated, the code posted above should work well (although since the lines are vertical, I think the Rect() command may be faster).  Does your flashlight beam need to be rotated?  Because that completely changes the challenge :P

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Filling the Lines
« Reply #3 on: March 14, 2012, 02:43:51 pm »
If the beam doesn't need to be rotated, the code posted above should work well (although since the lines are vertical, I think the Rect() command may be faster).  Does your flashlight beam need to be rotated?  Because that completely changes the challenge :P

Yes it does need to be rotated (Just a test, not a game :P)
But wouldn't Rect( do a rectangle and not a "pyramid"-like shape?

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Filling the Lines
« Reply #4 on: March 14, 2012, 02:59:21 pm »
But wouldn't Rect( do a rectangle and not a "pyramid"-like shape?
You still need the for-loop and just do one-wide rectangles. That's usually a bit faster than the Line(-command

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: Filling the Lines
« Reply #5 on: March 14, 2012, 03:17:18 pm »
You can for-loop the rectangular boundary of the region you want to illuminate (could be the whole screen) and then for each pixel, calculate its angle to the light source.  Only turn on the pixel if the angle is between the 2 angles of the light.  You can calculate the angle from pixel (x,y) to light source (a,b) with tan-1(x-a,y-b)
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Filling the Lines
« Reply #6 on: March 14, 2012, 03:20:05 pm »
How can you draw slant lines with rect() ?


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Filling the Lines
« Reply #7 on: March 14, 2012, 04:06:59 pm »
You can't.  In your original code you only had vertical lines, which I was substituting for a 1 wide rectangle for speed :) If the beam is rotated, things become a bit more complicated.  Quigibo's solution would work, but I fear for the speed, since you would be doing a tan-1 for every pixel on the screen, which is likely going to be super slow.  I imagine there would also be other options involving custom line algorithms and rectangular scan-lines, but this does seem like a tricky problem :/

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Filling the Lines
« Reply #8 on: March 14, 2012, 04:08:21 pm »
Is the line really too slow it couldn't be an option?


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Filling the Lines
« Reply #9 on: March 14, 2012, 04:10:46 pm »
It's still an option, but if you are doing vertical or horizontal lines, you might as well use Rect(). 

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Filling the Lines
« Reply #10 on: March 14, 2012, 04:11:45 pm »
Yeah. I see now :)
« Last Edit: March 14, 2012, 04:12:03 pm by Stefan Bauwens »


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me