Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea in Codea with built in examples

edited March 2012 in General Posts: 622

http://pastebin.com/HTng1SDV

Inspired by @Sciquest http://twolivesleft.com/Codea/Talk/discussion/691/using-codea-to-teach-programming-update:-codea-programming-class-starts-monday#Item_13

Based on @Simeon Codea in Codea http://twolivesleft.com/Codea/Talk/discussion/660/codea-written-in-codea#Item_16

I hacked in a few lines to have instant Codea have a few examples (don't get too excited, only 2 entries, just a proof of concept)

Some other alternatives would be a character for dialog about what is shown and/or a text shadow feature to show what to type.

With some work this could be one of the examples in Codea to cover short snippets of code examples and/or the star of Codea Learn, a free app that can instantly execute small bits of Codea Lua code.

Maybe it could go along with the future Learn to code in Codea iBook by @Frosty

Comments

  • Posts: 40

    Hey @Ipad41001 is @Frosty 's book on the market

  • Posts: 159

    Hi Michael

    Nope, it's still only really just an idea. I've done one introductory chapter, but it still needs work. Sorry! :)

  • Posts: 40

    @frosty ok I wish you well on your book let me know when it's finished I can't wait to read it :) :)

  • Posts: 622

    Added some to this

    Samples = class()
    
    function Samples:init()
        self.ex = {}
        self.i = 0
        local nl = "\n"
        self.ex[1] = "text(\"Hello World\",300,500)"
        self.ex[2] = "--two dahes is a comment and does nothing" .. nl .. self.ex[1]
        self.ex[2] = self.ex[2] .. nl .. "--the first number moves left or right --x"
        self.ex[2] = self.ex[2] .. nl .. "--the second number moves up or down --y"
        self.ex[2] = self.ex[2] .. nl .. "--try changing the text or the numbers"
        self.ex[3] = "--this line fill circles" .. nl
        self.ex[3] = self.ex[3] .. "--the first number is how red" .. nl
        self.ex[3] = self.ex[3] .. "--the second number is how green" .. nl
        self.ex[3] = self.ex[3] .. "--the third number is how blue" .. nl
        self.ex[3] = self.ex[3] .. "fill(255,0,0)" .. nl
        self.ex[3] = self.ex[3] .. "--this line draws a circle" ..nl
        self.ex[3] = self.ex[3] .. "ellipse(300,500,100,100)" .. nl
        self.ex[3] = self.ex[3] .. "--the first two numbers control the position like text --x,y" ..nl
        self.ex[3] = self.ex[3] .. "--the third number is how wide -w" ..nl
        self.ex[3] = self.ex[3] .. "--the forth number is how tall (height) -h" ..nl
        self.ex[4] = "--fill works on rectangles too" .. nl
        self.ex[4] = self.ex[4] .. "fill(0,0,255)" .. nl
        self.ex[4] = self.ex[4] .. "--this line draws a rectangle" ..nl
        self.ex[4] = self.ex[4] .. "rect(300,500,100,200)" .. nl
        self.ex[4] = self.ex[4] .. "--the numbers for rect work just like ellipse"
        self.ex[5] = "--we can draw lines as well" .. nl
        self.ex[5] = self.ex[5] .. "--we call them strokes, this makes them thicker" .. nl
        self.ex[5] = self.ex[5] .. "strokeWidth(5)" .. nl
        self.ex[5] = self.ex[5] .. "fill(255,0,0)" .. nl
        self.ex[5] = self.ex[5] .. "ellipse(300,500,100,100)"
        self.ex[6] = "--we can change the color of strokes, just like fill" .. nl
        self.ex[6] = self.ex[6] .. "stroke(0,0,255)" .. nl
        self.ex[6] = self.ex[6] .. "strokeWidth(5)" .. nl
        self.ex[6] = self.ex[6] .. "fill(255,0,0)" .. nl
        self.ex[6] = self.ex[6] .. "ellipse(300,500,100,100)"
        self.ex[7] = "--this works on rect too" .. nl
        self.ex[7] = self.ex[7] .. "stroke(255,0,0)" .. nl
        self.ex[7] = self.ex[7] .. "strokeWidth(5)" .. nl
        self.ex[7] = self.ex[7] .. "fill(0,0,255)" .. nl
        self.ex[7] = self.ex[7] .. "rect(300,500,100,200)" .. nl
        self.ex[8] = "--we can also just draw lines" .. nl
        self.ex[8] = self.ex[8] .. "stroke(255,0,0)" .. nl
        self.ex[8] = self.ex[8] .. "strokeWidth(5)" .. nl
        self.ex[8] = self.ex[8] .. "line(300,500,400,600)" .. nl
        self.ex[8] = self.ex[8] .. "--the first two numbers control the position like text --x,y" .. nl
        self.ex[8] = self.ex[8] .. "--that is the position where the line starts" .. nl
        self.ex[8] = self.ex[8] .. "--the second two numbers are where the line ends --x,y" .. nl
        self.max = 8
    end
    
    function Samples:next()
        if self.i ~= self.max then self.i = self.i + 1 end
        return self.ex[self.i]
    end
    
    function Samples:prev()
        if self.i ~= 1 then self.i = self.i - 1 end
        return self.ex[self.i]
    end
    
  • Posts: 622

    The above video is now available when you order the YouTube collection

  • edited April 2012 Posts: 2,820

    I don't know why I didn't come across this idea before - Would people like if I altered the code the use my File IO hack and can alter, run, and create other projects? 7 votes and I will, or take the project from me. Mabey make a Codea rival in Codea...
    LMK if you want to help, if your doing it, or if you like the idea!
    Edit: Whoops - I meant to put this on the actual Codea writen in Codea thread...

Sign In or Register to comment.