Pong in HTML 5 part 2

Let’s put a box around the court and bounce the ball when it hits the bottom.

Pong2

<html>
<head>
<body>

<canvas id=”game_maze” width=”800″ height=”300″ style=’border-style:solid;’>
This text is displayed if your browser does not support HTML5 Canvas.
</canvas>

<script>
//create ball on canvas
var gamemaze = document.getElementById(‘game_maze’);
var ball = gamemaze.getContext(’2d’);
ball.fillStyle = ‘grey’;

//initialize ball’s properties

oldxvector=1;
oldyvector=1;

xvector=1;
yvector=1;

//use a changeable variable for the amount to update the Y position.
increment=1;

//update ball’s position
Game_update = function() {

//get old ball properties to use in erasing it at it’s old position
oldxvector=xvector;
oldyvector=yvector;

//if ball hits edge change it’s trajectory with a bounce
if(oldyvector>290){
increment=-1;
}

//update ball position properties to move downward 45 degrees.
xvector=xvector+1;
yvector=yvector+increment;
};

Game_draw = function() {

ball.clearRect(oldxvector,oldyvector,5,5);
ball.fillRect(xvector,yvector,5,5);
};

//update the game logic and draw the game once every second
Game_fps = 40;

//loop logic and draw updates forever
Game_run = function() {
Game_update();
Game_draw();
};

// Start the game loop
Game_intervalId = setInterval(Game_run, 1000 / Game_fps);

</script>
</body>
</html>

Pong in HTML 5 part 1

How to move a ‘ball’ on a 45 degree trajectory in HTML 5/Javascript. You can see this bad boy in action at 1 fps: Here.

 

<html>
<head>
</head>
<body>
<canvas id=”game_maze” width=”700″ height=”700″>
This text is displayed if your browser does not support HTML5 Canvas.
</canvas>

<script>
//create ball on canvas
var gamemaze = document.getElementById(‘game_maze’);
var ball = gamemaze.getContext(’2d’);
ball.fillStyle = ‘grey’;

//initialize ball’s properties

oldxvector=1;
oldyvector=1;

xvector=1;
yvector=1;

//update ball’s position
Game_update = function() {

//get old ball properties to use in erasing it at it’s old position
oldxvector=xvector;
oldyvector=yvector;

//update ball position properties to move downward 45 degrees.
xvector=xvector+1;
yvector=yvector+1;
};

Game_draw = function() {
ball.clearRect(oldxvector,oldyvector,5,5);
ball.fillRect(xvector,yvector,5,5);
};

//update the game logic and draw the game once every second
Game_fps = 1;

//run logic and draw updates
Game_run = function() {
Game_update();
Game_draw();
};

// Start the game loop
//It’s run as a repeating interval to give the browser a chance to update the screen
Game_intervalId = setInterval(Game_run, 1000 / Game_fps);

</script>
</body>
</html>

Further reading:
JS game loop
HTML 5 Canvas basics
HTML 5 Canvas Docs

Hyperinflation

1) Stop consulting the mainstream media for economic advice.

2) Read the following statistics until their significance is thoroughly understood.

Annual U.S. tax revenue: $2,170,000,000,000
Federal budget: $3,820,000,000,000
New debt: $1,650,000,000,000
National debt: $14,271,000,000,000
Recent budget cut: $38,500,000,000

In order to make this information easier to absorb, we’ll remove eight zeros and think of it as a household budget:

Annual family income: $21,700
Money the family spent: $38,200
New debt on the credit card: $16,500
Outstanding balance on the credit card: $142,710
Total budget cuts: $385

Article

Proof it is climate hoax?

November 28, 2011 by Don Surber

The second batch of e-mails — stolen according to the Associated Press (which sued to get Sarah Palin’s e-mails) — shows once and for all that climate change/global warming is a fraud and not science, according to critics of the academicians who swear that man’s activity is pushing weather to extremes that will devastate life on Earth in just a few years.
Article

Bloomberg is right

“It was not the banks that created the mortgage crisis,” Bloomberg told an audience gathered for an Association for a Better New York breakfast, Capital New York first reported. “It was plain and simple Congress who forced everybody to go and give mortgages to people who were on the cusp.” Bloomberg argued that Congress forced banks and lending giants Fannie Mae and Freddie Mac to loosen their mortgage standards.
Video

Occupy Wall street gives up on socialism

Volunteer cooks at Zuccotti Park scale down their menu for three days, in an alleged attempt to get rid of freeloaders. Hypocritical?

The story: The New York Post reports that the Occupy Wall Street volunteer kitchen staff is tired of having to feed “professional homeless” people and others posing as protesters so they can eat for free at Zuccotti Park. To “show they mean business,” the Post says, OWS cooks shut down for two hours on Thursday. Then for three days starting Friday, the cooks will only offer brown rice and other basics instead of their tasty typical fare (organic chicken, roasted beets, sheep-milk-cheese salad). Protest organizers maintain that the slowdown is merely intended to free up time for kitchen workers to expand their operation. But a security worker tells the Post the cooks are feeling “overworked and under appreciated,” and plan to redirect vagrants to nearby soup kitchens.
more from ‘The week’

John McCarthy, Inventor of Lisp and AI R.I.P.

Artificial Intelligence, Lisp, Garbage Collection, Time sharing,
Electronic Commerce, these are just some of the things that John McCarthy was involved in inventing:

http://www.nytimes.com/2011/10/26/science/26mccarthy.html

He died the very week that we are studying chapter 8 of the AI book on first order logic, which had this to say about him:

McCarthy (1958) was primarily responsible for the introduction of first-order logic as a
tool for building A1 systems.
p 267 2nd ed.

He designed Lisp as a first order logic tool. Here are a couple pdf’s that summarize ch 8, and also a bit on Prolog, another popular FOL tool:

http://www.cs.umd.edu/~nau/cmsc421/chapter08.pdf

http://www.comp.nus.edu.sg/~kanmy/courses/3243_2005/lectureNotes/w8-all.pdf

Educating Programmers

I think there are 4 big problems with programming education:

1. Programming is fairly often not a required 2 course elective for all math/science/engineering students.

2. Programming 1 should start with basic boolean logic taught with Both basic math and electronic circuits, through solving useful basic problems, and progress to state machines and finally a Forth based system.

3. Programing 2 should cover this book: https://gustavus.edu/+max/concrete-abstractions-pdfs/ConcreteAbstractions.pdf

-When students start with Java, they are getting the worst of all worlds: a system that requires one rigid type of development process for reasons that are arbitrary, opaque and will also be unclear to a new student. Also, I believe the use of the C related languages and even all imperative languages is a historical wrong turn. Programming directly in an abstract syntax tree, in other words Lisp, is both more mathematically analyzable and more concise.

4. A more general science/math/engineering education problem of
not teaching on a historical time line with real world examples. The best demonstrator of that being how Calculus 1 is taught with an emphasis on modern analytical proofs instead of the older intuitive astronomy problem solving use it was originally invented for.