-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaves.nlogo3d
More file actions
77 lines (69 loc) · 2.23 KB
/
waves.nlogo3d
File metadata and controls
77 lines (69 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
globals [
membrane-edge-x ;; horizontal distance from center to edge of membrane
membrane-edge-y ;; vertical distance from center to edge of membrane
]
turtles-own [
edge? ;; are we on the edge of the membrane?
driver? ;; are we part of the green driving plate?
x ;; position on x axis in space
y ;; position on y axis in space
z ;; position on z axis in space
velocity ;; velocity along z axis
neighbor-turtles ;; agentset of turtles adjacent to us
]
to setup
clear-all
set membrane-edge-x floor (max-pxcor / 1.5 )
set membrane-edge-y floor (max-pycor / 1.5 )
set-default-shape turtles "circle"
ask patches with [(abs pxcor <= membrane-edge-x) and
(abs pycor <= membrane-edge-y) and
( pzcor = 0 ) ]
[ sprout 1
[
set edge? (abs xcor = membrane-edge-x) or
(abs ycor = membrane-edge-y)
if edge? [ set color blue ]
set driver? (abs (xcor - driver-x) <= driver-size) and
(abs (ycor - driver-y) <= driver-size)
if driver? [ set color green ]
set x xcor
set y ycor
set z 0
set velocity 0
recolor
ifelse driver? or edge?
[ set shape "square"
set size 0.5 ]
[ set shape "circle" ]
set heading 0
] ]
ask turtles
[ set neighbor-turtles turtles-on neighbors4 ]
reset-ticks
end
to recolor ;; turtle procedure
if not edge? and not driver?
[ set color scale-color red z -20 20 ]
end
to go
ask turtles with [not driver? and not edge?]
[ propagate ]
ask turtles
[ ifelse driver?
[ set z (driver-amplitude * (sin (0.1 * driver-frequency * ticks))) ]
[ set z (z + velocity)
recolor ]
set zcor z
]
tick
end
to propagate ;; turtle procedure -- propagates the wave from neighboring turtles
set velocity (velocity +
(stiffness * 0.01 *
(sum [z] of neighbor-turtles
- 4 * z)))
set velocity (((1000 - friction) / 1000) * velocity)
end
; Copyright 1996 Uri Wilensky.
; See Info tab for full copyright and license.