コード例 #1
0
WIDTH = 800
HEIGHT = 600
CLOCK = 0
plot = []

### ONLY EDIT THIS AREA ############


class springObj:
    startPos = vector(0, 0)
    endPos = vector(0, 1)
    length = 1
    k = 1


obj = object()
obj.mass = 200
obj.pos = vector(WIDTH / 2, HEIGHT / 2 + 50)

spring = springObj()
spring.startPos = vector(WIDTH / 2, HEIGHT / 2 + 150)
spring.endPos = obj.pos
spring.length = 150
spring.k = 16

obj2 = object()
obj2.mass = 200
obj2.pos = vector(WIDTH / 2, HEIGHT / 2 - 200)

spring2 = springObj()
spring2.startPos = obj.pos
コード例 #2
0
FPS = 100
ACCEL = 5
WIDTH = 800
HEIGHT = 600
CLOCK = 0
plot = []

### ONLY EDIT THIS AREA ############

class springObj:
    startPos = vector(0,0)
    endPos = vector(0,1)
    length = 1
    k = 1

obj = object()
obj.v = vector(0,0.00000001)
obj.pos = vector(WIDTH/2, HEIGHT/2-190)

spring = springObj()
spring.startPos = vector(WIDTH/2, HEIGHT/2+150)
spring.endPos = obj.pos
spring.length = 240
spring.k = 1


def objUpdate():
    spring.endPos = obj.pos
    kx = (abs(spring.startPos - spring.endPos) - spring.length) * spring.k
    obj.force = (spring.startPos - spring.endPos).normalized() * kx - abs(obj.v)*obj.v.normalized() * 0.1
    print(obj.force)