lib/play.py)
30|
Realtime 2D/3D game runtime: pygame (window, input, audio) + ModernGL
(OpenGL, GLSL shaders, meshes, textures). Import with
use play;.
Not the same as built-in
game.ticBestMove (tic-tac-toe AI).
40| Install optional deps:
pip install 'someProgrammingLanguage[play]'
(pygame, moderngl, numpy, Pillow). Needs a desktop display. Check with
play.depsOk() (returns
1 / 0).
use play;
win <- play.window(640, 480, "My Game");
tex <- play.solidTexture(win, 1, 0.3, 0.5, 1);
test.while(test.isEqualNumber(win.isOpen(), 1)):
win.tick(60);
win.poll();
test.ifTrue(test.isEqualNumber(win.keyPressed("escape"), 1)):
win.close();
end;
win.clear(0.05, 0.05, 0.08, 1);
win.drawSprite(tex, 100, 80, 64, 64);
win.flip();
end;
play.window(w, h, title) — OpenGL window handleplay.shader(win, vertSrc, fragSrc) / play.shaderFile(win, vertPath, fragPath)play.defaultShader(win) — lit mesh; play.pulseShader(win) — demo fullscreen FXplay.texture(win, path) / play.solidTexture(win, r, g, b, a)play.mesh(win, positions, indices [, normals, uvs])play.quad(win) / play.box(win) / play.sphere(win, segments)play.camera() — eye/target/fov; viewMatrix() / projMatrix(aspect)mat4Identity, perspective, lookAt, translate, rotateX/Y/Z, scale, mulplay.loadSound(path) / play.playSound(snd, loops)play.imageEditor(win [, img|path]) — slider image editor (see image library)play.textureFromImage(win, img) — upload an image.* buffer as a sprite textureisOpen, close, poll, tick(fps), time, dt, flip, titleclear(r,g,b[,a]), enableDepth(0|1)keyDown, keyPressed, mouseX, mouseY, mouseDowndrawSprite(tex, x, y, w, h [, angle, r,g,b,a]), drawQuad, drawFullscreen(shader)draw(mesh, shader, model [, view, proj] [, tex])setShaderUniform(shader, name, number|list) — conventions u_model, u_view, u_proj, u_tex, u_timeFrom repo root, with play extras installed (source .venv_play/bin/activate or pip install -e '.[play]'):
python3 -m someProgrammingLanguage.main examples/play/hello_sprite.spl python3 -m someProgrammingLanguage.main examples/play/shader_pulse.spl python3 -m someProgrammingLanguage.main examples/play/spin_cube.spl python3 -m someProgrammingLanguage.main examples/play/bounce_squares.spl python3 -m someProgrammingLanguage.main examples/play/particle_sim.spl python3 -m someProgrammingLanguage.main examples/play/chemistry_sim.spl python3 -m someProgrammingLanguage.main examples/play/digit_recognizer.spl python3 -m someProgrammingLanguage.main examples/play/image_editor.spl
examples/play/hello_sprite.splexamples/play/shader_pulse.splexamples/play/spin_cube.splexamples/play/digit_recognizer.spl
— draw a digit (mouse drag) and classify it with
lib/neural_network/ (pure SPL forward pass). Sidebar lists P(0)…P(9).
examples/play/image_editor.spl
— slider editor (hue, saturation, brightness, contrast, …). Uses
use image; for import/export.
Code-only edits: examples/image_edit/image_edit.spl.
Implementation:
lib/play.py +
someProgrammingLanguage/spl_play/