Use the A, S, D, F, and space keys to control individual digits. Move: 1 - right, 2 - left, 3 - up, 4 - down, 5 - closer, 6 - farther Use G to grasp with all digits. Use the arrow keys to rotate the hand in X, Y and the N and M keys to rotate in Z. Mouse or touch also rotates the display, but you must tap the screen first.
A fork of Mechanical Hand by Richard Bourne
xxxxxxxxxx
let digits=[];
let handPos, handVel;
let lapse = 0;
let xa = -30;
let ya = 40;
let za = 350;
function setup() {
createCanvas(1112, 834, WEBGL);
angleMode(DEGREES);
makeDigits();
}
function draw() {
orbitControl();
translate(xa,ya,za);
setLighting();
orientDisplay();
drawPalm();
for(let d of digits){
d.show();
d.flexback();
}
rotateHand();
operateDigits();
}
function makeDigits(){
handPos = createVector(80,50,10);
handVel = createVector(6,5,-2.5);
for(let i=0; i<4; i++){
let x = -100+i*40;
let y = 20*sin(55*i+10);
let pos = createVector(x,y,y);
let angles = createVector(6*i,25,0);
digits.push( new Digit(75+y,50+y/5, pos, angles) );
}
let pos = createVector(45,0,-36);
let angles = createVector(65,-20, -65);
digits.push( new Digit(60, 60, pos, angles) ); //Thumb
}
function setLighting(){
background(0, 100, 0);
ambientLight(100);
pointLight(150,150,150,200,200,200);
//orbitControl(1,1,0.01);
noStroke();
specularMaterial(50);
}
function orientDisplay(){
handPos.add(handVel);
handVel.mult(0.95);
rotateX(handPos.x);
rotateY(handPos.y);
rotateZ(-handPos.z);
}
function drawPalm(){
push();
translate(-30,-5,-45);
rotateZ(0);
rotateX(-18);
ellipsoid(50,20);
rotateX(90);
torus(60,20);
pop();
}
function rotateHand(){
if(keyIsDown(UP_ARROW)) handVel.x+=.1; // rotateX positive
if(keyIsDown(DOWN_ARROW)) handVel.x-=.1; // rotateX negative
if(keyIsDown(LEFT_ARROW)) handVel.y+=.1; // rotateY positive
if(keyIsDown(RIGHT_ARROW)) handVel.y-=.1; // rotateY negative
if(keyIsDown(78)) handVel.z+=.1; // N key - rotateZ positive
if(keyIsDown(77)) handVel.z-=.1; // M key - rotateZ negative
}
// Note - G key clasps the hand
function operateDigits(){
if(keyIsDown(65) || keyIsDown(71)){ // A or G - little finger
digits[0].a1-=4;
digits[0].a2-=8;
}
if(keyIsDown(83) || keyIsDown(71)){ // S or G - 4th finger
digits[1].a1-=4;
digits[1].a2-=8;
}
if(keyIsDown(68) || keyIsDown(71)){ // D or G - middle finger
digits[2].a1-=4;
digits[2].a2-=8;
}
if(keyIsDown(70) || keyIsDown(71)){ // F or G - index finger
digits[3].a1-=4.5;
digits[3].a2-=7;
}
if(keyIsDown(32) || keyIsDown(71)){ // Space or G - thumb
digits[4].a1-=3;
digits[4].a2-=7;
}
if(keyIsDown(49)){ // 1 - move right
xa--;
}
if(keyIsDown(50)){ // 2 - move left
xa++;
}
if(keyIsDown(51)){ // 3 - move up
ya--;
}
if(keyIsDown(52)){ // 4 - move down
ya++;
}
if(keyIsDown(53)){ // 5 - move closer
za+=4;
}
if(keyIsDown(54)){ // 6 - move farther
za-=4;
}
}