Skip to main content

Posts

Python Pygame Physics Simulation Collison Not Working [duplicate]

I am trying to make a physics simulation using pygame but the collision is having problems. It gets shaky whenever there is a collision with another block because gravity is applied, but Rect collision only works when it is a pixel or more. I tried to make it so gravity = 0 for every block when it collides at a slow enough velocity, but that causes the blocks to hover due to certain collisions. Sorry for the whole file I do not even know where to start to fix my problem. import pygame import math # pygame setup pygame.init() screen = pygame.display.set_mode((1280, 720)) clock = pygame.time.Clock() running = True dt = 0 swap = 1 enemy_rect = pygame.Rect(500,500,20,20) objects= [[600,300,20,20,0,1.57,10,'blue',.2]] object=pygame.draw.rect(screen, 'blue', (600,300,20,20)) walls= [[0,700,1300,99999,0,0,99999]]#,[200,300,100,200]] while running: # poll for events # pygame.QUIT event means the user clicked X to close your window for event in pygame.event.get():...
Recent posts

Plot lines using vertices and faces in matplotlib

I would like to plot 2 circles with differents radius using matplotlib given their faces and vertices. This is my code to define the circles and to plot them. r2,r3=2,3 n_t3=5 n_t2=n_t2 theta_t3=torch.linspace(0,2*torch.pi,n_t3,device=torchdeviceId) VT3 = torch.stack((r3*torch.cos(theta_t3),r3*torch.sin(theta_t3)),dim=1) theta_t2=torch.linspace(0,2*torch.pi,n_t2,device=torchdeviceId) VT2 = torch.stack((r2*torch.cos(theta_t2),r2*torch.sin(theta_t2)),dim=1) VT=torch.vstack((VT2,VT3)) FT3 = torch.cat((torch.arange(0,n_t3-1).reshape(n_t3-1,1),torch.arange(1,n_t3).reshape(n_t3-1,1)),dim=1) FT2 = torch.cat((torch.arange(n_t3,n_t3+n_t2-1).reshape(n_t2-1,1),torch.arange(n_t3+1,n_t3+n_t2).reshape(n_t2-1,1)),dim=1) FT=torch.vstack((FT2,FT3)).to(torchdeviceId) xt, yt = ( VT[FT,0].detach().cpu().numpy(), VT[FT,1].detach().cpu().numpy(), ) plt.figure() plt.plot(xt,yt,label='target',marker='x',markersize=10,alpha=0.2,lw=10); plt.show() But i have this weird result whe...

discord embed freezes on 2nd execution

I have a problem with a slash command, with an embed actually. When I run the slash command, I get an embed with a button with a label "xN" (where N - any number from 1 to 99). This embed gets edited every 2 seconds, and the button's label and id increase by 1. If I click the button, callback function is called, some logic gets executed in the callback function and the main function stops. And it all works as intended, until 2nd try and all the following. On 2nd try the embed just stops, nothing gets edited and button is not being changed, and when I click the button nothing happens. Here is the screenshot: On this screenshot the first /test run worked properly, embed was being edited every two seconds, button's label and id were increasing by 1 and when I clicked the button it edited the embed with "stop function" message from callback function and ended the function (maybe the function wasn't ended tho ??), but when I run it 2nd time, it just freez...

Why do the end and flush parameters affect how quickly python prints to the console?

I noticed that when using print() , these parameters significantly affected how quickly it got to the VSCode console, in ways that I do not understand. I used time.time to time some for loops counting to 100,000 with different parameters. No end character specified, flush=false : 13.01 s No end character specified, flush=true : 13.97 s Why did this take longer than with the buffer? It seems like without the middleman it should go faster. End=" " , flush=false : 0.47 s This seems like it would be the same as the first case, but printing a space instead of a newline character, does the newline character take that long to print? Does it have some sort of special functionality in the console? End=" " , flush=true : 6.46 s Once again, why is it longer without the buffer? And this one was 13x longer?! Edit: I've only grown more confused: Printing with "end='\n'" takes even longer than the first one! I thought all it was doing by default was...

Python remove all posts and images (media) via Wordpress REST API

I feel like this should be something several other people already accomplished... to write a script that removes all sample data from a dev webpage using the Wordpress Rest API. Right now I try to automate posting images and posts, which works and leads to several of hundreds posts and images blowing up my database. Looking for a script doing that, neither ChatGPT nor browsing the web has provided any good answers. Any ideas where to look for scripts like that or how to write it yourself? source https://stackoverflow.com/questions/77850567/python-remove-all-posts-and-images-media-via-wordpress-rest-api

How to find element in QTreewidget in python?

How to select this element in Qtreewidget using the path to an element? How to select this element in Qtreewidget using the path to an element? The path is written as an example string: parent/parent/parent/parent/element I create a tree from the list of similar cloths in this way: def makeTree(self): self.treeWidget.clear() data = talkToViz(SimpleLabels.IPSerwer) FunctionsWindow.dataGlobal = data treeWidget = self.treeWidget items = {} def makeChild(parentPath, name): if '^^^' in name: FunctionsWindow.colorRow = True name = name.replace('^^^', '') if parentPath in items: parent = items[parentPath] else: if not parentPath: parent = items[''] = treeWidget else: splitPath = parentPath.split('/') parent = makeChild('/'.join(splitPath[:-1]), splitPath[-1]) if parentPath: ...

Trim with transition/fade using FFMPEG given a list of timestamps

I have a video and a list of timestamps that I want to filter. [ { "timestamp": [10, 20], "state": true }, { "timestamp": [30, 40], "state": false }, { "timestamp": [50, 60], "state": true }, { "timestamp": [70, 80], "state": true } ] I have a script like this to trim based on state. video_path = Path(video_in.name) video_file_name = video_path.stem timestamps_to_cut = [ (timestamps_var[i]['timestamp'][0], timestamps_var[i]['timestamp'][1]) for i in range(len(timestamps_var)) if timestamps_var[i]['state']] between_str = '+'.join( map(lambda t: f'between(t,{t[0]},{t[1]})', timestamps_to_cut)) if timestamps_to_cut: video_file = ffmpeg.input(video_path) video = video_file.video.filter( "select", f'({between_str})').filter("s...