const maxdetectors := 20
const numberofbolts := 2
const detectiondistance := 100
function distance (x1, y1, x2, y2 : int) : int
result round (((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5)
end distance
colorback (16)
cls
View.Set ("offscreenonly")
var mx, my, mb : int
var x, y, xx1, yy1, xx2, yy2 := 300
procedure calcline (x1, y1, x2, y2 : int, var xx1, yy1, xx2, yy2 : int)
var slope : real
var xx := (x2 - x1) / 3
if x2 - x1 not= 0 then
slope := (y2 - y1) / (x2 - x1)
else
slope := 999999999
end if
yy1 := round (y1 + (xx * slope))
xx1 := round (x1 + xx)
xx := (x2 - x1) / (3 / 2)
yy2 := round (y1 + (xx * slope))
xx2 := round (x1 + xx)
end calcline
function random (m, x : int) : int
var rr : int
randint (rr, m, x)
result rr
end random
var ysh1 := 0
var ysh2 := 0
type detectors :
record
x, y : int
end record
var arr : array 1 .. maxdetectors of detectors
for i : 1 .. maxdetectors
arr (i).x := random (1, 640)
arr (i).y := random (1, 400)
end for
loop
mousewhere (mx, my, mb)
for i : 1 .. maxdetectors
if distance (mx, my, arr (i).x, arr (i).y) < detectiondistance then
calcline (mx, my, arr (i).x, arr (i).y, xx1, yy1, xx2, yy2)
for ii : 1 .. numberofbolts
ysh1 := random (-10, 10)
drawline (mx, my, xx1 + ysh1, yy1 + ysh1, 54)
ysh2 := random (-10, 10)
drawline (xx1 + ysh1, yy1 + ysh1, xx2 + ysh2, yy2 + ysh2, 52)
drawline (xx2 + ysh2, yy2 + ysh2, arr (i).x, arr (i).y, white)
end for
end if
drawfilloval (arr (i).x, arr (i).y, 10, 10, random (1, 255))
end for
drawfilloval (300, 300, 10, 10, 12)
View.Update
cls
exit when hasch
end loop |