Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- Code 14a - Examples
- -- Bruce Elliott
- -- May 2013
- -- Code in this program was inspired by
- -- Programming in Lua - Chapter 9
- -- Use this function to perform your initial setup
- function setup()
- co = coroutine.create(
- function()
- print("hi!")
- end)
- print("co uses an anonymous function")
- print("print: ", co)
- print("status: ", coroutine.status(co))
- print("resume 1: ", coroutine.resume(co))
- print("resume 2: ", coroutine.resume(co))
- print("status: ", coroutine.status(co))
- print("resume 3: ", coroutine.resume(co))
- print("coroutine np uses a named function")
- print("create np, create leaves cor suspended: ")
- np = coroutine.create(myPrint)
- print("status: ", coroutine.status(np))
- print("resume: ", coroutine.resume(np))
- print("status: ", coroutine.status(np))
- print("resume: ", coroutine.resume(np))
- g1 = coroutine.create(xSqrySqr)
- end
- function myPrint()
- print("This hi!")
- end
- x= 10
- y=10
- x1=10
- y1 = 10
- -- This function gets called once every frame
- function draw()
- -- xSquared()
- -- This sets a dark background color
- -- background(40, 40, 50)
- -- coroutine.resume(g1)
- -- This sets the line thickness
- strokeWidth(5)
- -- x, y, x1, y1 = xSquared()
- line(x, y, x1, y1)
- -- Do your drawing here
- end
- function xSqrySqr()
- x = 0
- y = 0
- x1 = 0
- y1 = 0
- j = -1
- while j < 1.1 do
- x1 = x1 + (500/20)
- y1 = math.sqrt(1- j^2) * HEIGHT/2
- print(x, y, x1, y1)
- coroutine.yield()
- x = x1
- y = y1
- j = j + 2/25
- end
- end
- function touched(touch)
- if touch.state == ENDED then
- coroutine.resume(g1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement