예제 #1
0
def setup():
    global world, pop, cage
    size(400, 400)
    smooth()
    Fisica.init(this)
    Fisica.setScale(10)
    world = FWorld()
    world.setEdges()
    world.remove(world.top)
    pop = createPop()
    pop.setPosition(width / 2, height / 2)
    pop.setBullet(True)
    world.add(pop)
    cage = createCage()
    cage.setPosition(width / 2, height / 2)
    cage.setRotation(PI / 6)
    cage.setBullet(True)
    world.add(cage)

    for _ in range(10):
        c = FCircle(7)
        c.setPosition(width / 2 - 10 + random(-5, 5),
                      height / 2 - 10 + random(-5, 5))
        c.setBullet(True)
        c.setNoStroke()
        c.setFillColor(color(0xFF, 0x92, 0x03))
        world.add(c)

    rectMode(CENTER)
예제 #2
0
def setup():
    global boxButton, circleButton, polyButton, world

    size(400, 400)
    smooth()
    Fisica.init(this)
    world = FWorld()
    world.setEdges()
    world.remove(world.left)
    world.remove(world.right)
    world.remove(world.top)
    boxButton = FBox(40, 40)
    boxButton.setPosition(width/4, 100)
    boxButton.setStatic(True)
    boxButton.setFillColor(buttonColor)
    boxButton.setNoStroke()
    world.add(boxButton)
    circleButton = FCircle(40)
    circleButton.setPosition(2*width/4, 100)
    circleButton.setStatic(True)
    circleButton.setFillColor(buttonColor)
    circleButton.setNoStroke()
    world.add(circleButton)
    polyButton = FPoly()
    polyButton.vertex(20, 20)
    polyButton.vertex(-20, 20)
    polyButton.vertex(0, -20)
    polyButton.setPosition(3*width/4, 100)
    polyButton.setStatic(True)
    polyButton.setFillColor(buttonColor)
    polyButton.setNoStroke()
    world.add(polyButton)
예제 #3
0
def mousePressed():
    radius = random(10, 40)
    bola = FCircle(radius)
    bola.setPosition(mouseX, mouseY)
    bola.setDensity(0.2)
    bola.setFill(120, 120, 190)
    bola.setNoStroke()
    world.add(bola)
예제 #4
0
def setup():
    global world, pop, cage
    size(400, 400)
    smooth()
    Fisica.init(this)
    Fisica.setScale(10)
    world = FWorld()
    world.setEdges()
    world.remove(world.top)
    pop = createPop()
    pop.setPosition(width/2, height/2)
    pop.setBullet(True)
    world.add(pop)
    cage = createCage()
    cage.setPosition(width/2, height/2)
    cage.setRotation(PI/6)
    cage.setBullet(True)
    world.add(cage)

    for _ in range(10):
        c = FCircle(7)
        c.setPosition(width/2-10+random(-5, 5), height/2-10+random(-5, 5))
        c.setBullet(True)
        c.setNoStroke()
        c.setFillColor(color(0xFF, 0x92, 0x03))
        world.add(c)

    rectMode(CENTER)
예제 #5
0
def setup():
    global world
    size(400, 400)
    smooth()
    Fisica.init(this)
    world = FWorld()
    world.setEdges()
    world.remove(world.left)
    world.remove(world.right)
    world.remove(world.top)
    world.setEdgesRestitution(0.0)
    for i in range(ballCount):
        b = FCircle(25)
        b.setPosition(map(i, 0, ballCount - 1, 40, width - 40), height / 6)
        b.setRestitution(map(i, 0, ballCount - 1, 0.0, 1.0))
        b.setNoStroke()
        b.setFill(map(i, 0, ballCount - 1, 60, 255), 80, 120)
        world.add(b)
예제 #6
0
def createPop():
    b = FBox(6, 60)
    b.setFillColor(color(0x1F, 0x71, 0x6B))
    b.setNoStroke()
    c = FCircle(20)
    c.setPosition(0, -30)
    c.setFillColor(color(0xFF, 0x00, 0x51))
    c.setNoStroke()

    result = FCompound()
    result.addBody(b)
    result.addBody(c)

    return result
예제 #7
0
def setup():
    global world
    size(400, 400)
    smooth()
    Fisica.init(this)
    world = FWorld()
    world.setEdges()
    world.remove(world.left)
    world.remove(world.right)
    world.remove(world.top)
    world.setEdgesRestitution(0.0)
    for i in range(ballCount):
        b = FCircle(25)
        b.setPosition(map(i, 0, ballCount-1, 40, width-40), height/6)
        b.setRestitution(map(i, 0, ballCount-1, 0.0, 1.0))
        b.setNoStroke()
        b.setFill(map(i, 0, ballCount-1, 60, 255), 80, 120)
        world.add(b)
예제 #8
0
def createPop():
    b = FBox(6, 60)
    b.setFillColor(color(0x1F, 0x71, 0x6B))
    b.setNoStroke()
    c = FCircle(20)
    c.setPosition(0, -30)
    c.setFillColor(color(0xFF, 0x00, 0x51))
    c.setNoStroke()

    result = FCompound()
    result.addBody(b)
    result.addBody(c)

    return result
예제 #9
0
def createSpider():
    posX = random(mainSize / 2, width - mainSize / 2)
    posY = random(mainSize / 2, height - mainSize / 2)
    main = FCircle(mainSize)
    main.setPosition(posX, posY)
    main.setVelocity(random(-20, 20), random(-20, 20))
    main.setFillColor(bodyColor)
    main.setNoStroke()
    main.setGroupIndex(2)
    world.add(main)
    mains.append(main)
    for i in range(legCount):
        x = legSize * cos(i * TWO_PI / 3) + posX
        y = legSize * sin(i * TWO_PI / 3) + posY
        leg = FCircle(mainSize / 2)
        leg.setPosition(posX, posY)
        leg.setVelocity(random(-20, 20), random(-20, 20))
        leg.setFillColor(bodyColor)
        leg.setNoStroke()
        world.add(leg)
        j = FDistanceJoint(main, leg)
        j.setLength(legSize)
        j.setNoStroke()
        j.setStroke(0)
        j.setFill(0)
        j.setDrawable(False)
        j.setFrequency(0.1)
        world.add(j)
예제 #10
0
def draw():
    background(255)
    if frameCount % 50 == 0:
        sz = random(30, 60)
        b = FCircle(sz)
        b.setPosition(random(0 + 30, width - 30), 50)
        b.setVelocity(0, 100)
        b.setRestitution(0.7)
        b.setDamping(0.01)
        b.setNoStroke()
        b.setFill(200, 30, 90)
        world.add(b)
    world.draw()
    world.step()
예제 #11
0
def mousePressed():
    pressed = world.getBody(mouseX, mouseY)
    if pressed == boxButton:
        myBox = FBox(40, 40)
        myBox.setPosition(width/4, 200)
        myBox.setRotation(random(TWO_PI))
        myBox.setVelocity(0, 200)
        myBox.setFillColor(bodyColor)
        myBox.setNoStroke()
        world.add(myBox)
    elif pressed == circleButton:
        myCircle = FCircle(40)
        myCircle.setPosition(2*width/4, 200)
        myCircle.setRotation(random(TWO_PI))
        myCircle.setVelocity(0, 200)
        myCircle.setFillColor(bodyColor)
        myCircle.setNoStroke()
        world.add(myCircle)
    elif pressed == polyButton:
        myPoly = FPoly()
        myPoly.vertex(20, 20)
        myPoly.vertex(-20, 20)
        myPoly.vertex(0, -20)
        myPoly.setPosition(3*width/4, 200)
        myPoly.setRotation(random(TWO_PI))
        myPoly.setVelocity(0, 200)
        myPoly.setFillColor(bodyColor)
        myPoly.setNoStroke()
        world.add(myPoly)
예제 #12
0
def draw():
    fill(0, 100)
    noStroke()
    rect(0, 0, width, height)
    if frameCount % 24 == 0:
        bolita = FCircle(8)
        bolita.setNoStroke()
        bolita.setFill(255)
        bolita.setPosition(100, 20)
        bolita.setVelocity(0, 400)
        bolita.setRestitution(0.9)
        bolita.setDamping(0)
        mundo.add(bolita)
    mundo.step()
    mundo.draw(this)
예제 #13
0
def createSpider():
    posX = random(mainSize/2, width-mainSize/2)
    posY = random(mainSize/2, height-mainSize/2)
    main = FCircle(mainSize)
    main.setPosition(posX, posY)
    main.setVelocity(random(-20,20), random(-20,20))
    main.setFillColor(bodyColor)
    main.setNoStroke()
    main.setGroupIndex(2)
    world.add(main)
    mains.append(main)
    for i in range(legCount):
        x = legSize * cos(i*TWO_PI/3) + posX
        y = legSize * sin(i*TWO_PI/3) + posY
        leg = FCircle(mainSize/2)
        leg.setPosition(posX, posY)
        leg.setVelocity(random(-20,20), random(-20,20))
        leg.setFillColor(bodyColor)
        leg.setNoStroke()
        world.add(leg)
        j = FDistanceJoint(main, leg)
        j.setLength(legSize)
        j.setNoStroke()
        j.setStroke(0)
        j.setFill(0)
        j.setDrawable(False)
        j.setFrequency(0.1)
        world.add(j)
예제 #14
0
def draw():
    fill(0, 100)
    noStroke()
    rect(0, 0, width, height)
    if frameCount % 24 == 0:
        bolita = FCircle(8)
        bolita.setNoStroke()
        bolita.setFill(255)
        bolita.setPosition(100, 20)
        bolita.setVelocity(0, 400)
        bolita.setRestitution(0.9)
        bolita.setDamping(0)
        mundo.add(bolita)
    mundo.step()
    mundo.draw(this)
