Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- CodeOS
- --window = function() return {} end
- -- Use this function to perform your initial setup
- function setup()
- local i = readImage("Documents:gear")
- saveImage("Project:Icon", i)
- displayMode(FULLSCREEN)
- keyPressed = ""
- backingMode(RETAINED)
- background(255, 255, 255, 255)
- moved = 1
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- --background(255, 255, 255, 255)
- -- This sets the line thickness
- strokeWidth(5)
- -- Do your drawing here
- drawWindows()
- --if keyPressed ~= "NP" then keyPressed = "NP" end
- --if msg then msg() end -- Debugging, doesn't do anything unless you have my print library
- end
- function keyboard(k)
- keyPressed = k
- --print(string.byte(k))
- end
- --# ColorCycle
- --[[
- local floor = math.floor
- ColorCycle = window(100, 100, 300, 200, "Background Color Cycle Demo")
- ColorCycle.i = image(30, 30)
- for x=1,30 do
- for y=1,30 do
- local r = (math.sin(math.rad(x / 30 * 360)) + 1) * 127
- local g = (math.sin(math.rad(x / 30 * 360 + 120)) + 1) * 127
- local b = (math.sin(math.rad(x / 30 * 360 + 240)) + 1) * 127
- ColorCycle.i:set(x, y, color(r, g, b))
- end
- end
- ColorCycle.main = function()
- local s = 2
- local r = math.sin(math.rad(CurrentFrame * s)) * 127 + 127
- local g = math.sin(math.rad(CurrentFrame * s + 120)) * 127 + 127
- local b = math.sin(math.rad(CurrentFrame * s + 240)) * 127 + 127
- background(r, g, b)
- --[=[
- if b < 128 or r < 128 and g > 128 then
- fill(0)
- else
- fill(255)
- end
- --]=]
- fill(255-r, 255-g, 255-b)
- text("Current Color: " .. floor(r) .. "," .. floor(g) .. "," .. floor(b), 10, 10)
- end
- --]]
- --# ShadeCycle
- ---[[
- ShadeCycle = window(640, 100, 300, 200, "Background Shade Cycle Demo")
- ShadeCycle.i = image(30, 30)
- for x=1,30 do
- for y=1,30 do
- local a = x / 30 * 255
- ShadeCycle.i:set(x, y, color(a))
- end
- end
- ShadeCycle.main = function()
- background(CurrentFrame % 255)
- end
- --ShadeCycle.active = true
- --]]
- --# TextEdit
- edit = window(500, 70, 300, 200, "Text Editor")
- edit.i = readImage("Documents:TextEdit")
- edit_te = edit:textscroll(10, 10, edit.w - 20, edit.h - 20)
- function edit.main()
- edit_te:draw()
- end
- edit:extensions("txt", "log")
- ---[[
- edit.onclose = function()
- edit:show()
- edit:alert(ui.OKAY_CANCEL,
- "Warning", "Are you sure you want to close?\nYou will probably lose your progress.",
- function() edit:mhide() end, function() edit:show() end
- )
- return true
- end
- --]]
- --# SketchPad
- sketch = window(100, 400, 400, 400, "Sketch Pad")
- sketch.i = readImage("Documents:nbrush")
- ---[[
- sketch.bgimage = image(sketch.w,sketch.h)
- setContext(sketch.bgimage)
- background(255)
- setContext()
- --]]
- sketch.main = function()
- smooth()
- if CurrentTouch.state == BEGAN then
- spriteMode(CORNER)
- sprite(sketch.bgimage, 0, 0)
- elseif sketch.active or 1 then
- --background(255)
- ---[[
- setContext(sketch.bgimage)
- stroke(0)
- strokeWidth(2)
- clip()
- local m = modelMatrix()
- resetMatrix()
- line(sketch.pmousex, sketch.pmousey, sketch.mousex, sketch.mousey)
- sketch.clip()
- sketch.translate()
- setContext()
- --]]
- spriteMode(CORNER)
- sprite(sketch.bgimage, 0, 0)
- end
- end
- sketch.onclose = function()
- sketch.bgimage = image(sketch.w,sketch.h)
- end
- --edit.active = true
- --# Debugger
- dev = window(450, 100, 150, 50, "Debug")
- dev.i = readImage("Documents:ngear")
- local afps, t, lt = 60, nil, os.clock()
- local fps, avg = {}, 10
- for i = 1, avg + 1 do
- fps[i] = 100
- end
- local f, tfps = avg + 1, 0
- ---[[
- dev.main = function()
- background(255, 255, 255, 255)
- tfps = 0
- for n = f - avg, f do
- tfps = tfps + fps[n]
- end
- fill(0)
- text("FPS: " .. math.floor(tfps / avg), 20, 10)
- --text("Windows: " .. awins, 20, 30)
- end
- dev.background = function()
- local t=os.clock()
- table.insert(fps, 1/(t-lt))
- lt=t
- f = f + 1
- end
- --dev.main()
- --]]
- --# ProgramMaker
- ide = window(300, 70, 300, 500, "cOS App Util")
- ide.i = readImage("Documents:CodeEdit")
- local cau = {}
- local cy = ide.h - 29
- cau.t = ide:textedit(5, cy, ide.w - 140, 24, "", "Title")
- cau.w = ide:textedit(ide.w - 130, cy, 60, 24, "", "Width")
- cau.h = ide:textedit(ide.w - 65, cy, 60, 24, "", "Height")
- cy = cy - 29
- cau.wname = ide:textedit(5, cy, ide.w - 10, 24, "", "winName")
- cy = cy - 205
- cau.main = ide:textedit(5, cy, ide.w - 10, 200, "", "Main")
- cy = cy - 105
- cau.onclose = ide:textedit(5, cy, ide.w - 10, 100, "", "OnClose")
- ide:extensions("cos")
- local function data()
- local s = ""
- local t = os.getenv(s)
- t["push"] = function(self, ...) self = self .. table.concat({...}, "") .. "\n" return self end
- os.setenv(s, t)
- return s
- end
- function save()
- local str = data()
- str:push("--[[")
- local t = cau.wname
- str:push(t, " = window(100, 100, ", cau.w, ", ", cau.h, ", ", cau.t)
- str:push("--]]")
- saveProjectTab("CodeOS_Programs:" .. t, str)
- end
- function ide.main()
- for i, v in pairs(cau) do
- v:draw()
- end
- --[[
- cau_t:draw()
- cau_w:draw()
- cau_h:draw()
- --]]
- end
- ide.onclose = function()
- ide:alert(ui.OKAY_CANCEL,
- "Warning", "Are you sure you want to close?\nYou will probably lose your progress.",
- function() ide:mhide() end, function() ide:show() end
- )
- return true
- end
- --# ccConfig
- --[[
- ###########################################
- ##Codea Community Project Config Settings##
- ###########################################
- ##You can use # to comment out a line
- ##Use 1 for true and 0 for false
- ###########################################
- # Add project info below #
- #==========================================
- ProjectName: CodeOS 2
- Version: 1.0 Release
- Comments: If you find a bug, please tell me!
- Author: FLCode
- ##License Info: http://choosealicense.com
- ##Supported Licneses: MIT, GPL, Apache, NoLicense
- License: NoLicense
- #==========================================
- ###########################################
- # Settings #
- [Settings]=================================
- ##Codea Community Configuration settings
- ##Format: Setting state
- Button 0
- NotifyCCUpdate 1
- ResetUserOption 0
- AddHeaderInfo 1
- CCFOLDER alpha
- [/Settings]================================
- ###########################################
- # Screenshots #
- [Screenshots]==============================
- ##Screenshots from your project.
- ##Format: url
- ##Example: http://www.dropbox.com/screenshot.jpg
- [/Screenshots]=============================
- ###########################################
- # Video #
- [Video]====================================
- ##Link to a YouTube.com video.
- ##Format: url
- ##Example: http://www.youtube.com/videolink
- [/Video]===================================
- ###########################################
- # Dependencies #
- [Dependencies]=============================
- ##Include the names of any dependencies here
- ##Format: Dependency
- ##Example: Codea Community
- [/Dependencies]============================
- ############################################
- # Tabs #
- [Tabs]======================================
- ##Select which tabs are to be uploaded.
- ##Keyword 'not' excludes a tab or tabs. Keyword 'add' includes a tab or tabs.
- ##not * will exclude all tabs to allow for individual selection
- ##not *tab1 will look for any tab with tab1 on the end.
- ##not tab1* will look for any tab with tab1 at the beginning.
- ##Format: (add/not)(*)tab(*)
- ##Example: not Main --this will remove main.
- ##Example: not *tab1 --this will remove any tab with "tab1" on the end.
- ##Example: add Main --This will add Main back in.
- [/Tabs]=====================================
- #############################################
- # Assets #
- [Assets]=====================================
- ##Directory, path and url info for any assets besides the standard Codea assets.
- ##Format: Folder:sprite URL
- ##Example: Documents:sprite1 http://www.somewebsite.com/img.jpg
- [/Assets]====================================
- ]]
- --# uitest
- uit = window(500,300,150,40,"uitest")
- uit.i = readImage("Documents:display")
- local b = uit:button(5, 5, 140, 16, "Filebrowser",
- function() uit:filebrowser(
- function(f) print(file.open(f).contents) end
- ) end
- )
- function uit.main()
- b:draw()
- if uit.selectedfile then
- textMode(CORNER)
- text("File: " .. uit.selectedfile, 5, 25)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement