Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/compiling/GScompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Move new files to glowscript source:
6) Copy the file embed/rapydscript.js to lib/rapydscript/compiler.js and insert this at start of file:

In compiler.js you may need to replace the randrange machinery with this, though this is now in the RapydSript repo:
# unlike the python version, this DOES build a range object, feel free to reimplement\ndef randrange():\n if arguments.length is 1:\n return randbelow(int(arguments[0]))\n start = int(arguments[0])\n stop = int(arguments[1])\n if arguments.length < 3:\n step = 1\n else:\n step = int(arguments[2])\n width = stop - start\n if step is 1:\n if width > 0:\n return start + randbelow(width)\n raise ValueError(\"empty range for randrange()\")\n if step > 0:\n n = (width + step - 1) // step\n elif step < 0:\n n = (width + step + 1) // step\n else:\n raise ValueError(\"zero step for randrange()\")\n if n <= 0:\n raise ValueError(f\"empty range in randrange({start}, {stop}, {step})\")\n return start + step * randbelow(n)\n\ndef randint(a, b):\n return int(random()*(b-a+1) + a)\n\ndef uniform(a, b):\n return random()*(b-a) + a\n\ndef randbelow(n):\n return Math.floor(random()*n)\n\ndef choice(seq):\n if seq.length > 0:\n return seq[randbelow(seq.length)]\n else:\n raise IndexError()\n\n
# unlike the python version, this DOES build a range object, feel free to reimplement\ndef randrange():\n if arguments.length is 1:\n return randbelow(int(arguments[0]))\n start = int(arguments[0])\n stop = int(arguments[1])\n if arguments.length < 3:\n step = 1\n else:\n step = int(arguments[2])\n width = stop - start\n if step is 1:\n if width > 0:\n return start + randbelow(width)\n raise ValueError(\"empty range for randrange()\")\n if step > 0:\n n = (width + step - 1) // step\n elif step < 0:\n n = (width + step + 1) // step\n else:\n raise ValueError(\"zero step for randrange()\")\n if n <= 0:\n raise ValueError(f\"empty range in randrange({start}, {stop}, {step})\")\n return start + step * randbelow(n)\n\ndef randint(a, b):\n return a + randbelow(b - a + 1)\n\ndef uniform(a, b):\n return random()*(b-a) + a\n\ndef randbelow(n):\n return Math.floor(random()*n)\n\ndef choice(seq):\n if seq.length > 0:\n return seq[randbelow(seq.length)]\n else:\n raise IndexError()\n\n

However you obtain the two RapydScript-NG files, you need to make the following changes:

Expand Down
2 changes: 1 addition & 1 deletion lib/rapydscript/compiler.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package/RScompiler.3.2.min.js

Large diffs are not rendered by default.