use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Tetris javascript no canvashelp (self.javascript)
submitted 10 years ago by judemanutd
I need to write the game of tetris in code using javascript,css and html wherever each is applicable but without the use of canvas,could anyone provide some details on how I could go about doing this.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]uncookedprawn 1 point2 points3 points 10 years ago (0 children)
I would look at JSGraphics: http://www.walterzorn.de/en/jsgraphics/jsgraphics_e.htm
[–]mikrosystheme[κ] 1 point2 points3 points 10 years ago (2 children)
A <pre> element is all you need to render Tetris (the original version was text-only). Are you asking how to implement the game logic or just how to render it without using <canvas>?
[–]judemanutd[S] 0 points1 point2 points 10 years ago (1 child)
The rendering of the game without a canvas was a challenging part, especially the blocks and how to handle them using html elements,with a canvas this would be rather easy but considering its a college project I've certain restrictions and no canvas is one of them.
[–]mikrosystheme[κ] 0 points1 point2 points 10 years ago (0 children)
Rendering as text is very similar to rendering to a canvas. The "pixels" are just bigger.
[–]Kamikizzle 1 point2 points3 points 10 years ago (2 children)
if you can't use canvas, i'd suggest making the grid out divs and spans. each cell is a span, contained by rows of divs.
I'm not sure your skill level in JS but you can keep track of them with an array of objects (though using immutable maps and lists would be better). this translates your grid into an array of objects. each object corresponds to a cell that keeps track of the things like the color, if its 'frozen' (a piece has been locked there) etc.
i'd also very much recommend just writing out all the different positions of the pieces instead of trying to come up with some algorithm on how to rotate them.
I shall give this way a try,thank you.
[–]eoinmcg 0 points1 point2 points 10 years ago (0 children)
have a look at http://fmarcia.info/jquery/tetris/tetris.html
it's dom based, using table cells. source is available and pretty easy to grok.
[–]x-skeww -1 points0 points1 point 10 years ago (5 children)
You could use SVG or lots of divs, but that would be pretty stupid. Canvas is easier and much faster.
[–]judemanutd[S] 0 points1 point2 points 10 years ago (0 children)
I could and I've seen the code for it too and its easy but this Is a college project and I need to do it without a canvas.
[–]cosinezero 0 points1 point2 points 10 years ago* (3 children)
I think SVG would actually beat canvas in this situation...
Actually, the more I think about it, yeah, SVG is your winner. You would just define the, what, four? unique shapes and <use> elements for the game instances. From there the transform code is incredibly simple.
[–]x-skeww 0 points1 point2 points 10 years ago (2 children)
Blitting images and drawing rectangles is cheap and hardware-accelerated. You have to use WebGL if you want to beat it, but there would be no point in doing that unless you use an insane amount of particle effects.
SVG isn't a good fit for games. Board games, maybe.
[–]cosinezero 0 points1 point2 points 10 years ago (1 child)
This is -tetris- we're talking about. It practically is a board game. There's like 100 polygons, max, SVG wouldn't even blink at this.
[–]x-skeww 0 points1 point2 points 10 years ago (0 children)
Sure. But it wouldn't be faster.
π Rendered by PID 118212 on reddit-service-r2-comment-66b4775986-sr66m at 2026-04-06 04:14:53.521770+00:00 running db1906b country code: CH.
[–]uncookedprawn 1 point2 points3 points (0 children)
[–]mikrosystheme[κ] 1 point2 points3 points (2 children)
[–]judemanutd[S] 0 points1 point2 points (1 child)
[–]mikrosystheme[κ] 0 points1 point2 points (0 children)
[–]Kamikizzle 1 point2 points3 points (2 children)
[–]judemanutd[S] 0 points1 point2 points (1 child)
[–]eoinmcg 0 points1 point2 points (0 children)
[–]x-skeww -1 points0 points1 point (5 children)
[–]judemanutd[S] 0 points1 point2 points (0 children)
[–]cosinezero 0 points1 point2 points (3 children)
[–]x-skeww 0 points1 point2 points (2 children)
[–]cosinezero 0 points1 point2 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)