General > General Technical Chat
Learning Simple Programming for a Ten Year Old?
Zero999:
I started programming with QBasic, which of course many remember was shipped with MS-DOS.
I've played with FreeBASIC which works quite well.
Another option is QB64, which I've not tried, but is supposed to be very close to the original QBasic.
https://qb64.com/
Cyberdragon:
--- Quote from: Smokey on November 13, 2022, 03:05:16 am ---
--- Quote from: DavidAlfa on November 12, 2022, 07:57:37 pm ---Didn't Lego made some sort of programmable stuff?
...
--- End quote ---
They are discontinuing the Mindstorms stuff, but I guess they have a new option:
https://www.theverge.com/2019/4/2/18292326/lego-spike-prime-programming-bricks-scratch-technic-robotics
--- End quote ---
They canned it since the new one was kinda meh and it's all online based. The software for older systems can still be found though, everything from RCX to EV3. If you want to get the new systems running on their own without Lego, use https://pybricks.com/
RJSV:
Try an approach, like an airplane flying lesson.
Kid sits a little back, while you go through a whole pile of install, activate, etc. But not for too long.
Then, you switch seats, have him enter something simple, like printf "My name is 'xxxx", maybe 3 times.
Then, a simple 'If Then', and build up from there.
That way you aren't teaching, immediately, the whole operating system, file system etc. Basically you would be letting more and more control (programming) be learned. Explain to kid, the operating system is a kind of environment, like a little village, explain he has to gradually learn, not just programming itself, but all the capability (he) needs to navigate the system.
And explicitly explain, the system is a lot to learn also, gradually, warning not to feel overwhelmed, by complexity, but that he has to develop focus, in things like program creation.
You guys can always switch seats, when you need to take the reins, when some compiler error gets in.
Nominal Animal:
For Python, I warmly recommend starting early with PySDL2 and/or Qt5 (PyQt5 or PySide2), and using Inkscape to create all graphics in the SVG (Scalable Vector Graphics) format, saving originals in Inkscape SVG format, and "finals" using Optimized SVG. The former retains your Inkscape guides and such, but the latter optimizes the SVG for parsers, also shrinking the file size. SVG images are fully scalable, support transparency, and even gradient fills. You can also use any browser to view SVG files.
The reason for this is that you can do real games and applications this way, and have them look as professional as you can. There are no limitations. Even if you decide you go to high-performance graphics via OpenGL, that works too; there are display widgets for that as well.
The one annoying thing with Inkscape is that when you do computer graphics with it, you need to do a three-step Document Setup in the beginning.
First, in File > Document Properties, you need to set Display Units: px and Units: px, Scale: 1, Checkerboard Background, and Width: and Height: to the desired size in pixels. This way, all px measurement units in the SVG file are in native SVG units, and you get the best results overall (no DPI issues et cetera; these work just fine even on HiDPI displays). See attached inkscape-1-pixel-mode.png.
Because Inkscape chose the right-hand coordinate system with origin at bottom left corner, changing document properties will always introduce an annoying translation to the SVG coordinates, even when the canvas is empty. To fix that, in Edit > XML Editor, select the id="layer1" element on the left, and then the transform on the right. Delete it using the Delete Attribute button top right, and close that window. See attached inkscape-2-fix-transform.png.
Modifying any of the layers in XML Editor causes Inkscape to drop to canvas root "layer". You don't want to draw there, you want to switch to Layer 1, because Inkscape uses the SVG g layers to do its internal markup and such. The selection is at the bottom left/center of the window; just click where it reads (root) and pick Layer 1. See attached inkscape-3-select-layer.png.
In Python, you can load SVG files as QPixmap objects, which are optimized for display on-screen. You can use a QPixmap in QLabels instead of text, in QGraphicsScenes, even in QPictures if you want to create a drawing application of some sort.
Of course, there are Python modules and libraries that make it even easier to create games, but this is the "real world" complexity level when creating user interfaces and applications in Python. As PySDL2 documentation shows, it is much more oriented towards game development, and has its own internal approach and model as to how game mechanics (sprites, et cetera) should be constructed.
However, both firmly use event-based programming model, the main difference being that with SDL2 the programmer is in control of the event loop, whereas in Qt5 (and basically in all windowing toolkits like Gtk, FLTK, etc.) the toolkit is in charge, and you just write the code responding to the events.
To additionally interface to microcontrollers, I recommend using a separate Python thread (or two); or a separate process, if there is a significant amount of data (more than full-speed USB, 12 Mbit/s) or processing (like FFTs or such) involved.
Nominal Animal:
An aside, since it WILL come up with anyone teaching kids to manipulate sprite-like images:
Qt and other widget toolkits cannot detect when partially transparent SVG or PNG images overlap. The solution for that is to subclass QPixmap (or whatever widget you use to represent stuff on-screen, often QLabels or QGraphicsItem), and add hitbox support. One can then check if they overlap or intersect, by checking if their hitboxes intersect. In most cases, hitboxes are either axis-aligned rectangles, or circles, defined in the SVG or PNG (pixel) coordinates (important!). It is simplest to use either rectangles OR circles, because rectangle-rectangle and circle-circle intersections are trivial, but rectangle-circle intersection is a bit tricky, especially if the rectangle is large compared to the circle. However, Qt also provides QPolygon or QPolygonF classes with .intersects() method, that will tell you if two polygons intersect. If you define their coordinates in the SVG or PNG pixel units, that gives very detailed hitboxes. On the other hand, (collections of) circular hitboxes can also do directional reflections, which is neat if you have e.g. a bulletproof character and want the bullets to just ping off.
One good approach to create sprite-like animated objects in Python is to use Python's built-in configparser to describe the images (animation) and hitboxes in a plain text INI-type file. Create a library class, initialized by specifying the path to an ini file, and have it load the images and information, and create a library of the aforementioned subclassed widgets. The library itself only needs a simple list() and get(name) interface. Depending on the game, you can add structure to the library, for example each character direction having their own animations, et cetera.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version