โŒ

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

How do I rotate a widget in kivy with the mouse

I'm trying to create a rectangle in kivy that follows my mouse so that the top (short side) of the rectangle is always perpendicular to the line between the rectangle and my mouse.

I have not been able to try anything since I know not very much about Kivy.

Full Code:

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.graphics import Color, Rectangle
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.core.audio import SoundLoader
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.image import Image
from kivy.config import Config 
from kivy.graphics import *
from kivy.utils import *

class Myapp(Widget):
    Config.set('graphics', 'resizable', True) 
    def __init__(self, **kwargs):
        super(Myapp, self).__init__(**kwargs)
        
    sound = SoundLoader.load('theme.mp3')
    sound.play()

class MenuScreen(Screen):
    pass

class Game(Screen, Widget):
    def __init__(self, **kwargs):
        super(Game, self).__init__(**kwargs)

        Config.set('graphics', 'resizable', True) 

        with self.canvas:
            Color(0, 0, 0)
            Rectangle(pos=(10, 10), size=(150, 50))

class Myapp(ScreenManager):
    pass

class MyApp(App):
    def build(self):
        return Myapp()

if __name__ == '__main__':
    MyApp().run()

Full description of what I am trying to do: After an initial starting screen, I click the start button to go to the main place. In this place, for now, I need to have a rectangle that follows the movement of my mouse.

REVIEW: Dictionary of Fine Distinctions: Nuances, Niceties, and Subtle Shades of Meaning by Eli Burnstein

Whatโ€™s the difference between mazes and labyrinths? Proverbs and adages? Clementines and tangerines? Join author Eli Burnstein on a hairsplitterโ€™s odyssey into the world of the ultra-subtle with Dictionary of Fine Distinctions. Illustrated by New Yorker cartoonist Liana Finck, this humorous dictionary takes a neurotic, brain-tickling plunge into the infinite (and infinitesimal) nuances that make up our world.

The perfect gift for book lovers, word nerds, trivia geeks, and everyday readers, this illustrated gem is more than just a bookโ€”it is an indispensable resource akin to a thesaurus but filled with charm and wit. Each entry, from โ€œlatte vs. flat whiteโ€ to โ€œGreat Britain vs. The United Kingdom,โ€ is accompanied by mnemonic aids, quirky asides, and detailed illustrations, making it a standout dictionary for any bibliophile or language enthusiastโ€™s library.

Review

This looked entertaining and since Iโ€™ve enjoyed a number of books dealing with words and what we do with them, I asked to review it. The blurb correctly leads one to believe that the distinctions between the terms covered will be, in most cases, small and I found this to be the case. I amused myself by glancing at the word pairings and seeing if I could mentally distinguish between them before reading what Burnstein had to say about them. I did okay on my own but did learn some things that, frankly, Iโ€™m not sure Iโ€™ll retain. Burnstein also said that for many of these pairs, the distinctions are being lost so this book is probably aimed at those who are curious or those who want to be pedants.

The book is filled with line drawings to illustrate differences but these are rather hit or miss as to usefulness. And despite being over 200 pages, itโ€™s a quick read. The words chosen to examine varied from common to vanishingly specific. There is little to no organization that I noticed so readers can fill a free moment or two without fear of losing their place. Here are some (abbreviated) examples of what you can find discussed.

Ethics vs morality โ€“ โ€ฆ why an immoral act sounds graver than an unethical one: One may get you fired, but the other could land you in hell.

Snitch = tattletale and a rat = traitor

Amp vs. Volt vs. Watt โ€“ In short, when you hear amps, think current, when you hear volts, think pressure, and when you hear watts, think utility bill.

AWD vs 4WD โ€“ One is safe and sophisticated. The other, rugged and badass.

Parable vs fable โ€“ A parable is a brief tale with a moral lesson. A fable is a brief tale with a moral lesson โ€“ plus animals.

I had fun reading it but it is more entertainment rather than a reference to be returned to. B-

~Jayne

AmazonBNKoboBook DepositoryGoogle

Finding the Smallest Language Class containing a given language definition

