Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw on January 26, 2008

Title: Sinus scrolling done right?
Post by: Pixel_Outlaw on January 26, 2008


I know how to make my text flow in sin() waves but my question is how to do it "correctly".

How do you usually pair this with scrolling text?

What is the method used most commonly to make your scrollers wrap around the screen?

How do you avoid slowdown when you are drawing say 20 sentences?

That is alot to ask at once but I would like to start with the best solution rather than poke around in the dark on this one.
Title: Re: Sinus scrolling done right?
Post by: Shockwave on January 26, 2008
Slowdown should not really be a problem on todays computers, the method behind a sine scroll is straight forward.

If you view your letter as a bitmap:


  #####
#######
##      ##
#######
##      ##
##      ##


It is made out of rows and columns.
In most programming languages/apis there is usually a method that allows you to cut a rectangle out of a bitmap and draw it.

So for the letter "a" above the program would need to  chop it up into vertical slices which can then be drawn in the right position.

Sin is straight forward;

n=sin(theta)

Returns a value in n between -1 and +1 depending on the angle you feed it (theta).

you can transform this into something more useful;

y=(99*sin(theta)) + 100

Produces a large sine wave that ranges from the top of the screen to about 200 pixels down.

So it's really a matter of chopping those letters up and drawing them in the right place. On the Amiga, they were done using the Blitter chip, you could set up a "blitter window" and move this around as you were blitting the letters.

There are dozens of sine scrollers here, if you need more help please ask :)