Rotate vertical rectangle to horizontal rectangle using Python Kivy - how?


beginner

I'm trying to write a game in Python Kivy and am stuck on just one thing, it's going to be a simple problem, but I haven't found a solution anywhere.

I want the line in the middle of the screen (see attached image) to be horizontal instead of vertical, meaning left to right. Is there any way to rotate this? Or do I have to change something in the script?

Change vertical lines to horizontal lines

Here is my script to create the graph:

<PongGame>:
    canvas:
       Rectangle:
          pos:    self.center_x - 5, 0
          size: 10, self.height

I would appreciate any help. Remember, I'm still a beginner.

best regards,

beginner

John Anderson

A good way is to use kv, like this:

<PongGame>:
    rotate: False  # property to control rotation
    canvas:
        Rectangle:
            pos:  (0, self.center_y - 5) if self.rotate else (self.center_x - 5, 0)
            size: (self.width, 10) if self.rotate else (10, self.height)

This code defines the property ( rotate) that controls the rotation PongGame. If it rotateis False, Rectangledraw your original , but if it rotateis True, Rectangledraw the rotation . Similar results can be achieved with python code, but you have to write more code (bindings) to handle user changes PongGame. Do all this kvand let kivy handle those bindings.

Once you have this code, you can rotate it PongGameusing :

def rotate(self, dt):
    self.root.rotate = not self.root.rotate

in your PongApp.

Related


How to draw a simple line and a rectangle using Kivy in Python3?

Space Pirate Hack 54 I just want the program to draw a line and a rectangle in a window using Kivy. Location and properties don't matter for now. I'm new to Python, and new to Kivy, and I've never used a GUI before. I've tried searching on multiple sites but n

How to draw a simple line and a rectangle using Kivy in Python3?

Space Pirate Hack 54 I just want the program to draw a line and a rectangle in a window using Kivy. Location and properties don't matter for now. I'm new to Python, and new to Kivy, and I've never used a GUI before. I've tried searching on multiple sites but n

How to rotate rectangle in Libgdx?

Kevin Bryan I rotated the sprite 90 degrees and wanted to do the same with the rectangle to make it work for collisions, but that rotate()method doesn't work for rectangles. Here is what I did: treeSpr=new Sprite(new Texture(Gdx.files.internal("tree.png")));

How to rotate rectangle in Libgdx?

Kevin Bryan I rotated the sprite 90 degrees and wanted to do the same with the rectangle to make it work for collisions, but that rotate()method doesn't work for rectangles. This is what I did: treeSpr=new Sprite(new Texture(Gdx.files.internal("tree.png")));

How to rotate rectangle in Libgdx?

Kevin Bryan I rotated the sprite 90 degrees and wanted to do the same with the rectangle to make it work for collisions, but that rotate()method doesn't work for rectangles. Here is what I did: treeSpr=new Sprite(new Texture(Gdx.files.internal("tree.png")));

How to rotate rectangle in Libgdx?

Kevin Bryan I rotated the sprite 90 degrees and wanted to do the same with the rectangle to make it work for collisions, but that rotate()method doesn't work for rectangles. This is what I did: treeSpr=new Sprite(new Texture(Gdx.files.internal("tree.png")));

How to rotate a rectangle?

Joe Hot 200 I'm trying to rotate a (Java class) Rectanglecreated using Rectangle rect = new Rectangle(x, y, width, height); I can't seem to find anything in the API. If I google "Java rotate rectangle" I can only find threads that tell me how to rotate the dr

How to rotate rectangle in Libgdx?

Kevin Bryan I rotated the sprite 90 degrees and wanted to do the same with the rectangle to make it work for collisions, but that rotate()method doesn't work for rectangles. Here is what I did: treeSpr=new Sprite(new Texture(Gdx.files.internal("tree.png")));

How to rotate a rectangle?

Joe Hot 200 I'm trying to rotate a (Java class) Rectanglecreated using Rectangle rect = new Rectangle(x, y, width, height); I can't seem to find anything in the API. If I google "Java rotate rectangle" I can only find threads that tell me how to rotate the dr

How to align rectangle to parent center using Kivy

Phil Andrews I am trying to draw a border around it FloatLayout. To do this, I added two rectangles to the canvas, the second rectangle is slightly smaller than its parent's layout. This works. However, aligning the rectangle with the center of the canvas has

