January 24, 2021, 01:04:58 PM

### Author Topic: [bb] AnimLine by Andres [ 1+ years ago ]  (Read 500 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] AnimLine by Andres [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : AnimLine
Author : Andres
Posted : 1+ years ago

Description : This is just like the ordinary line function except this line is animated. Wave-style animation.

Code :
Code: BlitzBasic
1. Function AnimatingLine(x1, y1, x2, y2)
2.         Local dis = Sqr((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
3.
4.         For i = 1 To dis
5.                 flt# = Float i / dis
6.                 x = x1 + (x2 - x1) * flt#
7.                 y = y1 + (y2 - y1) * flt#
8.                 a =  i * 10 + MilliSecs() / 2
9.                         red = (Cos(a) + 1) * .5 * 255
10.                         green = (Cos(a) + 1) * .5 * 255
11.                         blue = (Cos(a) + 1) * .5 * 255
12.                 WritePixel x, y, (blue Or (green Shl 8) Or (red Shl 16) Or (\$FF000000)), GraphicsBuffer()
13.         Next
14. End Function

`Graphics 800, 600, 32, 1SeedRnd MilliSecs()x1# = 50y1# = 50x2# = 500y2# = 500sx1# = Rnd(-1, 1)sy1# = Rnd(-1, 1)sx2# = Rnd(-1, 1)sy2# = Rnd(-1, 1)While Not KeyHit(1) AnimatingLine(x1, y1, x2, y2) x1 = x1 + sx1 y1 = y1 + sy1 x2 = x2 + sx2 y2 = y2 + sy2 If x1 < 0 Or x1 > GraphicsWidth() Then sx1 = -sx1 If y1 < 0 Or y1 > GraphicsHeight() Then sy1 = -sy1 If x2 < 0 Or x2 > GraphicsWidth() Then sx2 = -sx2 If y2 < 0 Or y2 > GraphicsHeight() Then sy2 = -sy2 FlipWendFunction AnimatingLine(x1, y1, x2, y2) Local dis = Sqr((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) For i = 1 To dis flt# = Float i / dis x = x1 + (x2 - x1) * flt# y = y1 + (y2 - y1) * flt# a =  i * 10 + MilliSecs() / 2 red = (Cos(a) + 1) * .5 * 255 green = (Cos(a) + 1) * .5 * 255 blue = (Cos(a) + 1) * .5 * 255 WritePixel x, y, (blue Or (green Shl 8) Or (red Shl 16) Or (\$FF000000)), GraphicsBuffer() NextEnd Function`