4 ms·
HTML5 is a beginner programmer's best friend! Nest a html, body and script tags, slap something like this inside, and off you go: canvas = document.createEle
by Jare 14y ago
HTML5 is a beginner programmer's best friend! Nest a html, body and script tags, slap something like this inside, and off you go:
canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 480;
canvas.style.background = "#F0F";
context = canvas.getContext("2d");
document.body.appendChild(canvas);
playerX = 100;
playerY = 100;
keyboard = [];
window.onkeydown = function(e) {keyboard[e.keyCode]=true};
window.onkeyup = function(e) {keyboard[e.keyCode]=false};
setInterval(function() {
if (keyboard[37]) playerX--;
if (keyboard[39]) playerX++;
if (keyboard[38]) playerY--;
if (keyboard[40]) playerY++;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#0F0";
context.fillRect(playerX, playerY, 20, 20);
}, 16);
- ygra 14y agoThe beginning programmer me from more than a decade ago would have run away, screaming.
- randallsquared 14y agoReally? Because I remember typing hundreds of lines into terrible keyboards for not much more result than this, and then hoping, hoping, hoping that nothing went wrong when saving it to cassette tape, or I'd have to type it all in again. If kids today are not getting sucked into programming, then in my opinion the reason is more to do with all the things online competing with programming for their time.
- ygra 14y agoOh, sure. Things used to take a lot of code back then and heck, I've written hundreds, if not thousands of lines of crappy beginner's code while learning, be it BASIC, Turbo Pascal or later VB¹. The point you make about so many things competing for at-the-computer time may be valid, indeed. But still, thinking back I remember disliking Delphi compared to VB because I thought it to be too complicated. “Why do I need a class just to have a window? And what's all that stuff I don't know from Pascal? Eek! Back to VB.” In retrospect that sounds silly, but when you're a beginner with no formal education in the field the priorities are perhaps different. At least they were for me. I ended up writing Object Pascal code years later and learned a lot more languages, but I guess most of my initial fiddling and writing fun things was with QB and TP. No forced OOP, not too many concepts to learn before starting (I stayed away from PEEK and POKE because I didn't understand what they did). Javascript doesn't really feel like a beginner-friendly language to me, actually. To grasp that snippet above you have to figure out at least parts of the DOM and events. I probably wouldn't have done that back then. ______ ¹ Yes, I already had hard drives in my day. The one time I sat at a computer with a cassette tape drive was when I was three and my father never let me use it again afterwards – randomly mashing buttons was not very appreciated, I guess.
- WayneDB 14y agoI don't think so. BASIC has much simpler syntax than Javascript. It's got clearly defined and easy to understand rules. It typically runs in a "pure" environment that you won't have to fight with (as compared to "the browsers"). Furthermore, if you learn the dirty hack known as HTML/CSS/JS first...you will forever be tainted. Javascript will become "good enough" for every programming task. It's not.
- FourthProtocol 14y agoAgree, emphatically. If your hammer is HTML/CSS/JS, then every nail starts to look like a thumb.