Push Up Challenge

Steps for competiting:

  1. You copy the following code into a new project.
  2. You run the project, placing your iPad on the floor in a room with much space.
  3. You do push ups - but warning - they only count when your nose touches the iPad!
  4. If you want, you can share your results!
-- Push Ups

function setup()
    --- AMOUNT OF PUSH UPS --- 
    n = 0
    
    --- SYSTEM DATA - TOUCH, DISPLAY, ... ---
    touching = false
    col = color(72, 189, 64, 255) -- You can change this.
    displayMode(FULLSCREEN)
    
    --- SECURITY OF ACCIDENTAL DOUBLE TOUCH ---
    pauseNeeded = 50 -- You can change this.
    pause = pauseNeeded
    canDoNext = true
    
    --- GIVE UP ---
    letterList = {}
    local DEMOTIVATION = "Give up!"
    for x = 1, #DEMOTIVATION do
        table.insert(letterList, Letter(string.sub(DEMOTIVATION, x, x), WIDTH*.5+(x-#DEMOTIVATION/2)*25, HEIGHT*.1))
    end
    
    --- MOTIVATING STRINGS EVERY N PUSH UPS ---
    motivationStrings = {"Come on! You can do it!", "Don't give up! One more!", "You're not done yet!", "You just started!", "The crowd applouses...", "You didn't even become red, yet!!", "We trust in you!"} -- You can change this.
    pushUpsForMotivation = 5 -- You can change this.
    motivationID = 1
end

function draw()
    fill(col)
    background(0)
    if touching then
        rect(0, 0, WIDTH, HEIGHT)
    end
    
    if n > 0 then
        fontSize(85)
        font("AmericanTypewriter")
        text(n, WIDTH*.5, HEIGHT*.5)
        
        for a, b in ipairs(letterList) do
            b:draw()
        end
        
        if n%pushUpsForMotivation == 0 then
            font("SourceSansPro-Regular")
            text(motivationStrings[motivationID], WIDTH*.5, HEIGHT*.35)
        else
            motivationID = math.random(1, pushUpsForMotivation)
        end
    end
    
    if not canDoNext then
        pause = pause - 1
        if pause < 0 then
            canDoNext = true
        end
    end
end

function touched(t)
    if t.state == BEGAN then
        touching = true
    elseif t.state == ENDED then
        if t.y < HEIGHT*.2 then
            setup()
            return
        end
        
        touching = false
        if canDoNext then
            n = n + 1
            canDoNext = false
            pause = pauseNeeded
        end
    end
end

Letter = class()

function Letter:init(letter, x, y)
    self.string = letter
    self.pos = vec2(x, y)
    self.fontSize = 50 -- You can change this
    
    self.rotRandom = math.random(1, 10)
    self.xRandom = math.random(1, 10)
    self.yRandom = math.random(1, 10)
end

function Letter:draw()
    fontSize(self.fontSize)
    font("GillSans")
    
    ROTATION = 15*math.sin(ElapsedTime*self.rotRandom*n/10)
    X_MODIFIER = 15*math.sin(ElapsedTime*self.xRandom*n/10)
    Y_MODIFIER = 15*math.sin(ElapsedTime*self.yRandom*n/10)
    
    translate(self.pos.x + X_MODIFIER, self.pos.y + Y_MODIFIER)
    rotate(ROTATION)
    text(self.string, 0, 0)
    rotate(-ROTATION)
    translate(-self.pos.x - X_MODIFIER, -self.pos.y - Y_MODIFIER)
end

https://i.imgur.com/2uoUYv5.jpg

https://i.imgur.com/c3BjGD5.jpg

You can develop the project to your own new game!

Of course, be pleased to share your score, but pay attention, if you release a picture with your face, it cannot be undone!

@TokOut This is interesting, but I guess this would have to be done on the honor system. I can sit on the couch and bring the iPad to my nose a lot more than if I actually did pushups.

Of course! But in our community, everyone is full of honor! Another developer would just change the n = 0 to n = 99

Btw. I made the project for you, guys! I know developers sitting all day and enjoying the code from my experience about me! But let’s take a small break and join the challenge :joy:

Edit: Those two pictures above ^ are two different hunts, the first one was just to demonstrate what to do, then I started it actually. What you see there with the 37 is after some long minute! :wink: and sadly my current Highscore :frowning:

@TokOut this is so cool, will give it a try later and post my score. I love what you’ve done with the animated text at the bottom of the screen

@Simeon, yeah, thought would be cool. Btw. I think it’s possible to do the same somehow faster, I just don’t get yet how. Also to make the letters be completely random on their curve, I’ll need to make a formula based of two math.sins where one contains an irrational factor, and the other a natural. I just hadn’t time yet, due to school and other stuff

Update

Attention! This is not a push up challenge but a contribution to Simeon’s favorite part of the code.

Hi @Simeon, so I’ve made here the code for you to play around a bit :wink: I hope you love it :slight_smile:

I can think of a “read the message” codea game or something based of this :slight_smile:

-- Glitchy Text Effect

function setup()
    displayMode(OVERLAY)
    parameter.text("message", "Simeon and John do the best for us!", callback)
    parameter.integer("turbulence", 2, 50, 15)
    callback()
end

function draw()
    background(0)
    for a, b in ipairs(array) do
        b:draw()
    end
end

function callback()
    array = {}
    for n = 1, #message do
        table.insert(array, Letter(string.sub(message, n, n), WIDTH*.5+(n-#message/2)*25, HEIGHT*.5))
    end
end

Letter = class()

function Letter:init(letter, x, y)
    self.string = letter
    self.pos = vec2(x, y)
    self.fontSize = 50 -- You can change this
    
    self.rotRandom = math.random(1, 50)
    self.xRandom = math.random(1, 20)
    self.yRandom = math.random(1, 20)
end

function Letter:draw()
    fontSize(self.fontSize)
    font("GillSans")
    
    ROTATION = turbulence*(math.sin(ElapsedTime*self.rotRandom)+math.sin((math.pi/3)*ElapsedTime*self.rotRandom))/2
    X_MODIFIER = turbulence*(math.sin(ElapsedTime*self.xRandom)+math.sin((math.pi/3)*ElapsedTime*self.xRandom))/2
    Y_MODIFIER = turbulence*(math.sin(ElapsedTime*self.yRandom)+math.sin((math.pi/3)*ElapsedTime*self.yRandom))/2
    
    translate(self.pos.x + X_MODIFIER, self.pos.y + Y_MODIFIER)
    rotate(ROTATION)
    text(self.string, 0, 0)
    rotate(-ROTATION)
    translate(-self.pos.x - X_MODIFIER, -self.pos.y - Y_MODIFIER)
end

@TokOut really nice effect, I like seeing these sorts of transformations applied to individual letters in text.

I see you have a fixed character spacing of 25 so I tried to modify your code to use the substring length to position the next character. It’s not perfect but you get slightly better character alignment.

I also used retained backing mode to add some motion blur

-- Glitchy Text Effect

function setup()
    displayMode(OVERLAY)
    backingMode(RETAINED)
    parameter.text("message", "Hello World", callback)
    parameter.integer("turbulence", 0, 50, 6)
    callback()
end

function draw()
    fill(0, 30)
    rect(0, 0, WIDTH, HEIGHT)
    
    fill(255)
    for a, b in ipairs(array) do
        b:draw()
    end
end

function callback()
    array = {}
    
    -- Lazy code here, we assume the text size and font
    fontSize(50)
    font("GillSans")
    
    local substringSize = 0
    for n = 1, #message do
        table.insert(array, Letter(string.sub(message, n, n), WIDTH*0.5 + substringSize, HEIGHT*.5))
        
        local substring = string.sub(message, 1, n)
        substringSize = textSize(substring)
    end
end

Letter = class()

function Letter:init(letter, x, y)    
    -- Assumes the font state is correctly set
    local letterWidth = textSize(letter)
    
    self.string = letter
    self.pos = vec2(x + letterWidth / 2.0, y)
    self.fontSize = 50 -- You can change this

    self.rotRandom = math.random(1, 50)
    self.xRandom = math.random(1, 20)
    self.yRandom = math.random(1, 20)
end

function Letter:draw()
    fontSize(self.fontSize)
    font("GillSans")

    ROTATION = turbulence*(math.sin(ElapsedTime*self.rotRandom)+math.sin((math.pi/3)*ElapsedTime*self.rotRandom))/2
    X_MODIFIER = turbulence*(math.sin(ElapsedTime*self.xRandom)+math.sin((math.pi/3)*ElapsedTime*self.xRandom))/2
    Y_MODIFIER = turbulence*(math.sin(ElapsedTime*self.yRandom)+math.sin((math.pi/3)*ElapsedTime*self.yRandom))/2

    translate(self.pos.x + X_MODIFIER, self.pos.y + Y_MODIFIER)
    rotate(ROTATION)
    text(self.string, 0, 0)
    rotate(-ROTATION)
    translate(-self.pos.x - X_MODIFIER, -self.pos.y - Y_MODIFIER)
end