How to rotate a rectangle to point to the mouse

Rodney Ramsay Whenever the mouse moves, I need to rotate the rectangle to point to the help of the mouse on the screen. I've been trying to do this, using the onmousemove event and calculating the degrees/angles and then converting to radians, but for some rea

How do I scale a rectangle with Kivy using the mouse wheel?

nbout Using python and kivy, I want to translate (drag with the mouse) and use the mouse wheel to zoom in/out of the rectangle drawn in the canvas of the scatter widget. I am using ubuntu and kivy 1.11. from kivy.config import Config Config.set('input', 'mouse

How do I scale a rectangle with Kivy using the mouse wheel?

nbout Using python and kivy, I want to translate (drag with the mouse) and use the mouse wheel to zoom in/out of the rectangle drawn in the canvas of the scatter widget. I am using ubuntu and kivy 1.11. from kivy.config import Config Config.set('input', 'mouse

Using C# to rotate a rectangle relative to the rotated rectangle

cod wrench I have two rectangles: First parentrotate -15 degrees relative to the center of the canvas Next childrenrotate -15 degrees relative to the center of the canvas, and 5 degrees relative to the center of the canvas parent. Get the original image: The m

Using C# to rotate a rectangle relative to the rotated rectangle

cod wrench I have two rectangles: First parentrotate -15 degrees relative to the center of the canvas Next childrenrotate -15 degrees relative to the center of the canvas, and 5 degrees relative to the center of the canvas parent. Get the original image: The m

How to draw a blank rectangle on the screen using Python

Jose Chamorro I'm not an expert, I'm trying to display a rectangle on the screen that follows the movement of the mouse from a fixed point, as if you were selecting something in text or painting. I have the following code: import win32gui m=win32gui.GetCursorP

How to draw a blank rectangle on the screen using Python

Jose Chamorro I'm not an expert, I'm trying to display a rectangle on the screen that follows the movement of the mouse from a fixed point, as if you were selecting something in text or painting. I have the following code: import win32gui m=win32gui.GetCursorP

How to draw a blank rectangle on the screen using Python

Jose Chamorro I'm no expert, I'm trying to display a rectangle on the screen that follows the movement of the mouse from a fixed point, as if you were selecting something in text or painting. I have the following code: import win32gui m=win32gui.GetCursorPos()

How to draw a blank rectangle on the screen using Python

Jose Chamorro I'm no expert, I'm trying to display a rectangle on the screen that follows the movement of the mouse from a fixed point, as if you were selecting something in text or painting. I have the following code: import win32gui m=win32gui.GetCursorPos()

How to draw rectangle inside rectangle using svg?

Sakthisundar I'm trying to draw a rectangle inside a rectangle using svg and I don't see the inner rectangle. Can someone help me what I'm doing wrong? code show as below. <html> <body> <h1>My first SVG</h1> <svg width="700" height="200">

Python | Rotate rectangle and get new bounding dimensions

core tax So we get the rectangle and then rotate it by degrees Aaround its corners . Now, I want to know how to calculate the bounds of the rectangle . The boundaries (blue rectangles) mean:xnew The known values are the width/height/center/corners of the inner

Python | Rotate rectangle and get new bounding dimensions

core tax So we get the rectangle and then rotate it by degrees Aaround its corners . Now, I want to know how to calculate the bounds of the rectangle . The boundaries (blue rectangles) mean:xnew The known values are the width/height/center/corners of the inner

Python | Rotate rectangle and get new bounding dimensions

core tax So we get the rectangle and then rotate it by degrees Aaround its corners . Now, I want to know how to calculate the bounds of the rectangle . The boundaries (blue rectangles) mean:xnew The known values are the width/height/center/corners of the inner

Python | Rotate rectangle and get new bounding dimensions

core tax So we get the rectangle and then rotate it by degrees Aaround its corners . Now, I want to know how to calculate the bounds of the rectangle . The boundaries (blue rectangles) mean:xnew The known values are the width/height/center/corners of the inner

Python | Rotate rectangle and get new bounding dimensions

core tax So we get the rectangle and then rotate it by degrees Aaround its corners . Now, I want to know how to calculate the bounds of the rectangle . The boundaries (blue rectangles) mean:xnew The known values are the width/height/center/corners of the inner