Advertisement
FeynmanTech

CodeOS_Programs

Dec 30th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.86 KB | None | 0 0
  1.  
  2. --# Main
  3. -- CodeOS
  4.  
  5. --window = function() return {} end
  6.  
  7. -- Use this function to perform your initial setup
  8. function setup()
  9.     local i = readImage("Documents:gear")
  10.     saveImage("Project:Icon", i)
  11.     displayMode(FULLSCREEN)
  12.     keyPressed = ""
  13.     backingMode(RETAINED)
  14.     background(255, 255, 255, 255)
  15.     moved = 1
  16. end
  17.  
  18. -- This function gets called once every frame
  19. function draw()
  20.     -- This sets a dark background color
  21.     --background(255, 255, 255, 255)
  22.    
  23.     -- This sets the line thickness
  24.     strokeWidth(5)
  25.  
  26.     -- Do your drawing here
  27.     drawWindows()
  28.     --if keyPressed ~= "NP" then keyPressed = "NP" end
  29.    
  30.     --if msg then msg() end -- Debugging, doesn't do anything unless you have my print library
  31. end
  32.  
  33. function keyboard(k)
  34.     keyPressed = k
  35.     --print(string.byte(k))
  36. end
  37.  
  38. --# ColorCycle
  39. --[[
  40. local floor = math.floor
  41.  
  42. ColorCycle = window(100, 100, 300, 200, "Background Color Cycle Demo")
  43.  
  44. ColorCycle.i = image(30, 30)
  45. for x=1,30 do
  46.     for y=1,30 do
  47.         local r = (math.sin(math.rad(x / 30 * 360)) + 1) * 127
  48.         local g = (math.sin(math.rad(x / 30 * 360 + 120)) + 1) * 127
  49.         local b = (math.sin(math.rad(x / 30 * 360 + 240)) + 1) * 127
  50.         ColorCycle.i:set(x, y, color(r, g, b))
  51.     end
  52. end
  53. ColorCycle.main = function()
  54.     local s = 2
  55.     local r = math.sin(math.rad(CurrentFrame * s)) * 127 + 127
  56.     local g = math.sin(math.rad(CurrentFrame * s + 120)) * 127 + 127
  57.     local b = math.sin(math.rad(CurrentFrame * s + 240)) * 127 + 127
  58.     background(r, g, b)
  59.     --[=[
  60.     if b < 128 or r < 128 and g > 128 then
  61.         fill(0)
  62.     else
  63.         fill(255)
  64.     end
  65.     --]=]
  66.     fill(255-r, 255-g, 255-b)
  67.     text("Current Color: " .. floor(r) .. "," .. floor(g) .. "," .. floor(b), 10, 10)
  68. end
  69. --]]
  70. --# ShadeCycle
  71. ---[[
  72. ShadeCycle = window(640, 100, 300, 200, "Background Shade Cycle Demo")
  73.  
  74. ShadeCycle.i = image(30, 30)
  75. for x=1,30 do
  76.     for y=1,30 do
  77.         local a = x / 30 * 255
  78.         ShadeCycle.i:set(x, y, color(a))
  79.     end
  80. end
  81. ShadeCycle.main = function()
  82.     background(CurrentFrame % 255)
  83. end
  84.  
  85. --ShadeCycle.active = true
  86. --]]
  87. --# TextEdit
  88. edit = window(500, 70, 300, 200, "Text Editor")
  89. edit.i = readImage("Documents:TextEdit")
  90.  
  91. edit_te = edit:textscroll(10, 10, edit.w - 20, edit.h - 20)
  92.  
  93. function edit.main()
  94.     edit_te:draw()
  95. end
  96.  
  97. edit:extensions("txt", "log")
  98.  
  99. ---[[
  100. edit.onclose = function()
  101.     edit:show()
  102.     edit:alert(ui.OKAY_CANCEL,
  103.         "Warning", "Are you sure you want to close?\nYou will probably lose your progress.",
  104.         function() edit:mhide() end, function() edit:show() end
  105.     )
  106.     return true
  107. end
  108. --]]
  109. --# SketchPad
  110. sketch = window(100, 400, 400, 400, "Sketch Pad")
  111. sketch.i = readImage("Documents:nbrush")
  112. ---[[
  113. sketch.bgimage = image(sketch.w,sketch.h)
  114. setContext(sketch.bgimage)
  115. background(255)
  116. setContext()
  117. --]]
  118. sketch.main = function()
  119.     smooth()
  120.     if CurrentTouch.state == BEGAN then
  121.         spriteMode(CORNER)
  122.         sprite(sketch.bgimage, 0, 0)
  123.     elseif sketch.active or 1 then
  124.         --background(255)
  125.         ---[[
  126.         setContext(sketch.bgimage)
  127.         stroke(0)
  128.         strokeWidth(2)
  129.         clip()
  130.         local m = modelMatrix()
  131.         resetMatrix()
  132.         line(sketch.pmousex, sketch.pmousey, sketch.mousex, sketch.mousey)
  133.         sketch.clip()
  134.         sketch.translate()
  135.         setContext()
  136.         --]]
  137.         spriteMode(CORNER)
  138.         sprite(sketch.bgimage, 0, 0)
  139.     end
  140. end
  141.  
  142. sketch.onclose = function()
  143.     sketch.bgimage = image(sketch.w,sketch.h)
  144. end
  145.  
  146. --edit.active = true
  147. --# Debugger
  148. dev = window(450, 100, 150, 50, "Debug")
  149. dev.i = readImage("Documents:ngear")
  150.  
  151. local afps, t, lt = 60, nil, os.clock()
  152. local fps, avg = {}, 10
  153.  
  154. for i = 1, avg + 1 do
  155.     fps[i] = 100
  156. end
  157.  
  158. local f, tfps = avg + 1, 0
  159. ---[[
  160. dev.main = function()
  161.     background(255, 255, 255, 255)
  162.     tfps = 0
  163.     for n = f - avg, f do
  164.         tfps = tfps + fps[n]
  165.     end
  166.     fill(0)
  167.     text("FPS: " .. math.floor(tfps / avg), 20, 10)
  168.     --text("Windows: " .. awins, 20, 30)
  169. end
  170.  
  171. dev.background = function()
  172.     local t=os.clock()
  173.     table.insert(fps, 1/(t-lt))
  174.     lt=t
  175.     f = f + 1
  176. end
  177. --dev.main()
  178. --]]
  179.  
  180. --# ProgramMaker
  181. ide = window(300, 70, 300, 500, "cOS App Util")
  182. ide.i = readImage("Documents:CodeEdit")
  183.  
  184. local cau = {}
  185.  
  186. local cy = ide.h - 29
  187. cau.t = ide:textedit(5, cy, ide.w - 140, 24, "", "Title")
  188. cau.w = ide:textedit(ide.w - 130, cy, 60, 24, "", "Width")
  189. cau.h = ide:textedit(ide.w - 65, cy, 60, 24, "", "Height")
  190. cy = cy - 29
  191. cau.wname = ide:textedit(5, cy, ide.w - 10, 24, "", "winName")
  192. cy = cy - 205
  193. cau.main = ide:textedit(5, cy, ide.w - 10, 200, "", "Main")
  194. cy = cy - 105
  195. cau.onclose = ide:textedit(5, cy, ide.w - 10, 100, "", "OnClose")
  196.  
  197. ide:extensions("cos")
  198.  
  199. local function data()
  200.     local s = ""
  201.     local t = os.getenv(s)
  202.     t["push"] = function(self, ...) self = self .. table.concat({...}, "") .. "\n" return self end
  203.     os.setenv(s, t)
  204.     return s
  205. end
  206. function save()
  207.     local str = data()
  208.     str:push("--[[")
  209.    
  210.     local t = cau.wname
  211.     str:push(t, " = window(100, 100, ", cau.w, ", ", cau.h, ", ", cau.t)
  212.    
  213.     str:push("--]]")
  214.     saveProjectTab("CodeOS_Programs:" .. t, str)
  215. end
  216.  
  217.  
  218. function ide.main()
  219.     for i, v in pairs(cau) do
  220.         v:draw()
  221.     end
  222.     --[[
  223.     cau_t:draw()
  224.     cau_w:draw()
  225.     cau_h:draw()
  226.     --]]
  227. end
  228.  
  229. ide.onclose = function()
  230.     ide:alert(ui.OKAY_CANCEL,
  231.         "Warning", "Are you sure you want to close?\nYou will probably lose your progress.",
  232.         function() ide:mhide() end, function() ide:show() end
  233.     )
  234.     return true
  235. end
  236. --# ccConfig
  237. --[[
  238. ###########################################
  239. ##Codea Community Project Config Settings##
  240. ###########################################
  241.  
  242. ##You can use # to comment out a line
  243. ##Use 1 for true and 0 for false
  244.  
  245.  
  246. ###########################################
  247. #       Add project info below            #
  248. #==========================================
  249. ProjectName: CodeOS 2
  250. Version: 1.0 Release
  251. Comments: If you find a bug, please tell me!
  252. Author: FLCode
  253. ##License Info: http://choosealicense.com
  254. ##Supported Licneses: MIT, GPL, Apache, NoLicense
  255. License: NoLicense
  256. #==========================================
  257.  
  258.  
  259. ###########################################
  260. #                Settings                 #
  261. [Settings]=================================
  262. ##Codea Community Configuration settings
  263. ##Format: Setting state
  264.  
  265. Button 0
  266. NotifyCCUpdate 1
  267. ResetUserOption 0
  268. AddHeaderInfo 1
  269. CCFOLDER alpha
  270.  
  271. [/Settings]================================
  272.  
  273.  
  274.  
  275. ###########################################
  276. #              Screenshots                #
  277. [Screenshots]==============================
  278. ##Screenshots from your project.
  279. ##Format: url
  280. ##Example: http://www.dropbox.com/screenshot.jpg
  281.  
  282.  
  283. [/Screenshots]=============================
  284.  
  285.  
  286.  
  287. ###########################################
  288. #                   Video                 #
  289. [Video]====================================
  290. ##Link to a YouTube.com video.
  291. ##Format: url
  292. ##Example: http://www.youtube.com/videolink
  293.  
  294.  
  295. [/Video]===================================
  296.  
  297.  
  298.  
  299. ###########################################
  300. #              Dependencies               #
  301. [Dependencies]=============================
  302. ##Include the names of any dependencies here
  303. ##Format: Dependency
  304. ##Example: Codea Community
  305.  
  306.  
  307. [/Dependencies]============================
  308.  
  309.  
  310.  
  311. ############################################
  312. #                   Tabs                   #
  313. [Tabs]======================================
  314. ##Select which tabs are to be uploaded.
  315. ##Keyword 'not' excludes a tab or tabs. Keyword 'add' includes a tab or tabs.
  316. ##not * will exclude all tabs to allow for individual selection
  317. ##not *tab1 will look for any tab with tab1 on the end.
  318. ##not tab1* will look for any tab with tab1 at the beginning.
  319. ##Format: (add/not)(*)tab(*)
  320. ##Example: not Main --this will remove main.
  321. ##Example: not *tab1 --this will remove any tab with "tab1" on the end.
  322. ##Example: add Main --This will add Main back in.
  323.  
  324.  
  325.  
  326.  
  327. [/Tabs]=====================================
  328.  
  329.  
  330.  
  331. #############################################
  332. #                  Assets                   #
  333. [Assets]=====================================
  334. ##Directory, path and url info for any assets besides the standard Codea assets.
  335. ##Format: Folder:sprite URL
  336. ##Example: Documents:sprite1 http://www.somewebsite.com/img.jpg
  337.  
  338.  
  339. [/Assets]====================================
  340. ]]
  341. --# uitest
  342. uit = window(500,300,150,40,"uitest")
  343. uit.i = readImage("Documents:display")
  344.  
  345. local b = uit:button(5, 5, 140, 16, "Filebrowser",
  346.     function() uit:filebrowser(
  347.         function(f) print(file.open(f).contents) end
  348.     ) end
  349. )
  350.  
  351. function uit.main()
  352.     b:draw()
  353.     if uit.selectedfile then
  354.         textMode(CORNER)
  355.         text("File: " .. uit.selectedfile, 5, 25)
  356.     end
  357. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement