Následující tabulka obsahuje výběr skriptů použitých v projektu.
| Soubor | Autor | Skript |
| roundextrusion.wrl | Filip |
Script {
# On initialization, generates a round cross section of `complexity` vertices
# and radius `radius` and assigns this cross section to Extrusion `ext`.
field SFNode ext USE Ext
field SFInt32 complexity IS complexity # number of vertices
field SFFloat radius IS radius
directOutput TRUE
url "javascript:
function generateCylinderCrossSection(n, r) {
//console.assert(n >= 1);
var cs = new MFVec2f();
var x = 0;
var y = r;
var vec0 = new SFVec2f(x, y);
cs[0] = vec0;
for (var i = 1; i < n; i++) {
var angle = i / n * Math.PI * 2;
var x = r * Math.sin(angle);
var y = r * Math.cos(angle);
var vec = new SFVec2f(x, y);
cs[i] = vec;
}
cs[n] = vec0;
return cs;
}
// Generates crossSection
function initialize() {
//console.assert(complexity >= 1);
ext.set_crossSection = generateCylinderCrossSection(complexity, radius);
}
"
}
|
| winding.wrl | Filip |
DEF RopeScript Script {
# This script controls `coil` scale so that its y component runs between
# `heightMin` and `heightMax` based on rotation `rot` of a CylinderSensor
# `cylinderSensor`. `cylinderSensor.minAngle` corresponds to `heightMin` and
# `cylinderSensor.maxAngle` corresponds to `heightMax`.
# When height surpasses `heightTarget`, `winding_solved` is set to true, indicating
# a successful solution of the winding puzzle.
eventIn SFRotation rot # rotation from CylinderSensor
field SFNode coil USE RopeCoil
field SFFloat heightMin 0.05
field SFFloat heightMax 0.3
field SFFloat heightTarget 0.28 # When height surpasses this value, winding_solved is set to true.
field SFNode cylinderSensor USE HingeCS # CylinderSensor
eventOut SFBool winding_solved IS winding_solved
url "javascript:
function setCoilHeight(h) {
var scale = new SFVec3f(1, h, 1);
coil.scale = scale;
if (h >= heightTarget) {
winding_solved = true;
}
}
function initialize() {
setCoilHeight(heightMin);
}
function rot(value) {
var angle = value[3];
var angleMin = cylinderSensor.minAngle;
var angleMax = cylinderSensor.maxAngle;
var angle01 = (angle - angleMin) / (angleMax - angleMin);
var height = heightMin + (heightMax - heightMin) * angle01;
setCoilHeight(height);
}
"
directOutput TRUE
}
|