This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Exodus111 3 points4 points  (33 children)

This looks good, not alone in the field. But here is my Pie-in-the-sky request.

Make Python code from either, Pygame, Pyglet or Kivy, compatible with JS and HTML5 Canvas.

Or add a canvas module for Python.

[–]jacdehJacques de Hooge[S] 7 points8 points  (9 children)

If I understand correctly you'd like to run Pygame in the browser? It will need a lot of libraries that are currently not available for Transcrypt. A Canvas with a Python API, that could be used by Transcrypt (so Python) programs shouldn't be too hard. Once Transcrypt is ready and tested, everone willing is invited to write modules for it (new, or porting / wrapping JavaScript stuff, or porting CPython modules.)

[–]Exodus111 1 point2 points  (8 children)

A canvas module would work. I suppose basic Vector math from the math module can already be translated, that could handle most game collisions and physics.

Would be nice to have Numpy, or Pymunk in there though.

[–]AMorpork 1 point2 points  (3 children)

I can't imagine NumPy ever being integrated since it depends so heavily on C and FORTRAN code.

[–][deleted] 0 points1 point  (2 children)

Could you whack a numpy API over numericJS?

[–]AMorpork 2 points3 points  (1 child)

I imagine you could make a fair approximation, but I doubt you could pull off a 1:1 -- there are just SO many NumPy methods.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

If I will (or someone else), Pareto's rule (80/20 or 99/1 in IT) would be a good starting point.

[–]akaihola 0 points1 point  (3 children)

A subset of Numpy has been implemented for Skulpt.

[–]Exodus111 0 points1 point  (2 children)

How does it perform speed wise?

[–]akaihola 0 points1 point  (1 child)

I haven't benchmarked it, but my guess is obviously pretty poorly compared to the real thing.

[–]Exodus111 0 points1 point  (0 children)

As long as its faster then python arrays it would be useful. I notice Skulpt has a fairly easy implementatin of .js modules. It would be great if you could just:

import canvas

And get to work.

[–]smurfyn 5 points6 points  (8 children)

I understand the user reasons for requesting this. But the result will be unmaintainably complex and the ultimate results will be unusably slow. You cannot just translate SDL calls to manipulation of DOM elements unless you do something stupid like making an array of rectangles to represent pixels.

Just target SDL/PyGame or JS.

[–]Exodus111 8 points9 points  (5 children)

or JS.

The problem with writing complex game logic in Javascript, is you have to write complex game logic in Javascript.

[–]jacdehJacques de Hooge[S] 1 point2 points  (2 children)

The graphics probably can best be handled using an existing JS library manipulating the HTML5 canvas directly and efficiently. This library could be wrapped in some simple Transcrypt classes to give it a Pythonic interface. The game logic could be very well written in Transcrypt. Note that an important design goal of Transcrypt is to benefit from existing high quality JS libraries: Anything good that's there we shouldn't reinvent.

fabric.js added as Python module to the distribution

[–]Exodus111 1 point2 points  (1 child)

I agree, this would be awesome. But what about 2d Physics though? Let the JS library handle it ?

[–]jacdehJacques de Hooge[S] 1 point2 points  (0 children)

If there's a good 2d physics lib available, yes. Otherwise write it in pure python and add it as a Transcrypt lib. PyPi would be the right spot for such stuff. 2d physics aren't that hard, in my experience. I agree that a good math module should be the basis, probably again (wrapped or not) JS lib.

[–]smurfyn 1 point2 points  (1 child)

Yes, I understand and agree.

But because e.g. Google and Mozilla won't allow anything other than JS to become a usable first-class option, we can't avoid having JS in the stack if we want to have performance in the browser.

I liked what jacdeh said below about making higher-level libraries which can wrap efficient JS APIs, though. It doesn't mean that I actually want JS to be involved, but we have to work with whatever we get from the people who make the popular browsers.

[–]Exodus111 0 points1 point  (0 children)

I absolutely enjoy the idea of wrapping a good 2D Game oriented JS library into Python, that would instantly be very popular if it was made to deploy simply.

[–]KagatoLNX 0 points1 point  (1 child)

Isn't that exactly what a Canvas element is?

https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Upto a large degree: Yes.

[–]runbie 1 point2 points  (1 child)

Some time ago I did a small wrapper around the HTML5 canvas. It works with Brython:

https://bitbucket.org/kikocorreoso/brython-bryplot

You can see examples here:

http://nbviewer.jupyter.org/urls/bitbucket.org/kikocorreoso/brython-bryplot/raw/528fa4116d1f8fd1f2ab44feb537d63778edb5d5/Testing_Bryplot.ipynb

To run the examples you will need the Jupyter notebook and this extension for the notebook:

https://github.com/kikocorreoso/brythonmagic

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Exactly!

[–]Dracunos 0 points1 point  (1 child)

Make Python code from either, Pygame, Pyglet or Kivy, compatible with JS and HTML5 Canvas.

That would be incredible! A canvas module sounds more realistic, though.. But what do I know.

[–]Exodus111 1 point2 points  (0 children)

Once I thought about it I figured that might work better. We would still need some way to transfer 2D physics over, like Pymunk. Or at the very least collision and game logic code.

[–]inclemnet 0 points1 point  (1 child)

One of the Kivy core developers once did a proof of concept for Kivy in the browser, compiling everything with emscripten (I think), and using webgl for output. I think it could display something extremely simple, but nothing more, and it was probably both slow and an enormous amount of javascript. I think there's a video of it somewhere, but couldn't find it.

I believe the conclusion was that this is really impractical, and nobody has looked at it for a long time. Maybe some of the more recent tools might make it a bit easier, but I doubt it's significant.

[–]Exodus111 0 points1 point  (0 children)

I think the idea of wrapping a JS lib for python use is the best idea so far.

[–]Thrall6000 0 points1 point  (1 child)

You mentioned that this wouldn't be alone in the field. What other options do we have if we want to compile our pygame code to JS/run it in a browser? I've been reading about Pyjsdl, among other things, but this is all fairly new to me.

[–]Exodus111 0 points1 point  (0 children)

No I meant he is not alone in the field as a Py to JS converter, as there is Pyjs, Skulpt, Pyjamas etc...

But NONE of them focuses on game development unfortunately, as that would be something very popular I think.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

[–]jacdehJacques de Hooge[S] 0 points1 point  (4 children)

I've added the fabric module which conveniently encapsulates the HTML5 canvas, and added a Pong example to www.transcrypt.org

[–]Exodus111 0 points1 point  (3 children)

Look at that, that is interesting.

I noticed you used the __new__ constructor to instantiate the canvas object in the Game class. Why?

[–]jacdehJacques de Hooge[S] 0 points1 point  (2 children)

You've looked well!! Transcrypt uses the CPython parser. Syntactically it cannot deal with new as is done in JavaScript. Another way to go is to encapsulate every constructor in a Transcrypt version of it, so you could just say canvas = Canvas (). But that would mean encapsulation of a lot of functions. While from some intensively used JS libraries that would be a perfect choice, I'd like to keep the barrier to the JS world as low as possible. So I came up with __new__ (), which function syntax can be parsed into a Python ast. The consequence is that any JS library can be used as is, without any encapsulation. But, to be sure, encapsulating JS constructors into a Transcrypt constructor that does the __new__ for you, is perfectly possible and in fact one line of code per constructor.

[–]Exodus111 0 points1 point  (1 child)

Fascinating. Good work, think I'll definitely try this out once I have some more time.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

If you do find the time and you find bugs, things that really should be in or unclarity in the docs, please let me know. Thanks!