Given two regular languages L1 and L2 over alphabet ฮฃ, we define the operator RQ(L1, L2) = {w | there exists a word v in L2 such that wv is in L1}. The task is to determine the smallest language class among Regular, LL, CFG, and DCFG that certainly contains RQ(L1, L2).

So, I started with the most restricted of the languages I mentioned, which is Regular. But the problem is that I don't really have a formal or actual definition of RQ, or L1 and L2 for that matter. The only thing I know is that L1 & L2 are regular and then I know the definition of RQ. So, how can I use the pumping lemma or DFA without the expression for RQ to for example prove or disprove that it is a regular language?

What I need help with is grasping the problem, and maybe assistance in making the question less abstract if possible, because I just can't wrap my head around it right now.

Thanks beforehand!

How to make object collision in python kivy?

I want to create a Luckman breed of Pac-Man for Android for phones and tablets. But I can't make a collision for the labyrinth.

I tried to do it as in these files https://drive.google.com/file/d/1pwCDpU1UPzB7V7TV7-WmbyDLkpIDODry/view. But due to the fact that my labyrinth is located not as a picture but as a drawn object in the .kv file, nothing happened.

Here is my program code main.py

from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.uix.widget import Widget
from kivy.uix.anchorlayout import AnchorLayout

from player import *
from kivy.clock import Clock

from kivy.core.window import Window

class GamePlay(Screen):
    width = Window.width
    height = Window.height

    pacman = Player()

    def __init__(self, **kwargs):
        super(GamePlay,self).__init__(**kwargs)

    def on_touch_down(self, touch):
        self.start_pos = touch.pos
        return True

    def on_touch_move(self, touch):
        # Calculate swipe distance and direction
        swipe_distance_x = abs(touch.pos[0] - self.start_pos[0])
        swipe_distance_y = abs(touch.pos[1] - self.start_pos[1])
        swipe_threshold = 50  # Adjust threshold based on your needs

        # Detect swipe directions
        if swipe_distance_y > swipe_threshold:
            if touch.pos[1] > self.start_pos[1]:
                self.pacman.velocity = (0, 1)
                self.pacman.number_update_pac_img = "up"
            else:
                self.pacman.velocity = (0, -1)
                self.pacman.number_update_pac_img = "down"
        elif swipe_distance_x > swipe_threshold:
            if touch.pos[0] > self.start_pos[0]:
                self.pacman.velocity = (1, 0)
                self.pacman.number_update_pac_img = "right"
            else:
                self.pacman.velocity = (-1, 0)
                self.pacman.number_update_pac_img = "left"

        return True

    def update(self, dt):
        self.pacman.move()

class LuckmanApp(App):
    def build(self):
        game = GamePlay()
        Clock.schedule_interval(game.update, 1.0/60.0)

        return game

if __name__ == '__main__':
    LuckmanApp().run()

luckman.kv

<Player>:
    Image:
        id: "pacman"
        source: root.pac_img
        allow_stretch: True
        pos: root.pos
        size: self.parent.width / 18, self.parent.height / 18

