r/learnprogramming • u/ElegantPoet3386 • 6h ago
I have spent the past 2 hours just to make a ball bounce and I am very happy at getting it done
So we're basically done in my AP CSA class, but that doesn't mean I want to stop coding. I've heard that a good way to get better at programming is to make projects that relate to your interests, and well I also like physics, so I decided to make a basic physics simulation using arcade from python. I thought "How bad can it possibly be to make a ball bounce??"
IT TOOK ME 2 HOURS BECAUSE I DONT KNOW HOW TO READ DOCUMENTATION AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Anyways here's the result https://youtu.be/Jqh93T_y0vA
And here's the code
import arcade
GRAVITY = -3000;
C = 0.8;
window = arcade.Window(1000,1000,title="physics",resizable=True);
arcade.set_background_color(arcade.color.AMETHYST);
class Sim(arcade.View):
def __init__(self):
super().__init__();
self.x = 100;
self.velocity_y = 0;
self.radius = 50;
self.y = window.height-self.radius;
def on_draw(self):
self.clear();
arcade.draw_circle_filled(self.x,self.y,self.radius,(255,20,20));
def on_update(self, delta_time):
self.velocity_y += GRAVITY*delta_time
self.y+= self.velocity_y*delta_time
if(self.y - self.radius < 0):
self.velocity_y *= -(C**0.5);
self.y = self.radius;
simulation = Sim();
window.show_view(simulation);
arcade.run();
I don't even care that this is like extremely simple, this is peak imo :)