Advertisement
Guest User

Flashcards 4 Codea (v1.0)

a guest
Sep 7th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.12 KB | None | 0 0
  1. --# Flashcards
  2. -- This is where you edit your flashcards...
  3. -- If enough people actually want me to, I will add that you can edit them from inside the app
  4. -- I will also make it so it is more interesting to learn (like other flashcard apps)
  5. -- Adding or Removing from this list should still keep it working, if it doesn't let me know
  6. -- Make sure you have the same amount of questions and answers! (there will be an error otherwise)
  7. -- Thanks for trying this out! It is my first completed app!
  8.  
  9. Questions={ "Q1",
  10.             "Q2",
  11.             "Q3",
  12.             "Q4",
  13.             "Q5",
  14.             "Q6",
  15.             "Q7",
  16.             "Q8",
  17.             "Q9",
  18.             "Q10"}
  19.  
  20. Answers={   "A1",
  21.             "A2",
  22.             "A3",
  23.             "A4",
  24.             "A5",
  25.             "A6",
  26.             "A7",
  27.             "A8",
  28.             "A9",
  29.             "A10"}
  30.  
  31. --# Main
  32. function setup()
  33.     --Check Q/A for errors
  34.     print("Checking Cards...")
  35.     if #Questions ~= #Answers then
  36.         error("There are not the same amount of questions and answers. Please review.")
  37.     else
  38.     end
  39.     print("Check Complete!")
  40.     --Load Theme
  41.     loadTheme()
  42.     --Download Icon
  43.     if readImage("Project:Icon") == nil then
  44.         http.request("https://www.dropbox.com/s/b5rsxdikj9o7xc5/flashcardsicon.png?dl=1",
  45.         function(image)
  46.             saveImage("Project:Icon",image)
  47.         end)
  48.     end
  49.     --Flashcard Stuff
  50.     flashcard = {}
  51.     flashcard.no=1
  52.     flashcard.side=false
  53.     flashcard.shuffle=false
  54.     flashcard.shufftext="Off"
  55.     flashcard.default=false
  56.     flashcard.deftext="Q"
  57.     --Display
  58.     displayMode(FULLSCREEN_NO_BUTTONS)
  59.     showCard = true
  60. end
  61.  
  62. function draw()
  63.     Time=os.date("%H"..":".."%M")
  64. -------------------------------------------------------------------------------------------------------------
  65. ---------------------------------------------- Normal Screen ------------------------------------------------
  66. -------------------------------------------------------------------------------------------------------------
  67.     if showCard then
  68.         --Stuff
  69.         fontSize(20)
  70.         font("ArialRoundedMTBold")
  71.         textAlign(CENTER)
  72.         textWrapWidth(475)
  73.        
  74.         --Background
  75.         background(255)
  76.         sprite("Cargo Bot:Background Fade",512,384,1024,768)
  77.         fill(theme.back)
  78.         noStroke()
  79.         rect(-1,-1,1030,790)
  80.        
  81.         --Flashcard Color
  82.         fill(255)
  83.         stroke(0)
  84.         strokeWidth(2)
  85.         rect(212,200,612,500)
  86.        
  87.         --Buttons
  88.         fill(theme.button.fill)
  89.         stroke(theme.button.stroke)
  90.         if flashcard.shuffle==false then
  91.             rect(262,125,100,50)
  92.             rect(674,125,100,50)
  93.         else
  94.             rect(412,125,200,50)
  95.         end
  96.         rect(242,50,140,50)
  97.         rect(654,50,140,50)
  98.         rect(0,718,101,50)
  99.        
  100.         --Button Text
  101.         fill(theme.text)
  102.         if flashcard.shuffle==false then
  103.             text("Previous",312,150)
  104.             text("Next",724,150)
  105.             text("Card "..flashcard.no.." out of "..#Questions,512,150)
  106.         else
  107.             text("Next Card",512,150)
  108.         end
  109.         text("Options",50,743)
  110.         text("Shuffle: "..flashcard.shufftext,312,75)
  111.         text("Default: "..flashcard.deftext,724,75)
  112.         textWrapWidth(500)
  113.         text("Tap the card to flip!",512,730)
  114.        
  115.         --Take a Guess
  116.         text(Time,990,750)
  117.        
  118.         --Exit Button
  119.         fill(theme.exit.fill)
  120.         stroke(theme.exit.stroke)
  121.         rect(462,50,100,50)
  122.         fill(theme.exit.text)
  123.         text("Exit",512,75)
  124.        
  125.         --Extra Flashcard Studd
  126.         if flashcard.no > #Questions then
  127.             flashcard.no=1
  128.         elseif flashcard.no == 0 then
  129.             flashcard.no=#Questions
  130.         end
  131.        
  132.         --Flashcard Text
  133.         fontSize(14)
  134.         fill(209, 209, 209, 255)
  135.         if flashcard.side==false then
  136.             text("Question",512,675)
  137.         else
  138.             text("Answer",512,675)
  139.         end
  140.         fill(0, 0, 0, 255)
  141.         fontSize(30)
  142.         if flashcard.side==false then
  143.             text((Questions[flashcard.no]),512,450)
  144.         else
  145.             text((Answers[flashcard.no]),512,450)
  146.         end
  147.        
  148.         --Shuffle Cards
  149.         if flashcard.shuffle==false then
  150.             flashcard.shufftext="Off"
  151.         else
  152.             flashcard.shufftext="On"
  153.         end
  154.        
  155.         --Default Side
  156.         if flashcard.default==true then
  157.             flashcard.deftext="A"
  158.         else
  159.             flashcard.deftext="Q"
  160.         end
  161.        
  162.     else
  163.        
  164. -------------------------------------------------------------------------------------------------------------
  165. ---------------------------------------------- Option Screen ------------------------------------------------
  166. -------------------------------------------------------------------------------------------------------------
  167.        
  168.         --Background
  169.         background(255)
  170.         sprite("Cargo Bot:Background Fade",512,384,1024,768)
  171.         fill(theme.back)
  172.         noStroke()
  173.         rect(-1,-1,1030,790)
  174.        
  175.         --Themes
  176.         fill(0)
  177.         rect(-1,550,1026,50)
  178.         fill(255, 0, 0, 255)
  179.         rect(242,555,40)
  180.         fill(255, 118, 0, 255)
  181.         rect(342,555,40)
  182.         fill(255, 228, 0, 255)
  183.         rect(442,555,40)
  184.         fill(49, 255, 0, 255)
  185.         rect(542,555,40)
  186.         fill(0, 93, 255, 255)
  187.         rect(642,555,40)
  188.         fill(209, 0, 255, 255)
  189.         rect(742,555,40)
  190.        
  191.         --Text
  192.         fill(255)
  193.         fontSize(30)
  194.         text("Options",512,725)
  195.         fontSize(25)
  196.         text("Theme",512,625)
  197.         fontSize(20)
  198.         text("Current Theme: "..theme.name,512,525)
  199.        
  200.         --Yet Again
  201.         text(Time,990,750)
  202.        
  203.         --Return Button
  204.         fill(theme.button.fill)
  205.         stroke(theme.button.stroke)
  206.         strokeWidth(2)
  207.         rect(0,718,101,50)
  208.         fill(theme.text)
  209.         text("Return",50,743)
  210.        
  211.         --About
  212.         fill(255)
  213.         fontSize(25)
  214.         text("About",512,475)
  215.         fontSize(20)
  216.         text("Created by Jonathon Gaczol\nThis is just a simple flashcards app for your simple flashcards. It was originally created for preparing for my German Oral exam but I decided to continue to work on it.\n\nPlease Note:\nI know the themes aren't the greatest so please PM if you have any better ideas, or just anything that I should incorporate into this. Thanks :)",512,340)
  217.        
  218.         --Version
  219.         fontSize(25)
  220.         text("Version",512,175)
  221.         fontSize(20)
  222.         text("1.0",512,150)
  223.     end  
  224. end
  225.  
  226. function touched(touch)
  227.     if touch.state==ENDED then
  228.         --Normal Screen
  229.         if showCard then
  230.             if touch.x > 462 and touch.x < 562 and
  231.             touch.y > 50 and touch.y < 100 then
  232.                 exit()
  233.                
  234.             elseif touch.x > 212 and touch.x < 824 and
  235.             touch.y > 200 and touch.y < 700 then
  236.                 flashcard.side = not flashcard.side
  237.                
  238.             elseif touch.x > 262 and touch.x < 362 and
  239.             touch.y > 125 and touch.y < 175 and flashcard.shuffle==false then
  240.                 flashcard.no=flashcard.no-1
  241.                 Defaultcard()
  242.                
  243.             elseif touch.x > 674 and touch.x < 774 and
  244.             touch.y > 125 and touch.y < 175 and flashcard.shuffle==false then
  245.                 flashcard.no=flashcard.no+1
  246.                 Defaultcard()
  247.                
  248.             elseif touch.x > 242 and touch.x < 382 and
  249.             touch.y > 50 and touch.y < 100 then
  250.                 flashcard.shuffle = not flashcard.shuffle
  251.                 randomcard()
  252.                 Defaultcard()
  253.                
  254.             elseif touch.x > 412 and touch.x < 612 and
  255.             touch.y > 125 and touch.y < 175 and flashcard.shuffle==true then
  256.                 randomcard()
  257.                 Defaultcard()
  258.                
  259.             elseif touch.x > 654 and touch.x < 794 and
  260.             touch.y > 50 and touch.y < 100 then
  261.                 flashcard.default = not flashcard.default
  262.                
  263.             elseif touch.x > 0 and touch.x < 100 and
  264.             touch.y > 718 then
  265.                 showCard=false
  266.             end
  267.            
  268.         --Option Screen
  269.         elseif not showCard then
  270.            
  271.             if touch.x > 242 and touch.x < 282 and
  272.             touch.y > 555 and touch.y < 595 then
  273.                 saveLocalData("theme.name","Red")
  274.                 loadTheme()
  275.                
  276.             elseif touch.x > 342 and touch.x < 382 and
  277.             touch.y > 555 and touch.y < 595 then
  278.                 saveLocalData("theme.name","Orange")
  279.                 loadTheme()
  280.                
  281.             elseif touch.x > 442 and touch.x < 482 and
  282.             touch.y > 555 and touch.y < 595 then
  283.                 saveLocalData("theme.name","Yellow")
  284.                 loadTheme()
  285.                
  286.             elseif touch.x > 542 and touch.x < 582 and
  287.             touch.y > 555 and touch.y < 595 then
  288.                 saveLocalData("theme.name","Green")
  289.                 loadTheme()
  290.                
  291.             elseif touch.x > 642 and touch.x < 682 and
  292.             touch.y > 555 and touch.y < 595 then
  293.                 saveLocalData("theme.name","Blue")
  294.                 loadTheme()
  295.                
  296.             elseif touch.x > 742 and touch.x < 782 and
  297.             touch.y > 555 and touch.y < 595 then
  298.                 saveLocalData("theme.name","Magenta")
  299.                 loadTheme()
  300.                
  301.             elseif touch.x > 0 and touch.x < 100 and
  302.             touch.y > 718 then
  303.                 showCard=true
  304.                
  305.             end
  306.         end
  307.     end
  308. end
  309.  
  310. --Pick a Random Card
  311. function randomcard()
  312.     if flashcard.shuffle==true then
  313.         flashcard.no=math.random(1,#Questions)
  314.     else
  315.     end
  316. end
  317.  
  318. --Default Flashcard Side
  319. function Defaultcard()
  320.     if flashcard.default==false then
  321.         flashcard.side=false
  322.     else
  323.         flashcard.side = true
  324.     end
  325. end
  326.  
  327. --Obvious I Hope
  328. function exit()
  329.     saveLocalData("theme.name",theme.name)
  330.     close()
  331. end
  332.  
  333. --# Themes
  334. function loadTheme()
  335.     theme = {}
  336.     theme.name = readLocalData("theme.name","Blue")
  337.     if theme.name == "Blue" then
  338.     --Background
  339.     theme.back = color(0, 246, 255, 135)
  340.     --Exit Button
  341.     theme.exit = {}
  342.     theme.exit.fill = color(89, 82, 232, 255)
  343.     theme.exit.stroke = color(30,25,159,255)
  344.     theme.exit.text = color(25, 28, 155, 255)
  345.     --Other Buttons
  346.     theme.button = {}
  347.     theme.button.fill = color(0, 137, 255, 226)
  348.     theme.button.stroke = color(0,85,255,355)
  349.     --Misc
  350.     theme.text = color(10, 0, 255, 255)
  351.     elseif theme.name == "Red" then
  352.     --Background
  353.     theme.back = color(255, 0, 0, 81)
  354.     --Exit Button
  355.     theme.exit = {}
  356.     theme.exit.fill = color(255, 9, 0, 116)
  357.     theme.exit.stroke = color(206, 16, 14, 255)
  358.     theme.exit.text = color(255, 13, 0, 255)
  359.     --Other Buttons
  360.     theme.button = {}
  361.     theme.button.fill = color(255, 6, 0, 113)
  362.     theme.button.stroke = color(255, 20, 0, 255)
  363.     --Misc
  364.     theme.text = color(255, 0, 5, 255)
  365.     elseif theme.name == "Orange" then
  366.     --Background
  367.     theme.back = color(255, 117, 0, 135)
  368.     --Exit Button
  369.     theme.exit = {}
  370.     theme.exit.fill = color(206, 106, 14, 154)
  371.     theme.exit.stroke = color(255, 106, 0, 255)
  372.     theme.exit.text = color(255, 118, 0, 255)
  373.     --Other Buttons
  374.     theme.button = {}
  375.     theme.button.fill = color(209, 107, 13, 226)
  376.     theme.button.stroke = color(255, 134, 0, 255)
  377.     --Misc
  378.     theme.text = color(255, 168, 0, 255)
  379.     elseif theme.name == "Yellow" then
  380.     --Background
  381.     theme.back = color(255, 249, 0, 135)
  382.     --Exit Button
  383.     theme.exit = {}
  384.     theme.exit.fill = color(185, 173, 19, 255)
  385.     theme.exit.stroke = color(255, 253, 0, 255)
  386.     theme.exit.text = color(255, 235, 0, 255)
  387.     --Other Buttons
  388.     theme.button = {}
  389.     theme.button.fill = color(203, 197, 15, 255)
  390.     theme.button.stroke = color(255, 248, 0, 255)
  391.     --Misc
  392.     theme.text = color(239, 255, 0, 255)
  393.     elseif theme.name == "Green" then
  394.     --Background
  395.     theme.back = color(60, 255, 0, 135)
  396.     --Exit Button
  397.     theme.exit = {}
  398.     theme.exit.fill = color(60, 185, 18, 255)
  399.     theme.exit.stroke = color(35, 255, 0, 255)
  400.     theme.exit.text = color(49, 255, 0, 255)
  401.     --Other Buttons
  402.     theme.button = {}
  403.     theme.button.fill = color(45, 203, 14, 255)
  404.     theme.button.stroke = color(36, 255, 0, 255)
  405.     --Misc
  406.     theme.text = color(54, 255, 0, 255)
  407.     elseif theme.name == "Magenta" then
  408.     --Background
  409.     theme.back = color(183, 0, 255, 135)
  410.     --Exit Button
  411.     theme.exit = {}
  412.     theme.exit.fill = color(197, 0, 255, 132)
  413.     theme.exit.stroke = color(255, 0, 250, 255)
  414.     theme.exit.text = color(229, 0, 255, 255)
  415.     --Other Buttons
  416.     theme.button = {}
  417.     theme.button.fill = color(171, 13, 203, 255)
  418.     theme.button.stroke = color(255, 0, 238, 255)
  419.     --Misc
  420.     theme.text = color(255, 0, 252, 255)
  421.     end
  422. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement