-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathp5CommandFunctionCall.js
95 lines (83 loc) · 1.95 KB
/
p5CommandFunctionCall.js
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
class p5CommandFunctionCall extends p5Command
{
constructor(list, elmt)
{
super(list,elmt);
this.name = this.elmt.find(".cm-p5-function").text();
this.parameters = [];
this.elmt.find(".param").each( (index,p) => this.addParameter(p) );
this.gfx = null;
}
execute()
{
this.highlight();
console.log("execute "+this.name);
this.gfx = makeGraphic(this);
if (this.gfx)
{
g.interpreter.graphics.push(this.gfx);
return this.gfx.beginAnimation();
}
else
return this.wait();
}
addParameter(p)
{
let name = $(p).attr("data-name");
this.parameters.push( new p5FunctionParameter(this,name,$(p)) );
}
getParameter(name)
{
let v = null;
for (let i=0; i<this.parameters.length;i++)
if ( this.parameters[i].name == name )
{
v = this.parameters[i];
break;
}
return v;
}
getParameterValue(p)
{
let param = this.getParameter(p);
if (param)
return param.getValue();
return 0;
}
getParams()
{
let s = "";
let sep="";
this.parameters.forEach( v => {s += `${sep}${v.value}`; sep=","} );
return s;
}
getString()
{
return `${this.name}(${this.getParams()});`;
}
evaluate()
{
eval( this.getString() );
}
highlightParameters(paramNames)
{
paramNames.forEach( name => {
let param = this.getParameter(name);
if (param)
param.highlight();
} )
}
unhighlightParameters(paramNames)
{
paramNames.forEach( name => {
let param = this.getParameter(name);
if (param)
param.unhighlight();
} )
}
unhighlight()
{
super.unhighlight();
this.unhighlightParameters( this.parameters.map( p=>p.name ) );
}
}