Drawing graphics for LCDs - python

Im not sure if this is the correct place to ask this but as its more programming related than electronics I am posting here.
I have recently purchased a small LCD to experiment with. Its just one colour. Im using python to control it over serial.
My question is when it comes to the actual drawing. This whole area is completely new to me so I don't know if I am thinking the right way / going down the right path.
I want to be able to draw things on the LCD such as progress bars, animations (such as volume meters etc) and other simple - non text - based things. Just anything really.
In my mind the way I imagine doing this is by using python to draw a complete image of what I want on the LCD. Using PIL / Pillow for example and constantly redrawing and resending to the LCD.
So in the case of the progress bar, everything that's static is the same but then the progress bar rectangle for example would have its width altered each redraw.
I dont know if this it the correct way or if there are better ways or even if there are specific tools / modules for this kind of thing.

Related

Is there a way to draw in the "background" using turtle?

Is there a way to have an image be created/drawn entirely without the actual Window that usually pops up when starting a turtle script showing up? The reason for this question is that while doing more research into another problem I posted here:
How to properly interact with turtle canvas/screen sizing?
I found that resizing the screen using maximize on the window actually altered what was capture when using .getcanvas() to be saved.
This wouldn't be a problem if I weren't attempting to create large images, larger than my monitors certainly. (around 15000 x 15000 pixels).
Thus I am wondering if there is a way to have the entire drawing process be done in the background. Without a window popping up at all. This way (I would hope at least) my images aren't becoming distorted or incorrectly sized due to buggy window interactions. As an example when I try to create an image this big, even with turtle.tracer(False) set it still flashes for a small amount of time (as the images are large and take time to complete) and while it is 'open' I cannot switch to it, it does not appear on my screen, it only appears on the task bar, which I can hover over and like with other applications 'preview' it without clicking on it, and it does not show there. However the image will be created and saved. But the dimensions are entirely wrong based on the code I used.
For a minimally repeatable example please look to the hyperlink to my related question. The code and subsequent image of that post is directly related to this question. But as the questions are different in nature I decided to create this post asking it.
Any feedback would be greatly appreciated as I cannot find any information in the documentation on how this might be done if it is possible at all. If anyone knows any good resources to directly contact regarding Turtle then that information would be welcomed as well.
I'm not sure if this will help to much but if you set the turtles speed to 0 then there will be no animation and the turtle will draw the picture instantly.
The code would look something like: turtle.speed(0)

Creating a "Fill" command in tk inter

I am pretty new to Python and coding in general. I have been working on a program that is similar in nature to ms paint. So far, I've added the capabilities to create multi-colored rectangles, lines, ovals, and really any polygon.
I've been using the tkinter GUI. I've been wanting to add a fill command, but I'm kind of stuck as to how to start it. My idea for how it would work would be that it would check the color of the pixel the user is currently hovering over, then check up, down, left, and right for the same color in pixels. If it found that, it would change the color of those pixels (I guess by creating a really small rectangle object?). This would theoretically be able to fill an area. But, I really can't find anything on how to access the color of a pixel in tkinter.
I know the location is event.x and event.y for a specific event, but I can't find anything about pixel color. I don't really have any code written for it yet because I am unsure that tkinter can even access the color of a pixel and not just object colors.
Unfortunately, this isn't possible. I did some searching around, and found several other similar questions, but the general idea is that Tkinter does not support such a feature. It makes sense, considering that Tkinter is a GUI library.
I saw a suggestion somewhere, where an idea was proposed to create 1x1 rectangles using the Tkinter Canvas to basically mimic pixels. However, this method eventually leads into performance issues and lagging, so it's not really recommended either.
You may want to try exploring some other libraries to work together with Tkinter. You can keep the Tkinter GUI, but use an image manipulation library or something similar which integrates well with Tkinter, for the actual pixel drawing.

Is there a way to make the python-vlc window acknowledge cropping?