<GamePlay>:
    canvas:
        Rectangle:
            source: "png/bg.png"
            size: self.size
    
    pacman: pacman_player

    FloatLayout:
        # ะ’ะตั€ั…ะฝะธะน ะฒั…ะพะด
        canvas:
            Color:
                rgb: [0, 0, 1]
            # ะ’ะตั€ั…ะฝะธะน ะฒั…ะพะด - ะฟั€ะฐะฒะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 1.79, self.height
                size: self.width / -43.2, self.height / -6
            # ะ’ะตั€ั…ะฝะธะน ะฒั…ะพะด - ะปะตะฒะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 2.274, self.height
                size: self.width / 43.2, self.height / -6
            # ะ’ะตั€ั…ะฝะธะน ะปะตะฒั‹ะน ะบะฒะฐะดั€ะฐั‚ ัั‚ะตะฝะพะบ
            Rectangle:
                pos: self.width / 2.274, self.height / 1.2
                size: self.width / -15, self.height / 96
            Rectangle:
                pos: self.width / 2.52, self.height / 1.2
                size: self.width / -43.2, self.height / 8
            Rectangle:
                pos: self.width / 2.52, self.height / 1.055
                size: self.width / -2.85, self.height / 96
            Rectangle:
                pos: self.width / 15, self.height / 1.0444
                size: self.width / -43.2, self.height / -4.7
            Rectangle:
                pos: self.width / 23.1, self.height / 1.34
                size: self.width / 7.3, self.height / -96
            Rectangle:
                pos: self.width / 2.6, self.height / 1.34
                size: self.width / -7.7, self.height / -96
            Rectangle:
                pos: self.width / 2.68, self.height / 1.359
                size: self.width / 11, self.height / 16.2
            # ะ’ะตั€ั…ะฝะธะน ะปะตะฒั‹ะน ัั€ะตะดะฝะธะน ะบะฒะฐะดั€ะฐั‚ 
            Rectangle:
                pos: self.width / 7.29, self.height / 1.0948
                size: self.width / 22, self.height / -7.6
            Rectangle:
                pos: self.width / 3.92, self.height / 1.0948
                size: self.width / 22, self.height / -7.6

            # ะ’ะตั€ั…ะฝะธะน ะฟั€ะฐะฒั‹ะน ะบะฒะฐะดั€ะฐั‚ ัั‚ะตะฝะพะบ
            Rectangle:
                pos: self.width / 1.8, self.height / 1.2
                size: self.width / 15, self.height / 96
            Rectangle:
                pos: self.width / 1.631, self.height / 1.2
                size: self.width / 43.2, self.height / 8
            Rectangle:
                pos: self.width / 1.631, self.height / 1.055
                size: self.width / 2.85, self.height / 96
            Rectangle:
                pos: self.width / 1.06, self.height / 1.0444
                size: self.width / 43.2, self.height / -4.7
            Rectangle:
                pos: self.width / 1.035, self.height / 1.34
                size: self.width / -7.3, self.height / -96
            Rectangle:
                pos: self.width / 1.6043, self.height / 1.34
                size: self.width / 7.7, self.height / -96
            Rectangle:
                pos: self.width / 1.57, self.height / 1.359
                size: self.width / -10, self.height / 16.2
            # ะ’ะตั€ั…ะฝะธะน ะฟั€ะฐะฒั‹ะน  ัั€ะตะดะฝะธะน ะบะฒะฐะดั€ะฐั‚ 
            Rectangle:
                pos: self.width / 1.207, self.height / 1.0948
                size: self.width / 22, self.height / -7.6
            Rectangle:
                pos: self.width / 1.324, self.height / 1.0948
                size: self.width / -22, self.height / -7.6


            # ะะธะถะฝะธะน ะฒั…ะพะด - ะฟั€ะฐะฒะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 1.79, self.height * 0
                size: self.width / -43.2, self.height / 6
            # ะะธะถะฝะธะน ะฒั…ะพะด - ะปะตะฒะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 2.274, self.height * 0
                size: self.width / 43.2, self.height / 6
            # ะะธะถะฝะธะน ะปะตะฒั‹ะน ะบะฒะฐะดั€ะฐั‚ ัั‚ะตะฝะพะบ
            Rectangle:
                pos: self.width / 2.274, self.height / 6.4
                size: self.width / -15, self.height / 96
            Rectangle:
                pos: self.width / 2.52, self.height / 6
                size: self.width / -43.2, self.height / -8
            Rectangle:
                pos: self.width / 2.52, self.height / 24
                size: self.width / -2.85, self.height / 96
            Rectangle:
                pos: self.width / 15, self.height / 24
                size: self.width / -43.2, self.height / 4.7
            Rectangle:
                pos: self.width / 23.1, self.height / 3.8
                size: self.width / 7.25, self.height / -96
            Rectangle:
                pos: self.width / 2.6, self.height / 3.8
                size: self.width / -7.7, self.height / -96
            Rectangle:
                pos: self.width / 2.68, self.height / 3.8
                size: self.width / 11, self.height / -16.2
            #ะะธะถะฝะธะน ะ›ะตะฒั‹ะน ัั€ะตะดะฝะธะน ะบะฒะฐะดั€ะฐั‚ 
            Rectangle:
                pos: self.width / 7.29, self.height / 4.61
                size: self.width / 22, self.height / -7.6
            Rectangle:
                pos: self.width / 3.92, self.height / 4.61
                size: self.width / 22, self.height / -7.6

            # ะะธะถะฝะธะน ะฟั€ะฐะฒั‹ะน ะบะฒะฐะดั€ะฐั‚ ัั‚ะตะฝะพะบ
            Rectangle:
                pos: self.width / 1.8, self.height / 6.4
                size: self.width / 15, self.height / 96
            Rectangle:
                pos: self.width / 1.631, self.height / 6
                size: self.width / 43.2, self.height / -8
            Rectangle:
                pos: self.width / 1.631, self.height / 24
                size: self.width / 2.85, self.height / 96
            Rectangle:
                pos: self.width / 1.06, self.height / 24
                size: self.width / 43.2, self.height / 4.7
            Rectangle:
                pos: self.width / 1.035, self.height / 3.8
                size: self.width / -7.25, self.height / -96
            Rectangle:
                pos: self.width / 1.6043, self.height / 3.8
                size: self.width / 7.6, self.height / -96
            Rectangle:
                id: stop
                pos: self.width / 1.57, self.height / 3.8
                size: self.width / -10, self.height / -16.2
            #ะะธะถะฝะธะน ะฟั€ะฐะฒั‹ะน ัั€ะตะดะฝะธะน ะบะฒะฐะดั€ะฐั‚ 
            Rectangle:
                pos: self.width / 1.207, self.height / 4.61
                size: self.width / 22, self.height / -7.6
            Rectangle:
                pos: self.width / 1.324, self.height / 4.61
                size: self.width / -22, self.height / -7.6


            #ะฆะตะฝั‚ั€ะฐะปัŒะฝั‹ะต ัั‚ะพั€ะพะฝั‹

            #ะฆะตะฝั‚ั€ะฐะปัŒะฝะฐั ะปะตะฒะฐั ะณะพั€ะธะทะพะฝั‚ะฐะปัŒะฝะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 6.31, self.height / 1.34
                size: self.width / 43.2, self.height / -2.05

            #ะฆะตะฝั‚ั€ะฐะปัŒะฝะฐั ะฟั€ะฐะฒะฐั ะณะพั€ะธะทะพะฝั‚ะฐะปัŒะฝะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 1.208, self.height / 1.34
                size: self.width / 43.2, self.height / -2.05
            
            #ะฆะตะฝั‚ะฐะปัŒะฝะฐั ะฒะตั€ั…ะฝัั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 3.92, self.height / 1.43
                size: self.width / 2., self.height / -96

            #ะฆะตะฝั‚ั€ ัะฟะฐะฒะฝะฐ ะฟั€ะธะทั€ะฐะบะพะฒ
            Rectangle:
                pos: self.width / 2.68, self.height / 1.555
                size: self.width / 11, self.height / 96
            Rectangle:
                pos: self.width / 1.57, self.height / 1.555
                size: self.width / -10, self.height / 96
            Rectangle:
                pos: self.width / 2.68, self.height / 1.65
                size: self.width / 43.2, self.height / 27
            Rectangle:
                pos: self.width / 1.57, self.height / 1.65
                size: self.width / -43.2, self.height / 27
            Rectangle:
                pos: self.width / 2.68, self.height / 1.65
                size: self.width / 3.79, self.height / -96
                
            #ะฆะตะฝั‚ะฐะปัŒะฝะฐั ัั€ะตะดะฝัั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 3.92, self.height / 1.786
                size: self.width / 2, self.height / -96
                
            #ะฆะตะฝั‚ั€ะฐะปัŒะฝะฐั ะฟั€ะฐะฒะฐั ะฒะตั€ั‚ะตะบะฐะปัŒะฝะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 1.324, self.height / 1.68
                size: self.width / -22, self.height / 17.5
            #ะฆะตะฝั‚ั€ะฐะปัŒะฝะฐั ะปะตะฒะฐั ะฒะตั€ั‚ะตะบะฐะปัŒะฝะฐั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 3.92, self.height / 1.68
                size: self.width / 22, self.height / 17.5
                
            #ะฆะตะฝั‚ะฐะปัŒะฝะฐั ะปะตะฒะฐั ะฝะธะถะฝัั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 6.31, self.height / 1.945
                size: self.width / 3.25, self.height / -96
            #ะฆะตะฝั‚ะฐะปัŒะฝัั ะฟั€ะฐะฒะฐั ะฝะธะถะฝัั ัั‚ะตะฝะบะฐ
            Rectangle:
                pos: self.width / 1.208, self.height / 1.945
                size: self.width / -3.5, self.height / -96
            #ะฆะตะฝั‚ั€ะฐะปัŒะฝะธะน ะฝะธะถะฝะธะน ะบะฒะฐะดั€ะฐั‚
            Rectangle:
                pos: self.width / 3.92, self.height / 3.8
                size: self.width / 2, self.height / 4.85

        Player:
            id: pacman_player
            pos: self.width / 2.13, self.height / 5.7

