Ooops
January 26, 2021, 04:42:59 AM

Author Topic: [bb] Mouse Follow Text by n8r2k [ 1+ years ago ]  (Read 452 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Mouse Follow Text by n8r2k [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Mouse Follow Text
Author : n8r2k
Posted : 1+ years ago

Description : Now on <a href="http://n8r2k.deviousbytes.com/" target="_blank">http://n8r2k.deviousbytes.com/[/url] . Basically just wave your mouse and the 3 text strings follow it with a slightly different speed for each string.

Code :
Code: BlitzBasic
  1. ;set the graphics
  2. Graphics 800,600,32,2
  3.  
  4. n = 5
  5.  
  6. ;call the arrays
  7. Dim textcolor(n)
  8. Dim x(n)
  9. Dim y(n)
  10. Dim speed(n)
  11.  
  12. ;set the color and speed starting variables
  13. d = 255
  14. s = 2
  15.  
  16. ;set the color For the Text
  17. For a = 1 To n
  18.         textcolor(a) = d
  19.         d = d - 200/n
  20. Next
  21.  
  22. ;set the speed for the text
  23. For b = 1 To n
  24.         speed(b) = s
  25.         s = s + 1
  26. Next
  27.  
  28. ;set the text string value
  29. Const followtext$ = "This is the followtext demo"
  30.  
  31. ;start the loop
  32. While Not KeyHit(1)
  33.  
  34. ;clear the screen
  35. Cls
  36.  
  37. ;move the text strings around on screen
  38. For c = n To 1 Step -1
  39.         x(c) = x(c) + ((MouseX() - x(c))/speed(c))
  40.         y(c) = y(c) + ((MouseY() - Y(c))/speed(c))
  41.  
  42.         Color textcolor(c),textcolor(c),textcolor(c)
  43.                                
  44.         Text x(c)+10,y(c),followtext$
  45. Next
  46.  
  47. ;flip the buffers
  48. Flip
  49.  
  50. ;loop to beginning
  51. Wend
  52.  
  53. ;end the program
  54. End


Comments :


xlsior(Posted 1+ years ago)

 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:
Code: [Select]
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. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal