is there any way to create a game were there are two background colors where one square is smaller than the other. In the background, I am thinking of being able to place buttons and so on. I have a game that works fine but I would like to develop it. As I have no knowledge about how to do, I have not tried it.
Pygame won't allow you to have more than one screen per application, if that is what you are asking. You can check the pyglet library for that: http://pyglet.org/ -
I can't figure out if you have any further doubts from your text, however - you will have to be more specific.
If it is about having a sub-section of the window as the action area of the game, and an outer margin where to to place controls, yes, that is just straightforward drawing with the provided calls.
Related
Let me make my question more clear. I am making a program where the program simulates a certain set of keypresses in a video game when a certain 'graphic' fully 'charges' up. This graphic is basically a vertical bar that fills up all the way to the top. How can I use python to interpret this graphic and return some info when the bar is visually fully charged up. The position of the graphic on the screen is always consistent and the state of the bar when it is indeed fully charged up, is always the same.
Probably the easiest way to achieve that is to use the ImageGrab module from Pillow.
And then use some pixels in the snapshot to determine if the bar is filling.
Pillow docs - https://pillow.readthedocs.io/en/3.0.x/reference/ImageGrab.html
so im building a simple paint program in python as a project, using Pygame it works by basically drawing a stream of circles when the mouse gets pressed and you drag it around the surface, its got a couple other little things going on but the thing i wanna ask is, is there a way to change the singular mouse input you know mouse.get_pressed to either multiple mouse inputs at one time or a multi-touch input into the point list that's streaming the circles.
running= True
while running:
if buttons[0] == True:
x,y = pygame.mouse.get_pos()
if x> PA+AS:
xShift = x - PA - AS
pygame.draw.circle(pArea,DRAW_CLR,(xShift,y),BRUSHSIZE)
pygame.display.flip()
so this is the part of the code i really want to change more or less. just so that instead of just one mouse, i could use my touchscreen to draw with maybe two finger
Latest versions of pygame support multitouch input (and I believe also gestures).
The events which control it are pygame.FINGERDOWN, .FINGERUP and .FINGERMOTION. My understanding is that they work like mouse inputs, but can be multiple and can be distinguished by means of an event.finger_id property.
An example can be found here:
https://www.patreon.com/posts/finger-painting-43786073?l=fr
You're going to have a difficult time if you insist on doing this in PyGame. Your best bet for multitouch in Python is Kivy, which was a very solid framework a few years ago when I used it and appears to have only gotten better since.
The disadvantage of switching to Kivy is a more complicated API, but this tutorial seems spot-on for what you're trying to do.
This question already has answers here:
simple animation using tkinter
(2 answers)
Closed 6 years ago.
In Python 2.7, I want to display some simple graphics, such as a red square moving around on a blue window. On every frame, I want to update the position of the square, and render the new window. I am looking for something simple and lightweight.
I have seen people use matplotlib for drawing shapes, but I don't want to have to deal with axes and data points. I have also seen pygame suggested, but this seems to heavyweight for what I want, as I do not want to create a game, just a simple animation.
So what I really want is something where on every frame, I just indicate the colour of every pixel on an image, and then display that image. What are some good suggestions?
Tkinter is not good for setting individual pixels. If you want to move rectangles or ovals though (a small oval will look like a pixel, but it doesn't scale for updating a whole image).
def update(x,y):
canvas.delete('all')
canvas.create_rectangle(x-1,y-1,x+1,y+1)
You can, of course, be more judicious, saving the return value of the rectangle and then only clear the appropriate elements. Or you can move existing elements directly as Bryan points out. As he explains elsewhere Tkinter of course, supports drawing images, ovals, and a slew of other things. Here's a canonical source edit: that is old and not canoncial This one's slightly better For a general source on animating with a timer loop, here's Bryan agian
Bryan also noted that you can work with pixels directly You can do that with PhotoImage.
Array-Like Pixel Access Without Graphical Extensions
A robust module like pygame will be the most scalable option. However, I've had success (in educational settings only) writing graphics engines by modifying the elements of a numpy array and then displaying it as an image (you also need this link to display the images).
This lets you do pixel level modifications; since it's relatively trivial to write C-extensions that modify numpy arrays, you can prototype fast image processing doing custom manipulations. While I've written whole graphics engines using just tkinter this way, again I can only reccomend it for educational purposes.
Otherwise, just bite the bullet and pull in openGl or pygame. You'll save yourself a ton of time in the long run.
Summary
Very simple animations can be done right in tkinter
For educational purposes, you can do arbitrary graphics with numpy and tkinter
For rhobust animations, check out a full library (openGl, matplotlib, pygame) that suits your needs (graphical rendering, statistical graphing, game development, etc.)
The Widget collide_points allows to identify if an event that occurs inside a widget.
I know that one approach used in the Pong Game example is putting the vertex instructions that we want to collide inside a Widget. In the Pong Example the ball is a Widget that has an Ellipse in its canvas. The problem with the this approach is that internally the ball is actually a rectangle (not an issue for this particular game).
I was wondering if there is any implementation that indicates if a coordinate (x,y) is inside a particular Vertex Instruction.
I know there are some maths involved so I don't really expect Kivy handling this yet. However, I guess any other library could help me.
There isn't something like this in Kivy, but you should check out some of the examples that are bundled in Kivy. There is one called customcollide that implements "Custom shape & collide widget".
I wanted to know if anyone knew where to start in terms of recreating this sort of functionality?
http://www.learningnuke.com/wp-content/uploads/nukewipepreview.png
In the picture you can drag the centre line to reveal Image A or Image B or parts of each, interactively.
I want to be able to wipe/reveal across two images, maybe it's possible doing some sort of interactive crop of sorts.
Wanting to add this feature to a window in Maya, so maybe with QT, but not essential.
Just some pointers would be great.
I can tell you that this is possible via Qt/PyQt in maya. You can create a dialog that displays QPixmaps with some form of mouse interaction to control their display. I would forget about trying to extend the actual Render View as this would be a pain in the ass.
Just focus on a Qt solution. Unfortunately beyond this, I'm not sure what more I can offer unless you have a specific question about its implementation.
I would probably stack the QPixmaps on top of each other inside of custom QLabel widgets. The QLabel would have a custom mousepress/move event that would resize maybe the right edge to simulate the wipe effect, and reveal the one stacked underneath.
Also, it does resemble the functionality of a QSplitter so that might also work, with an image on each side of the layout and a custom style to the split bar.