예제 #15
0
def setup():
    global world
    size(400, 400)
    smooth()
    Fisica.init(this)
    world = FWorld()
    world.setGravity(0, 0)
    world.setEdges()
    world.remove(world.left)
    world.remove(world.top)
    world.remove(world.bottom)
    for i in range(ballCount):
        b = FCircle(25)
        b.setPosition(40, map(i, 0, ballCount - 1, 40, height - 40))
        b.setDensity(map(i, 0, ballCount - 1, 0.1, 0.9))
        b.setVelocity(100, 0)
        b.setDamping(0.0)
        b.setNoStroke()
        b.setFill(map(i, 0, ballCount - 1, 120, 0))
        world.add(b)
    for i in range(ballCount):
        b = FCircle(25)
        b.setPosition(width / 2, map(i, 0, ballCount - 1, 40, height - 40))
        b.setVelocity(0, 0)
        b.setDamping(0.0)
        b.setDensity(0.9)
        b.setNoStroke()
        b.setFill(125, 80, 120)
        world.add(b)
예제 #16
0
def draw():
    background(255)
    if frameCount % 8 == 0:
        b = FCircle(random(5, 20))
        b.setPosition(random(0+10, width-10), 50)
        b.setVelocity(0, 200)
        b.setRestitution(0)
        b.setNoStroke()
        b.setFill(200, 30, 90)
        world.add(b)
    pala.setPosition(mouseX, height - 40)
    world.draw()
    world.step()
예제 #17
0
def setup():
    global world
    size(400, 400)
    smooth()
    Fisica.init(this)
    world = FWorld()
    world.setGravity(0, 0)
    world.setEdges()
    world.remove(world.left)
    world.remove(world.top)
    world.remove(world.bottom)
    for i in range(ballCount):
        b = FCircle(25)
        b.setPosition(40, map(i, 0, ballCount-1, 40, height-40))
        b.setDensity(map(i, 0, ballCount-1, 0.1, 0.9))
        b.setVelocity(100, 0)
        b.setDamping(0.0)
        b.setNoStroke()
        b.setFill(map(i, 0, ballCount-1, 120, 0))
        world.add(b)
    for i in range(ballCount):
        b = FCircle(25)
        b.setPosition(width/2, map(i, 0, ballCount-1, 40, height-40))
        b.setVelocity(0, 0)
        b.setDamping(0.0)
        b.setDensity(0.9)
        b.setNoStroke()
        b.setFill(125, 80, 120)
        world.add(b)
예제 #18
0
def draw():
    background(255)
    if frameCount % 8 == 0:
        b = FCircle(random(5, 20))
        b.setPosition(random(0 + 10, width - 10), 50)
        b.setVelocity(0, 200)
        b.setRestitution(0)
        b.setNoStroke()
        b.setFill(200, 30, 90)
        world.add(b)
    pala.setPosition(mouseX, height - 40)
    world.draw()
    world.step()
예제 #19
0
def setup():
    global puenteY, world

    size(400, 400)
    smooth()
    puenteY = height/3
    Fisica.init(this)
    world = FWorld()
    bola = FCircle(40)
    bola.setPosition(width/3, puenteY-10)
    bola.setDensity(0.2)
    bola.setFill(120, 120, 190)
    bola.setNoStroke()
    world.add(bola)
    for i in range(stepCount):
        box = FBox(boxWidth, 10)
        box.setPosition(map(i, 0, stepCount - 1, boxWidth, width-boxWidth), puenteY)
        box.setNoStroke()
        box.setFill(120, 200, 190)
        world.add(box)
        steps.append(box)
    for i in range(1, stepCount):
        junta = FDistanceJoint(steps[i-1], steps[i])
        junta.setAnchor1(boxWidth/2, 0)
        junta.setAnchor2(-boxWidth/2, 0)
        junta.setFrequency(frequency)
        junta.setDamping(damping)
        junta.setFill(0)
        junta.calculateLength()
        world.add(junta)
    left = FCircle(10)
    left.setStatic(True)
    left.setPosition(0, puenteY)
    left.setDrawable(False)
    world.add(left)
    right = FCircle(10)
    right.setStatic(True)
    right.setPosition(width, puenteY)
    right.setDrawable(False)
    world.add(right)
    juntaPrincipio = FDistanceJoint(steps[0], left)
    juntaPrincipio.setAnchor1(-boxWidth/2, 0)
    juntaPrincipio.setAnchor2(0, 0)
    juntaPrincipio.setFrequency(frequency)
    juntaPrincipio.setDamping(damping)
    juntaPrincipio.calculateLength()
    juntaPrincipio.setFill(0)
    world.add(juntaPrincipio)
    juntaFinal = FDistanceJoint(steps[stepCount-1], right)
    juntaFinal.setAnchor1(boxWidth/2, 0)
    juntaFinal.setAnchor2(0, 0)
    juntaFinal.setFrequency(frequency)
    juntaFinal.setDamping(damping)
    juntaFinal.calculateLength()
    juntaFinal.setFill(0)
    world.add(juntaFinal)