Эффект радара
Небольшой по размеру и красивый пример, реализующий анимацию: эффект
радара.
Платформы: Windows, Linux
Автор: ikkejw. Создано в 2006
году
'by ikkejw #INCLUDE "fbgfx.bi" Randomize Timer Const pi As Double = Atn(1) * 4 Const deg2rad = pi / 180 Const false = 0 Const true = Not false Const xres = 640, yres = 480 Const p = 100 'precision (default: 100 (=2 decimal places)) Const radarcolor = Rgba(128,255,128, 255) Const radarlinecolor = Rgba(255,255,255,255) Const gridcolor = Rgba(0, 128, 0, 255) Const fadecolor = Rgba(0, 0, 0, 1) Const borderr = 255 Const borderg = 255 Const borderb = 255 Const bordersize = 10 Const grid = true Const gridsize = 15 Const roundgrid = true Const roundgridcolor = Rgba(192, 255, 192, 255) Const roundgridstart = 0.1 Const roundgridend = 0.9 Const roundgridsize = 25 Const movespeed = 0.01 Const maxthings = 10 Const thingmovespeed = 0.0005 Const thingchance = 250 'chance of 'things' appearing (default: 1 in 250) Const thingcolor = Rgba(255,255,255,255) Const thingsize = .01 Const thingsappearafter = 10 'degrees Const dp = 2 'detection precision (less is more precise) Const xrn = xres / yres Screenres xres,yres,32,2, &h40 Screenset 1,0 Locate Hiword(Width)/2, Loword(Width)/2-5 Print "Loading...":Flip Dim As Uinteger i, a, b, c, d = 1 Dim As Single g, h Redim As Double _sint_(0 To 360*p - 1), _cost_(0 To 360*p - 1), _tant_(0 To 360*p - 1) #DEFINE sint(x) _sint_( (x) Mod (360 * p) ) #DEFINE cost(x) _cost_( (x) Mod (360 * p) ) #DEFINE tant(x) _tant_( (x) Mod (360 * p) ) For i = 0 To 360*p sint(i) = Sin((i/p)*deg2rad) cost(i) = Cos((i/p)*deg2rad) tant(i) = Tan((i/p)*deg2rad) Next i Type thingtype alive As Integer x As Single y As Single End Type Dim As thingtype thing(maxthings) Dim As Uinteger things Dim As Any Ptr circ, temp temp = Imagecreate(xres, yres) circ = Imagecreate(xres, yres) If grid = true Then For g = (xres Mod gridsize) / 2 - 1 To xres Step gridsize Line circ, (g, 0)-(g, yres), gridcolor Next g For g = (yres Mod gridsize) / 2 - 1 To yres Step gridsize Line circ, (0, g)-(xres, g), gridcolor Next g End If Line temp, (0,0)-(xres,yres), Rgba(0,0,0,255), BF Circle temp, (xres / 2, yres / 2), yres / 2, Rgba(255,0,255,255),,,, F Put circ, (0,0), temp, Trans For g = 1 To bordersize Step .01 h = Iif(g < bordersize/2, (g*2)/bordersize, (bordersize/2)/ g) Circle circ, (xres / 2, yres / 2), (yres / 2) + g, Rgba(borderr * h, borderg * h, borderb * h, 255) Next g Window (-xrn, -1)-(xrn, 1) If roundgrid = true Then For i = 1 To 360*p Step gridsize*p Line circ, (sint(i) * roundgridstart, cost(i) * roundgridstart)-(sint(i) * roundgridend, cost(i) * roundgridend), roundgridcolor Next i For i = 1 To 100 Step roundgridsize Circle circ, (0,0), i/100, roundgridcolor Next i End If Line temp, (-xrn, 1)-(xrn, -1), Rgba(0,0,0,255), BF For a = 0 To 360*p Step p For b = 0 To p Step 1 c = a + b Line temp, (0,0)-(sint(c), cost(c)), radarcolor Next b Line temp, (0,0)-(sint(c), cost(c)), radarlinecolor d xor= 1:If d = 1 Then Line temp, (-xrn, -1)-(xrn, 1), fadecolor, BF Put temp, (-xrn,1), circ, Trans Next a g = xrn: h = -(1+bordersize/(xres/2/xrn)) For a = 1 To 360*p Step p For b = 0 To p Step 1 c = a + b Line temp, (0,0)-(sint(c), cost(c)), radarcolor Next b Line temp, (0,0)-(sint(c), cost(c)), radarlinecolor d xor= 1:If d = 1 Then Line temp, (-xrn, -1)-(xrn, 1), fadecolor, BF g -= movespeed If g <= -xrn Then g = -xrn Put temp, (-xrn,1), circ, Trans Line temp, (-xrn, 1)-(h, -1), Rgba(255,0,255,255), BF Cls Put (g, 0.9975), temp, Trans Flip Sleep 1 If Inkey <> "" Then System Next a Do For a = 1 To 360*p Step p If (things < maxthings) And (Int(Rnd * thingchance) + 1 = 1) Then For i = 0 To maxthings With thing(i) If .alive = false Then .alive = true .x = (Rnd * 2) - 1 .y = 1 Exit For End If End With Next i End If For b = 0 To p Step 1 c = a + b Line(0,0)-(sint(c), cost(c)), radarcolor, 'B 'uncomment this for a funny effect Next b Line(0,0)-(sint(c), cost(c)), radarlinecolor For i = 0 To maxthings With thing(i) If .alive = true Then .y -= thingmovespeed If .y <= -1 Then .alive = 0 a -= thingsappearafter*p: b = false If ((.x>0) And (.y>0)) And ((a/p>=0 ) And (a/p<=90 )) And ((Int(tant(a)*dp)) = (Int((.x/.y)*dp))) Then b = true If ((.x>0) And (.y<0)) And ((a/p>=90 ) And (a/p<=180)) And ((Int(tant(a)*dp)) = (Int((.x/.y)*dp))) Then b = true If ((.x<0) And (.y<0)) And ((a/p>=180) And (a/p<=270)) And ((Int(tant(a)*dp)) = (Int((.x/.y)*dp))) Then b = true If ((.x<0) And (.y>0)) And ((a/p>=270) And (a/p<=360)) And ((Int(tant(a)*dp)) = (Int((.x/.y)*dp))) Then b = true a += thingsappearafter*p:If b = true Then Circle (.x, .y), thingsize, thingcolor,,,, F End If End With Next i d xor= 1:If d = 1 Then Line(-xrn, -1)-(xrn, 1), fadecolor, BF Put (-xrn,1), circ, Trans Flip Sleep 1 If Inkey <> "" Then Exit Do Next a Loop Imagedestroy circ System