exporting python turtle drawing to video - python

Is there a way to export a python turtle drawing to a video?
The video should contain the real-time drawing process.
In particular I'm not interested in a screen-recording workaround, but a solution that would work in a headless system like a cloud environment.
Here's an example of a turtle drawing
import turtle
tr = turtle.Turtle()
rad = 80
tr.circle(rad)
turtle.done()

Related

Turtle pen too blurry

I'm making a platformer game with python turtle, the game not built for high graphics any way, the rendering created with pen, but I still want a way to make the pen less pixelated,
I tried a lot of things like using tkinter root.tk.call('tk', 'scaling', 2.0) and ctypes.windll.shcore.SetProcessDpiAwareness(1)
but it just don't work on the turtle pen graphics.
example:
from turtle import *
wn = Screen()
wn.colormode(255)
pen = Turtle()
pen.speed(0)
pen.ht()
pen.pu()
pen.pensize(15)
pen.pencolor(0, 255, 255)
pen.setpos(-150, -50)
pen.pd()
pen.setpos(150, 50)
wn.mainloop()
So that code draws a diagonal line, but as you can see it is too pixelated, and I guess it has resolution limit (not sure):
screen shot from the code up
screen shot of the life bar from my own game when using 1920x1080 resolution and it still seems like 720p not anti aliased
so if you know any way to do it, really thanks, if you can't find a way to do it through turtle or tkinter, or any other trusted module, I don't even care if I have to edit turtle for the solution.

HOW i can generate cubes random in pygame?

i need code
How can a randomly generated 3dcube using just pygame be created from the top of the screen and then fall from the top to the bottom of the screen
please help me
using python pygame
As mentioned by #The_spider , pygame is a 2D Game engine. It cannot load 3D files or do any 3D stuff. A few recommended modules would be Panda3d and Ursina(which is a simplified version of Panda3d) install them via pip.
If you really need to use pygame, you'll have to save an image of the cube at every angle and Blit it on the screen using an extremely complicated algorithm. Moreover, it will be extremely slow. Thus, use a python 3D game engine.

How can i rotate a specific screen with python?

Im trying to make a arduino based rotation of the monitor detection and i have a problem because i cannot find how to change a specific screen rotation.
My code:
import rotatescreen
screen = rotatescreen.get_primary_display()
screen.set_landscape()

how to zoom out on Turtle canvas?

How do I zoom out on the canvas so I'll be able to see everything that is drawn from the turtle in Python. As the name suggests, I use the Turtle from Python to draw a binary tree of certain strings. I could of course force the turtle to draw more narrowly, but then the leaves would be too close to each other. That's why I'm looking for an option to zoom out on the thee when the turtle is done with its drawings.
The screenshot below should show my frustration. As you can see, it is not possible for me to see the whole binary tree.
Have not included the whole code. But let me know if you want to see it. Here is a snippet though.
import turtle
turtle.screensize(5000, 3000)
t = turtle.Turtle()
t.hideturtle()
t.speed(0); turtle.delay(0)
h = height(root)
jumpto(0, 30*h)
draw(root, 0, 30*h, 40*h) #function to draw
t.hideturtle()
turtle.mainloop()

adding an image to the Turtle Screen

How can I add image to my Turtle Screen using turtle graphics?
whenever I use the function addshape I keep getting errors.
does turtle graphics got any other way loading/importing images?
for example:
import turtle
screen = turtle.Screen()
image = r"C:\Users\myUser\Desktop\Python\rocketship.png"
screen.addshape(image)
turtle.shape(image)
The turtle module does have support for images, but only GIF images, not PNG or any other format. As the docs for addshape say:
name is the name of a gif-file and shape is None: Install the corresponding image shape.
And if you look at the source, they're serious about "gif-file": the way it decides whether you're trying to add an image or a polygon is by calling data.lower().endswith(".gif"), which obviously won't work for .png files.
And, even if you fix that, it will still only be able to handle the file formats that Tkinter supports out of the box, which includes some extra things like PPM/PGM/PBM, but still not PNG. If you want to support PNG files, you'll want to install Pillow as well.
At this point, you're getting beyond what people usually do with turtle. That might be worth pursuing (you'll learn a lot by doing so), but it may be simpler to use an image-converting program to convert the .png file to a .gif file so it will work with your existing code.
You can only use gif files with Python Turtle. Take any picture and convert/resize for free at ezgif.com.
Background:
win = turtle.Screen()
win.bgpic('background.gif')
Using shapes:
win.register_shape('pic1.gif')
sprite = turtle.Turtle()
sprite.shape('pic1.gif')
Example game:
https://www.youtube.com/watch?v=q49Xyo0LYDs

Categories