I want to play a video using python-vlc. I have gotten everything to work, and the video plays without any technical issues. There is this one aesthetic issue, though. I only want to play part of the video. As in, I want to crop out a fair bit on the bottom and a good bit on the right. I know I can do this with a call to MediaPlayer.video_set_crop_geometry(), and I've done so semi-successfully. However, the actual window that opens is the one that is adjusted for the entire video, with the part that I want centered in the middle with black bars around it. (If I call MediaPlayer.video_set_scale(), then the cropped-out bit the same size as it would be if I didn't crop. If I don't call video_set_scale(), the cropped-out bit is stretched, maintaining aspect ratio, until it reaches the edge of the window. Regardless, there are black bars).
Can I get the window to adjust to this new, smaller video? Preferably automatically, but if I have to pass in the size I want, that's fine too.
I have tried shuffling around the order between the different calls to no avail. Clearly python-vlc has the capacity somewhere to adjust the window it's playing in, as it can open a window the correct size for the regular video to play, and it adjusts automaticallty after calling video_set_scale(), but only to fit the original video, not the cropped one.
You should probably share more details, such as your full code and platform used.
That being said, libvlc doesn't offer an API to resize the native Window it draws on, but you can easily do it yourself (with win32 APIs for HWND, on Windows, for example).

How to create a picture with animated aspects programmatically

Background
I have been asked by a client to create a picture of the world which has animated arrows/rays that come from one part of the world to another.
The rays will be randomized, will represent a transaction, will fade out after they happen and will increase in frequency as time goes on. The rays will start in one country's boundary and end in another's. As each animated transaction happens a continuously updating sum of the amounts of all the transactions will be shown at the bottom of the image. The amounts of the individual transactions will be randomized. There will also be a year showing on the image that will increment every n seconds.
The randomization, summation and incrementing are not a problem for me, but I am at a loss as to how to approach the animation of the arrows/rays.
My question is what is the best way to do this? What frameworks/libraries are best suited for this job?
I am most fluent in python so python suggestions are most easy for me, but I am open to any elegant way to do this.
The client will present this as a slide in a presentation in a windows machine.
The client will present this as a slide in a presentation in a windows machine
I think this is the key to your answer. Before going to a 3d implementation and writing all the code in the world to create this feature, you need to look at the presentation software. Chances are, your options will boil down to two things:
Animated Gif
Custom Presentation Scripts
Obviously, an animated gif is not ideal due to the fact that it repeats when it is done rendering, and to make it last a long time would make a large gif.
Custom Presentation Scripts would probably be the other way to allow him to bring it up in a presentation without running any side-programs, or doing anything strange. I'm not sure which presentation application is the target, but this could be valuable information.
He sounds like he's more non-technical and requesting something he doesn't realize will be difficult. I think you should come up with some options, explain the difficulty in implementing them, and suggest another solution that falls into the 'bang for your buck' range.
If you are adventurous use OpenGL :)
You can draw bezier curves in 3d space on top of a textured plane (earth map), you can specify a thickness for them and you can draw a point (small cone) at the end. It's easy and it looks nice, problem is learning the basics of OpenGL if you haven't used it before but that would be fun and probably useful if your in to programing graphics.
You can use OpenGL from python either with pyopengl or pyglet.
If you make the animation this way you can capture it to an avi file (using camtasia or something similar) that can be put onto a presentation slide.
It depends largely on the effort you want to expend on this, but the basic outline of an easy way. Would be to load an image of an arrow, and use a drawing library to color and rotate it in the direction you want to point(or draw it using shapes/curves).
Finally to actually animate it interpolate between the coordinates based on time.
If its just for a presentation though, I would use Macromedia Flash, or a similar animation program.(would do the same as above but you don't need to program anything)

How do I track an animated object in Python?

I want to automate playing a video game with Python. I want to write a script that can grab the screen image, diff it with the next frame and track an object to click on. What libraries would be useful for this other than PIL?
There are a few options here. The brute force diff'ing approach will lead to a lot of frustration unless what you're tracking is very consistent. For this you could use any number of genetic approaches to train your program what to follow. After enough generations it would do the right thing reliably. If the thing you want to track is visually obvious (like a red ball on a white screen) then you could detect it yourself through simple brute force scanning of the bitmap.
Another approach would be just looking at the memory of the running app, and figuring out what area is controlling the position of your object. For some more info and ideas on this, see how mumble got 3D positional audio working in various games.
http://mumble.sourceforge.net/HackPositionalAudio
Answer would depend on the platform and game too.
e.g. I did once similar things for helicopter flash game, as it was very simple 2d game with well defined colored maze
It was on widows with copy to clipboard and win32 key events using win32api bindings for python.

Categories