Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

8-Ball/Crystal Ball program

I thought it would be a good idea to start off by posting simple programs. Here is a Y/N crystal ball:
-- Crystal Ball

-- Use this function to perform your initial setup
function setup()
    displayMode(FULLSCREEN)
    responses = {
        "Yes.",
        "No.",
        "Maybe.",
        "It's Probable.",
        "Definetly.",
        "I Doubt It",
        "I am not sure."
        -- You may add more responses
    }
    answer = "Shake the iPad for an answer!"
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(49, 49, 89, 255)
    fill(0, 255, 232, 255)
    font("Didot-Italic")
    fontSize(24)
    text("Ask the Crystal Ball a Yes or No Question!", WIDTH/2, HEIGHT-100)
    fontSize(48)
    text(answer, WIDTH/2, HEIGHT/2)
    if (UserAcceleration.z > 1.5) then
        answer = responses[math.random(#responses)]
    end
end
Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 8,187

    Nice program. I used to have an 8 ball.

  • dave1707dave1707 Mod
    Posts: 8,187

    @niorg2606 I modified your code a little. Hold the iPad flat for an answer, tilt the iPad to clear the answer.

    function setup()
        choice=0
        alpha=0
        answer=""
        displayMode(FULLSCREEN)
        responses = {
            "Yes.",
            "No.",
            "Maybe.",
            "It's Probable.",
            "Definetly.",
            "I Doubt It.",
            "I am not sure."
            -- You may add more responses
        }
        font("Didot-Italic")
    end
    
    function draw()
        background(0)
        fontSize(24)
        fill(0,255,232)
        text("Ask the Crystal Ball a Yes or No Question!", WIDTH/2, HEIGHT-100)
        text("Hold the iPad flat for an answer...",WIDTH/2,HEIGHT-150)
        text("Tilt the iPad to clear...",WIDTH/2,HEIGHT-200)
        if Gravity.z<-.97 then
            if choice==0 then
                choice=math.random(#responses)
                answer = responses[choice]
            end  
            if alpha<255 then
                alpha=alpha+2
            end
        else
            choice=0
            if alpha>0 then
                alpha=alpha-5
            end
        end
        fill(0, 149, 255, 80)
        ellipse(WIDTH/2,HEIGHT/2,350)
        fontSize(48)
        fill(255,0,0,alpha)
        text(answer, WIDTH/2, HEIGHT/2)
    end
    
  • Posts: 79

    That's cool! I love the fading effect.

Sign In or Register to comment.