Advertisement
br1wr2el3

Code 14a - Examples

May 29th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2. --# Main
  3. -- Code 14a - Examples
  4.  
  5. -- Bruce Elliott
  6. -- May 2013
  7.  
  8. -- Code in this program was inspired by
  9. -- Programming in Lua - Chapter 9
  10.  
  11. -- Use this function to perform your initial setup
  12. function setup()
  13.  
  14. co = coroutine.create(
  15. function()
  16. print("hi!")
  17. end)
  18.  
  19. print("co uses an anonymous function")
  20. print("print: ", co)
  21. print("status: ", coroutine.status(co))
  22. print("resume 1: ", coroutine.resume(co))
  23. print("resume 2: ", coroutine.resume(co))
  24. print("status: ", coroutine.status(co))
  25. print("resume 3: ", coroutine.resume(co))
  26.  
  27. print("coroutine np uses a named function")
  28. print("create np, create leaves cor suspended: ")
  29. np = coroutine.create(myPrint)
  30. print("status: ", coroutine.status(np))
  31. print("resume: ", coroutine.resume(np))
  32. print("status: ", coroutine.status(np))
  33. print("resume: ", coroutine.resume(np))
  34.  
  35. g1 = coroutine.create(xSqrySqr)
  36. end
  37.  
  38.  
  39.  
  40. function myPrint()
  41. print("This hi!")
  42. end
  43.  
  44. x= 10
  45. y=10
  46. x1=10
  47. y1 = 10
  48. -- This function gets called once every frame
  49.  
  50. function draw()
  51. -- xSquared()
  52. -- This sets a dark background color
  53. -- background(40, 40, 50)
  54. -- coroutine.resume(g1)
  55. -- This sets the line thickness
  56. strokeWidth(5)
  57. -- x, y, x1, y1 = xSquared()
  58. line(x, y, x1, y1)
  59. -- Do your drawing here
  60.  
  61. end
  62.  
  63. function xSqrySqr()
  64. x = 0
  65. y = 0
  66. x1 = 0
  67. y1 = 0
  68. j = -1
  69. while j < 1.1 do
  70. x1 = x1 + (500/20)
  71. y1 = math.sqrt(1- j^2) * HEIGHT/2
  72.  
  73. print(x, y, x1, y1)
  74. coroutine.yield()
  75. x = x1
  76. y = y1
  77. j = j + 2/25
  78. end
  79. end
  80.  
  81. function touched(touch)
  82. if touch.state == ENDED then
  83. coroutine.resume(g1)
  84. end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement