Educational materials

WiiLab Example Code - BouncingBall: resetWindow

Note: MATLAB R2007a or greater is required for this code to run correctly.

Annotations

Used at the beginning to initially set up the bouncing ball figure and position plot. Called again if the user pushes the Wiimote's 'HOME' button to restart and throw the ball again.

Initializes a plot for the ball's position, draws the ball, displays user instructions, and calls helper functions to allow the ball to be lifted and thrown.

Raw Source Code

The source code is also available as a .m file download at the bottom of the page.


function resetWindow(bb_figure)
%  usage:    resetWindow()
%  purpose:  creates a ball in the open window, displays the appropriate
%            user instructions, and allows the user to lift and toss the
%            ball

global xVel;
global yVel;
global ball;
global graph;
    
    % initialize a plot for graphing the ball's position
    figure(2);
    plot(0, 0, 'w');
    hold on;
    setLabels(1, 'X-Coordinates', 'Y-Coordinates', 'Ball''s Position', 1);
    axis([0, 500, 0, 300]);
    graph = gca;

    figure(bb_figure);
    % draw a ball
    ball = drawCircle(18, 10, 10);
    
    % user instructions
    dir1 = 'Hold the B button and tilt the Wiimote up to lift the ball.';
    dir2 = 'Now hold B, swing the Wiimote to the right, and release B to throw the ball.';
    
    t1 = text(250, 290, dir1, 'HorizontalAlignment', 'center', 'FontSize', 12);
            
    waitForButtonPress('B');
    
    lift(ball);
    
    hide(t1);
    t2 = text(250, 290, dir2, 'HorizontalAlignment', 'center', 'FontSize', 12);
    
    waitForButtonPress('B');
    
    % obtain the horizontal velocity as the user "throws" the ball
    getXVel();
    yVel = 0;
    
    hide(t2);
    
end

r5 - 30 Jun 2008 - 17:23:33 - JessicaSzweda
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Syndicate this site RSSATOM