Skip to content

Commit 8489d13

Browse files
authored
fix dispatch args for forwar, right, arc (#3114)
1 parent 5887760 commit 8489d13

File tree

1 file changed

+64
-96
lines changed

1 file changed

+64
-96
lines changed

js/logo.js

Lines changed: 64 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,20 +1839,21 @@ class Logo {
18391839

18401840
const suppressOutput = tur.singer.suppressOutput;
18411841

1842+
let arg;
18421843
const __pen = (turtle, name, b, timeout) => {
18431844
switch (name) {
1844-
case "penup":
1845-
case "pendown":
1846-
break;
1847-
default:
1848-
const arg = this.parseArg(
1849-
this,
1850-
turtle,
1851-
this.blockList[b].connections[1],
1852-
b,
1853-
this.receivedArg
1854-
);
1855-
break;
1845+
case "penup":
1846+
case "pendown":
1847+
break;
1848+
default:
1849+
arg = this.parseArg(
1850+
this,
1851+
turtle,
1852+
this.blockList[b].connections[1],
1853+
b,
1854+
this.receivedArg
1855+
);
1856+
break;
18561857
}
18571858
const _penSwitch = (name) => {
18581859
switch (name) {
@@ -1907,14 +1908,25 @@ class Logo {
19071908
}
19081909
};
19091910

1910-
const __right = (turtle, arg, timeout) => {
1911+
const __right = (turtle, b, waitTime, stepTime, sign) => {
1912+
const arg = this.parseArg(
1913+
this,
1914+
turtle,
1915+
this.blockList[b].connections[1],
1916+
b,
1917+
this.receivedArg
1918+
) * sign;
19111919
if (suppressOutput) {
19121920
const savedPenState = tur.painter.penState;
19131921
tur.painter.penState = false;
19141922
tur.painter.doRight(arg);
19151923
tur.painter.penState = savedPenState;
19161924
} else {
1917-
setTimeout(() => tur.painter.doRight(arg), timeout);
1925+
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
1926+
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
1927+
const deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor);
1928+
setTimeout(() => tur.painter.doRight(deltaArg), deltaTime);
1929+
}
19181930
}
19191931
};
19201932

@@ -1942,14 +1954,25 @@ class Logo {
19421954
}
19431955
};
19441956

1945-
const __forward = (turtle, arg, timeout) => {
1957+
const __forward = (turtle, b, waitTime, stepTime, sign) => {
1958+
const arg = this.parseArg(
1959+
this,
1960+
turtle,
1961+
this.blockList[b].connections[1],
1962+
b,
1963+
this.receivedArg
1964+
) * sign;
19461965
if (suppressOutput) {
19471966
const savedPenState = tur.painter.penState;
19481967
tur.painter.penState = false;
19491968
tur.painter.doForward(arg);
19501969
tur.painter.penState = savedPenState;
19511970
} else {
1952-
setTimeout(() => tur.painter.doForward(arg), timeout);
1971+
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
1972+
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
1973+
const deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor);
1974+
setTimeout(() => tur.painter.doForward(deltaArg), deltaTime);
1975+
}
19531976
}
19541977
};
19551978

@@ -2059,14 +2082,32 @@ class Logo {
20592082
}, timeout);
20602083
};
20612084

2062-
const __arc = (turtle, arg1, arg2, timeout) => {
2085+
const __arc = (turtle, b, waitTime, stepTime) => {
2086+
const arg1 = this.parseArg(
2087+
this,
2088+
turtle,
2089+
this.blockList[b].connections[1],
2090+
b,
2091+
this.receivedArg
2092+
);
2093+
const arg2 = this.parseArg(
2094+
this,
2095+
turtle,
2096+
this.blockList[b].connections[2],
2097+
b,
2098+
this.receivedArg
2099+
);
20632100
if (suppressOutput) {
20642101
const savedPenState = tur.painter.penState;
20652102
tur.painter.penState = false;
20662103
tur.painter.doArc(arg1, arg2);
20672104
tur.painter.penState = savedPenState;
20682105
} else {
2069-
setTimeout(() => tur.painter.doArc(arg1, arg2), timeout);
2106+
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
2107+
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
2108+
const deltaArg = arg1 / (NOTEDIV / tur.singer.dispatchFactor);
2109+
setTimeout(() => tur.painter.doArc(deltaArg, arg2), deltaTime);
2110+
}
20702111
}
20712112
};
20722113

@@ -2341,74 +2382,22 @@ class Logo {
23412382
break;
23422383

23432384
case "right":
2344-
arg = this.parseArg(
2345-
this,
2346-
turtle,
2347-
this.blockList[b].connections[1],
2348-
b,
2349-
this.receivedArg
2350-
);
2351-
2352-
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
2353-
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
2354-
const deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor);
2355-
__right(turtle, deltaArg, deltaTime);
2356-
}
2357-
2385+
__right(turtle, b, waitTime, stepTime, 1);
23582386
waitTime += NOTEDIV * stepTime;
23592387
break;
23602388

23612389
case "left":
2362-
arg = this.parseArg(
2363-
this,
2364-
turtle,
2365-
this.blockList[b].connections[1],
2366-
b,
2367-
this.receivedArg
2368-
);
2369-
2370-
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
2371-
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
2372-
const deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor);
2373-
__right(turtle, -deltaArg, deltaTime);
2374-
}
2375-
2390+
__right(turtle, b, waitTime, stepTime, -1);
23762391
waitTime += NOTEDIV * stepTime;
23772392
break;
23782393

23792394
case "forward":
2380-
arg = this.parseArg(
2381-
this,
2382-
turtle,
2383-
this.blockList[b].connections[1],
2384-
b,
2385-
this.receivedArg
2386-
);
2387-
2388-
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
2389-
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
2390-
const deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor);
2391-
__forward(turtle, deltaArg, deltaTime);
2392-
}
2393-
2395+
__forward(turtle, b, waitTime, stepTime, 1);
23942396
waitTime += NOTEDIV * stepTime;
23952397
break;
23962398

23972399
case "back":
2398-
arg = this.parseArg(
2399-
this,
2400-
turtle,
2401-
this.blockList[b].connections[1],
2402-
b,
2403-
this.receivedArg
2404-
);
2405-
2406-
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
2407-
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
2408-
const deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor);
2409-
__forward(turtle, -deltaArg, deltaTime);
2410-
}
2411-
2400+
__forward(turtle, b, waitTime, stepTime, -1);
24122401
waitTime += NOTEDIV * stepTime;
24132402
break;
24142403

@@ -2461,32 +2450,11 @@ class Logo {
24612450
break;
24622451

24632452
case "arc":
2464-
arg1 = this.parseArg(
2465-
this,
2466-
turtle,
2467-
this.blockList[b].connections[1],
2468-
b,
2469-
this.receivedArg
2470-
);
2471-
arg2 = this.parseArg(
2472-
this,
2473-
turtle,
2474-
this.blockList[b].connections[2],
2475-
b,
2476-
this.receivedArg
2477-
);
2478-
2479-
for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) {
2480-
const deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor;
2481-
const deltaArg = arg1 / (NOTEDIV / tur.singer.dispatchFactor);
2482-
__arc(turtle, deltaArg, arg2, deltaTime);
2483-
}
2484-
2453+
__arc(turtle, b, waitTime, stepTime);
24852454
waitTime += NOTEDIV * stepTime;
24862455
break;
24872456

24882457
default:
2489-
// console.debug(name + " is not supported inside of Note Blocks");
24902458
break;
24912459
}
24922460
}

0 commit comments

Comments
 (0)