How to wave hands for space key?

34 views
Skip to first unread message

Larry Serflaten

unread,
Sep 1, 2017, 7:44:04 AM9/1/17
to Khan Academy Javascript Technical Q&A
Paste the code below into a new program and see if this is close to what you want:


var keys = [];
var spin = 30;


keyPressed = function(){
    keys[keyCode] = true;
};
keyReleased = function(){
    keys[keyCode] = false;
};


var hand = function(x, y, a){
    a += 509;
    quad(x+sin(a-20)*15, y+cos(a-20)*15, x+sin(a-15)*35, y+cos(a-15)*35,
         x+sin(a+15)*35, y+cos(a+15)*35, x+sin(a+20)*15, y+cos(a+20)*15);
};

var guy = function(){
    if (keys[32]){spin = (spin + 6) % 360;}
    background(255);
    ellipse(100, 150, 60, 80);
    ellipse(100, 100, 50, 60);
    hand(50, 150, sin(spin)*30+31);
    hand(150, 150, sin(spin)*30+31);
};


draw = function() {
    guy(); 
};

Reply all
Reply to author
Forward
0 new messages