Jump to content



0

Sine Demo


2 replies to this topic

#1 orion1052003 OFFLINE  

orion1052003

    Chopper Commander

  • 140 posts

Posted Fri Sep 9, 2011 10:50 PM

Tursi, how would you make this SIne Wave move down the screen unbroken? I changed some values from the originals experimenting,
but did not get it to be continuous on screen.



10 PRINT TAB(30);"SINE WAVE"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT :: PRINT :: PRINT :: PRINT :: PRINT
50 B=0
110 FOR T=0 TO 40 STEP .25
120 A=INT(26+25*SIN(T))
130 PRINT TAB(A);
140 IF B=1 THEN 180
150 PRINT "CREATIVE"
160 B=1
170 GOTO 200
180 PRINT "COMPUTING"
190 B=0
200 NEXT T
999 END

Attached Files



#2 Tursi OFFLINE  

Tursi

    Stargunner

  • 1,448 posts
  • Location:SJC

Posted Fri Sep 9, 2011 11:07 PM

I remember that program. :)

You just have to fix the width. You only have 28 columns across the screen for PRINT. "COMPUTING" is 9 characters wide, so you need a range from 1-17 for TAB().

As I explained on the list, SIN() returns a value from -1 to +1. So your math needs to deal with that. The fact that he loop counts from 0 to 40 is mathematically arbitrary, but works just as well as carefully chosen values in this case.

So the problem boils down to line 120, which needs to convert a floating point range from -1 to +1 into an integer range from 1-17. The original range is 2 (-1 to +1), and the new range is 16 (1-17) so 16/2 gives us 8 as the ratio.

So, if we multiply the output of SIN by 8, the new range is -8 to +8. We want 1-17, so we add 9. Now we have the range we want.

The other function in there is INT, which truncates a number to an integer.

So the new 120 is:

120 A=INT(9+8*SIN(T))

And that should fit on the screen.

Feel free to experiment - always experiment. Also, there are lots of skilled people here, no need to single me out. I'm on vacation. ;)

#3 orion1052003 OFFLINE  

orion1052003

    Chopper Commander

  • 140 posts

Posted Sat Sep 10, 2011 5:32 PM

Thanks. I was just replying and wanted to send pictures. I heard you were good to ask though, by someone on the group. I played around with the numbers of the SINE parameters before reading your message, but came up with the wrong numbers each time. I will mess around further and see what happens when I change things in hopes of learning something more.

Edited by orion1052003, Sat Sep 10, 2011 5:32 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users