Code archives/Graphics/Mouse Follow Text

This code has been declared by its author to be Public Domain code.

Download source code

Mouse Follow Text by n8r2k2005
Now on http://n8r2k.deviousbytes.com/ . Basically just wave your mouse and the 3 text strings follow it with a slightly different speed for each string.
;set the graphics
Graphics 800,600,32,2

n = 5

;call the arrays
Dim textcolor(n)
Dim x(n)
Dim y(n)
Dim speed(n)

;set the color and speed starting variables
d = 255
s = 2

;set the color For the Text
For a = 1 To n
	textcolor(a) = d
	d = d - 200/n
Next 

;set the speed for the text
For b = 1 To n
	speed(b) = s
	s = s + 1
Next 

;set the text string value
Const followtext$ = "This is the followtext demo"

;start the loop
While Not KeyHit(1)

;clear the screen
Cls

;move the text strings around on screen
For c = n To 1 Step -1
	x(c) = x(c) + ((MouseX() - x(c))/speed(c))
	y(c) = y(c) + ((MouseY() - Y(c))/speed(c))

	Color textcolor(c),textcolor(c),textcolor(c)
				
	Text x(c)+10,y(c),followtext$
Next

;flip the buffers
Flip

;loop to beginning
Wend

;end the program
End

Comments

xlsior2005
On a fast computer, the mouse values have almost no chance to change within your loop, so there is no trailing visible at all: all text is drawn on exactly the same place.

This small change does make the trailing work though:

For c = 3 To 1 Step -1
	x(c) = x(c) + ((MouseX() - x(c))/speed(c))
	y(c) = y(c) + ((MouseY() - Y(c))/speed(c))

	Color r(c),g(c),b(c)
				
	Text x(c)+10,y(c),followtext$
Delay(5)
Next


The 5 millisecond delay within the loop give you a an opportunity to move the mouse between the redraws.


Code Archives Forum