player.py

from kivy.uix.widget import Widget
from kivy.properties import StringProperty, NumericProperty, ReferenceListProperty
from kivy.vector import Vector

class Player(Widget):    
    pac_img = StringProperty("png/pacman/pacman_down.gif")

    number_update_pac_img = "None"

    velocity_x = NumericProperty(0)
    velocity_y = NumericProperty(0)
    velocity = ReferenceListProperty(velocity_x, velocity_y)

    def move(self):
        self.pos = Vector(*self.velocity) + self.pos

        #update pacman gifts
        if self.number_update_pac_img == "up":
            self.pac_img = "png/pacman/pacman_up.gif"
        if self.number_update_pac_img == "down":
            self.pac_img = "png/pacman/pacman_down.gif"
        if self.number_update_pac_img == "left":
            self.pac_img = "png/pacman/pacman_left.gif"
        if self.number_update_pac_img == "right":
            self.pac_img = "png/pacman/pacman_right.gif"

Links: Public Library Awesomeness, Fic Organizing, & More

Workspace with computer, journal, books, coffee, and glasses.Welcome back to Wednesday Links!

The Boston spring has devolved back into a Boston winter this week. Typical! I donโ€™t really mind the cold so much; itโ€™s the wind. The wind is so brutal sometimes.

My partner recently made a Trader Joeโ€™s run and TJs is so good for fun and interesting snacks. But I have a gripe. Theyโ€™re so popular and I get very overwhelmed and overstimulated in crowded areas. I want to browse, but I feel like I cannot do that before I need to run screaming out the building. My partnerโ€™s brother works at a TJs and heโ€™s been very helpful in giving me some ideal โ€œdown timesโ€ to try and shop.

Any Trader Joeโ€™s disciples in the house? Iโ€™d love to hear about some of your favorite TJs go-to foods!

โ€ฆ

The greater Boston area is getting a romance bookstore! No news yet on its opening, but Iโ€™m excited. Lovestruck Books, if you ever want a moderator for events, Iโ€™m in the neighborhood!

โ€ฆ

A colleague at work told me about this article on A.I. art pushing the limits of happy puppies and silly geese. I think I was able to grab a gift link for it. They also reference this Twitter thread.

โ€ฆ

I havenโ€™t been shy about my fanfic preferences, which have included Dramione. I saw this post on reddit about a person organizing their favorite fics, which led to some great discussion in the comments about how people do this for themselves.

So how do you keep track or organize your fanfic TBR pile?

โ€ฆ

As Iโ€™ve been preparing for my trip to Korea, Iโ€™ve been doing some language learning. A friend recommended Mango Languages to me and told me she gets her lessons through our public library system! Does your library have language learning resources? Have you tried Mango Languages?

โ€ฆ

Donโ€™t forget to share what cool or interesting things youโ€™ve seen, read, or listened to this week! And if you have anything you think weโ€™d like to post on a future Wednesday Links,ย send itย my way!

โŒ
โŒ