Example #1
0
            if (p.loc - center.loc).magnitude() < 100:
                f = center.grav_attract(p)
                p.apply_force(f*-0.6)   # Repels
        s.apply_force(PVector(0, 0.05))
        s.run(canvas)
        s.add_particle()
        s.particles[len(s.particles)-1].vec = PVector(4*(random()-0.5),
                                                      4*(random()-0.5))

    canvas.after(D_STEP, draw)


root = tkinter.Tk()
root.title("Particle Shower")
canvas = tkinter.Canvas(root, height=C_HEIGHT, width=C_WIDTH)
canvas.pack(expand="YES")
canvas.configure(background="white")

center = Mover(PVector(C_WIDTH/2, C_HEIGHT/2),
               PVector(0, 0), PVector(0, 0), 20)
center.display(canvas)

ps = []
ps.append(ParticleSystem(PVector(C_WIDTH/5, C_HEIGHT/8)))
ps.append(ParticleSystem(PVector(2*(C_WIDTH/5), C_HEIGHT/8)))
ps.append(ParticleSystem(PVector(3*(C_WIDTH/5), C_HEIGHT/8)))
ps.append(ParticleSystem(PVector(4*(C_WIDTH/5), C_HEIGHT/8)))

canvas.after(1, draw)
canvas.mainloop()
Example #2
0
def draw():
    global mouse, sat
    # print(mouse.loc.x, mouse.loc.y)

    f = mouse.grav_attract(sat)
    sat.apply_force(f)

    sat.check_edges(C_WIDTH, C_HEIGHT)
    sat.display()
    sat.update()

    canvas.after(D_STEP, draw)


root = tkinter.Tk()
root.title("Mouse Attractor")
canvas = tkinter.Canvas(root, height=C_HEIGHT, width=C_WIDTH)
canvas.pack(expand="YES")
canvas.configure(background="white")

mouse = Mover(PVector(C_WIDTH / 2, C_HEIGHT / 2), PVector(0, 0), PVector(0, 0), 20)
Mover.display = _sat_display
sat = Mover(PVector(C_WIDTH / 2, C_HEIGHT / 2), PVector(0, 0), PVector(0, 0), 10)
sat.canvas_id2 = 0
sat.elast = -0.5

root.bind("<Motion>", on_mouse_move)
canvas.after(1, draw)
canvas.mainloop()