/
Timeline.rtf
128 lines (127 loc) · 5.36 KB
/
Timeline.rtf
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue255;\red0\green0\blue0;\red96\green96\blue96;
\red191\green0\blue0;\red0\green0\blue191;\red0\green115\blue0;\red51\green51\blue191;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
\f0\fs18 \cf2 var\cf3 name = \cf4 "compscore"\cf3 ;\
\cf2 var\cf3 randomseed, offsettime, lastoffsettime, score;\
\cf2 var\cf3 speed = 1;\
\cf2 var\cf3 drones, dronelines;\
\cf2 var\cf3 track = 0;\
\cf2 var\cf3 tempgui, tempview; \cf5 // temp\cf3 \
\cf2 var\cf3 scale = 30;\
\cf2 var\cf3 timeline = 0;\
\
tempgui = \cf6 Window\cf3 .new(\cf4 "score"\cf3 , \cf6 Rect\cf3 (830, 100, 360, 700)).front;\
tempview = \cf6 TextView\cf3 (tempgui, \cf6 Rect\cf3 (0, 0, 360, 700));\
tempview.string_(\cf4 "oo"\cf3 );\
\
#randomseed, score = (\cf4 "dronemachines/"\cf3 ++name++\cf4 ".drnCSC"\cf3 ).load;\
score = score.sort(\{\cf2 arg\cf3 a, b; a[0] <= b[0] \}); \cf5 // home made sort algorithm as there are subarrays\cf3 \
score = score.collect(\{\cf2 |event|\cf3 event[0] = event[0]/speed \});\
offsettime = score[0][0];\
lastoffsettime = offsettime;\
\
\cf6 Post\cf3 << score;\
\
drones = ();\
dronelines = [];\
\
m = 2000;\
\
w = \cf6 Window\cf3 .new(\cf4 "oo"\cf3 , \cf6 Rect\cf3 (300, 100, 500, 700)).front;\
c = \cf6 SCScrollView\cf3 (w, \cf6 Rect\cf3 (0, 0, 500, 700)).background_(\cf6 Color\cf3 .grey.alpha_(0.3));\
\
u = \cf6 UserView\cf3 (c, \cf6 Rect\cf3 (0, 0, 500, m)).background_(\cf6 Color\cf3 .white);\
u.bounds_(\cf6 Rect\cf3 (0, 0, 500, m));\
\
score.do(\{\cf2 | event, i |\cf3 \
\cf2 var\cf3 cmd, agent;\
cmd = event[1].replace(\cf4 " "\cf3 , \cf4 ""\cf3 ).replace(\cf4 " "\cf3 , \cf4 ""\cf3 );\
if(event[1].contains(\cf4 "createDrone"\cf3 ), \{ \cf5 // find a new drone and then its score\cf3 \
track = track + 1;\
b = cmd[cmd.find(\cf4 "name:"\cf3 )+6 .. ];\
c = b[0 .. b.find(\cf4 "'"\cf3 )-1 ];\
drones.add(c.asSymbol -> ().add(\cf7 \\track\cf3 -> track).add(\cf7 \\name\cf3 -> c.asSymbol ).add(\cf7 \\dronescore\cf3 -> [ event ] ));\
\}, \{\
agent = cmd[0.. cmd.find(\cf4 "."\cf3 )-1];\
if(drones[agent.asSymbol].isNil.not, \{\
drones[agent.asSymbol][\cf7 \\dronescore\cf3 ] = drones[agent.asSymbol][\cf7 \\dronescore\cf3 ].add(event);\
\});\
[\cf7 \\agent\cf3 , agent].postln;\
\
\});\
\});\
\
\cf6 Post\cf3 << drones; \cf4 ""\cf3 .postln; \
\
drones.do(\{ \cf2 | drone, i |\cf3 \
\cf5 //dronelines = dronelines.add( TimelineDrone( drones.size+1, event[0]*60*scale, 4000 ) );\cf3 \
(drone[\cf7 \\dronescore\cf3 ][0][0]*60*scale).postln;\
\cf5 //dronelines = dronelines.add( TimelineDrone( drone[\\track], drone[\\dronescore][0][0]*60*scale, 4000 ).submitScore(drone[\\dronescore]) );\cf3 \
dronelines = dronelines.add( \cf6 TimelineDrone\cf3 ( drone, scale, tempview ) );\
\});\
\
\
u.mouseDownAction_(\{\cf2 |view, x, y, modifiers, buttonNumber, clickCount|\cf3 \
[view, x, y, modifiers, buttonNumber, clickCount].postln; \
dronelines.copy.do(\{ \cf2 |drone, i|\cf3 drone.mouseDown(dronelines, i, x, y); \}); \
u.refresh;\
if(\cf6 Rect\cf3 ((u.bounds.width/2)-20, u.bounds.height-40, 40.5, 20.5).contains(\cf6 Point\cf3 (x, y)), \{\
\
\});\
\});\
u.mouseMoveAction_(\{\cf2 |view, x, y, modifiers, buttonNumber, clickCount|\cf3 \
dronelines.copy.do(\{ \cf2 |drone, i|\cf3 drone.mouseMove(x, y, modifiers.isShift); \
u.refresh; \})\
\});\
u.mouseUpAction_(\{\cf2 |view, x, y, modifiers, buttonNumber, clickCount|\cf3 \
dronelines.copy.do(\{ \cf2 |drone, i|\cf3 drone.mouseUp(dronelines, i, x, y)\});\
score = score.sort(\{\cf2 arg\cf3 a, b; a[0] <= b[0] \}); \cf5 // Sort main score\cf3 \
u.refresh; \
\cf4 "______________________score___________________"\cf3 .postln;\
\cf6 Post\cf3 << score; \cf4 ""\cf3 .postln;\
if(\cf6 Rect\cf3 ((u.bounds.width/2)-20, u.bounds.height-40, 40.5, 20.5).contains(\cf6 Point\cf3 (x, y)), \{\
\cf4 "EXPANDING"\cf3 .postln; \
m = m + 2000;\
u.bounds_(\cf6 Rect\cf3 (0, 0, 500, m));\
u.refresh;\
\});\
\});\
\
Pen.font_(Font("Monaco", 9));\
\
u.drawFunc_(\{\
\cf6 Color\cf3 .black.set;\
11.do(\{\cf2 arg\cf3 i;\
\cf6 Pen\cf3 .line(\cf6 Point\cf3 (50+(i*20), 20)+0.5, \cf6 Point\cf3 (50+(i*20), m)+0.5); \
\});\
((m/scale).floor).do(\{\cf2 arg\cf3 j;\
\cf6 Pen\cf3 .line(\cf6 Point\cf3 (50, j*scale+20)+0.5, \cf6 Point\cf3 (250, j*scale+20)+0.5);\
\cf6 Pen\cf3 .stringAtPoint( (j+\cf4 "sec"\cf3 ).asString, \cf6 Point\cf3 (5, j*scale+20)+0.5);\
\
\}); \
\cf6 Pen\cf3 .stroke;\
dronelines.do(\{ \cf2 | drone |\cf3 drone.draw \});\
\cf6 Color\cf3 .white.set;\
\cf6 Pen\cf3 .fillRect( \cf6 Rect\cf3 ((u.bounds.width/2)-20, u.bounds.height-40, 40.5, 20.5)+0.5);\
\cf6 Color\cf3 .black.set;\
\cf6 Pen\cf3 .strokeRect( \cf6 Rect\cf3 ((u.bounds.width/2)-20, u.bounds.height-40, 40.5, 20.5)+0.5);\
\cf6 Pen\cf3 .stringAtPoint(\cf4 "down"\cf3 , \cf6 Point\cf3 ((u.bounds.width/2)-15, u.bounds.height-38) );\
\cf6 Color\cf3 .red.set;\
\cf6 Pen\cf3 .line(\cf6 Point\cf3 (50, timeline)+0.5, \cf6 Point\cf3 (350, timeline)+0.5); \
\cf6 Pen\cf3 .stroke;\
\});\
\
t = \{\
var now;\
var starttime = Main.elapsedTime;\
\cf8 inf\cf3 .do(\{\
now = \cf0 Main.elapsedTime - starttime;\
//[\\now, now].postln;\cf3 \
timeline = (now * scale).round(0.01); \cf5 // FIND THE SCALE\cf3 \
\{u.refresh\}.defer;\
0.05.wait; \
\})\
\}.fork\
}