CONST pip180
= 3.141592 / 180
min_weight = 6
gravity = 1
obj_c = 1000 'number objects
DIM obj
(obj_c
- 1, 9) '0,1 posX,Y 3fix/mover cent_x = monx / 2: cent_y = mony / 2: zoom = 1.8
'cobweb
ag0 = 320 'size
ag1 = 18 'felbontas ag
ag2 = 14 'felbontas net
ag3 = ag0 * .18 / 2 'rad1
ag4 = ag0 * .9 / 2 'rad2
ang = (360 / ag1 * t + randx(360 / ag1 * .3)) * pip180
x1
= SIN(ang
) * ag3
+ randx
(ag3
* .1) y1
= COS(ang
) * ag3
+ randx
(ag3
* .1) x2
= SIN(ang
) * ag4
+ randx
(ag4
* .2) y2
= COS(ang
) * ag4
+ randx
(ag4
* .2)
aobj = t2 + ag2 * t
obj(aobj, 0) = x1 + (x2 - x1) / (ag2 - 1) * t2
obj(aobj, 1) = y1 + (y2 - y1) / (ag2 - 1) * t2
obj(aobj, 2) = 1.9 'min_weight
obj(aobj, 3) = 1
' IF t2 = ag2 - 1 THEN obj(aobj, 3) = 0
obj(aobj, 4) = 1
'connections
conn_c
= 1000:
DIM conn
(conn_c
- 1, 4): ac
= 0
FOR t
= 0 TO ag2
- 2:
FOR t2
= 0 TO ag1
- 1: conn
(ac
, 0) = t2
* ag2
+ t: conn
(ac
, 1) = t2
* ag2
+ ((t
+ 1) MOD ag2
) conn
(ac
, 2) = SQR((obj
(conn
(ac
, 0), 0) - obj
(conn
(ac
, 1), 0)) ^ 2 + (obj
(conn
(ac
, 0), 1) - obj
(conn
(ac
, 1), 1)) ^ 2) conn(ac, 2) = conn(ac, 2) + randx(conn(ac, 2) * .1)
conn
(ac
, 3) = 1: ac
= ac
+ 1:
NEXT t2
, t
FOR t
= 0 TO ag2
- 1:
FOR t2
= 0 TO ag1
- 1: conn
(ac
, 0) = t
+ ag2
* t2: conn
(ac
, 1) = t
+ ag2
* ((t2
+ 1) MOD ag1
) conn
(ac
, 2) = SQR((obj
(conn
(ac
, 0), 0) - obj
(conn
(ac
, 1), 0)) ^ 2 + (obj
(conn
(ac
, 0), 1) - obj
(conn
(ac
, 1), 1)) ^ 2) conn(ac, 2) = conn(ac, 2) + randx(conn(ac, 2) * .1)
conn
(ac
, 3) = 1: ac
= ac
+ 1:
NEXT t2
, t
polar_p = ag1 * ag2
obj
(polar_p
+ t
, 0) = ((t
AND 1) * 2 - 1) * ag0
/ 2 obj
(polar_p
+ t
, 1) = (SGN(t
AND 2) * 2 - 1) * ag0
/ 2 obj(polar_p + t, 2) = 6 'min_weight
obj(polar_p + t, 3) = 0
obj(polar_p + t, 4) = 1
mindis = 999999999
dis
= SQR((obj
(polar_p
+ t
, 0) - obj
(a
, 0)) ^ 2 + (obj
(polar_p
+ t
, 1) - obj
(a
, 1)) ^ 2) * .8 IF dis
< mindis
THEN mindis
= dis: conn_n
= a
conn(ac, 0) = polar_p + t
conn(ac, 1) = conn_n
conn(ac, 2) = mindis
conn(ac, 3) = 1
ac = ac + 1
stiff = 1
'show info
wch
= -1:
FOR a
= 0 TO obj_c
- 1 ' LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
'IF wch = a THEN PRINT "<--- using mousewheel !" 'change weights with mousewheel
IF wch
<> -1 THEN obj
(wch
, 2) = obj
(wch
, 2) + mw
/ 10:
IF obj
(wch
, 2) < min_weight
THEN obj
(wch
, 2) = min_weight
IF moving
THEN PRINT "press SPACE to FIX/FLY" ELSE PRINT "grab the ball with the mouse and move it!" ' PRINT "S-button - rigid / flexible connections";
'draw objects
x = cent_x + obj(a, 0) * zoom: y = cent_y + obj(a, 1) * zoom
' CIRCLE (x, y), obj(a, 2) * zoom: _PRINTSTRING (x, y), LTRIM$(STR$(a))
'draw connections
x1 = obj(conn(a, 0), 0) * zoom + cent_x: y1 = obj(conn(a, 0), 1) * zoom + cent_y
x2 = obj(conn(a, 1), 0) * zoom + cent_x: y2 = obj(conn(a, 1), 1) * zoom + cent_y
'calculate moving
FOR a
= 0 TO obj_c
- 1: obj
(a
, 6) = obj
(a
, 0): obj
(a
, 7) = obj
(a
, 1) 'connections vector
vec_x = 0: vec_y = 0: vec_c = 0
x
= -1:
FOR t2
= 0 TO 1:
IF conn
(t
, t2
) = a
THEN x
= conn
(t
, t2
XOR 1) disx = obj(a, 0) - obj(x, 0)
disy = obj(a, 1) - obj(x, 1)
ang = (-degree(disx, disy) + 0) * pip180
dis
= SQR(disx
* disx
+ disy
* disy
) power = (dis - conn(t, 2)) * .6 ' obj(a, 2) ^ 2 '/ 20
IF stiff
THEN power
= power
/ obj
(a
, 2) ^ 2 * 4 vec_x
= vec_x
+ SIN(ang
) * power
vec_y
= vec_y
- COS(ang
) * power
vec_c = vec_c + 1
gravity = 0 '.1
lass = .90
obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass
obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
obj(a, 6) = obj(a, 0) + obj(a, 4)
obj(a, 7) = obj(a, 1) + obj(a, 5)
FOR a
= 0 TO obj_c
- 1:
FOR t
= 0 TO 1: obj
(a
, t
) = obj
(a
, 6 + t
):
NEXT t
, a
'mouse moving activing
mindis = 99999999
mouse_near = -1
disx
= (cent_x
+ obj
(a
, 0) * zoom
) - _MOUSEX disy
= (cent_y
+ obj
(a
, 1) * zoom
) - _MOUSEY dis
= SQR(disx
* disx
+ disy
* disy
) IF dis
< 60 AND mindis
> dis
THEN mouse_near
= a:mindis
= dis
moving = 1
obj
(mouse_near
, 0) = (_MOUSEX - cent_x
) / zoom
obj
(mouse_near
, 1) = (_MOUSEY - cent_y
) / zoom
stiff
= stiff
XOR ABS(inkey2$
= "s")
'commands
FUNCTION degree
(a
, b
): degreex
= ATN(a
/ (b
+ .00001)) / pip180: degreex
= degreex
- 180 * ABS(0 > b
): degreex
= degreex
- 360 * (degreex
< 0): degree
= degreex:
END FUNCTION