<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with image - Codea</title>
      <link>http://twolivesleft.com/Codea/Talk/discussions/tagged/image/feed.rss</link>
      <pubDate>Sun, 26 May 13 05:26:28 -0400</pubDate>
         <description>Tagged with image - Codea</description>
   <language>en-CA</language>
   <atom:link href="/Codea/Talk/discussions/taggedimage/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>save image to camera roll options</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/2660/save-image-to-camera-roll-options</link>
      <pubDate>Fri, 26 Apr 2013 16:19:42 -0400</pubDate>
      <dc:creator>jasl</dc:creator>
      <guid isPermaLink="false">2660@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Hey.. I found info on how to save images back into spritepack folders which is super useful but I have created an app where I would like to be able to offer the option of making an on screen gesture save a screen shot and open a dialogue to email or post an image to a specific location.
I have found out how to do this in Xcode but now my question is how to implement that code with my Codea app? I am not a proficient coder and haven't tried hacking it as I don't fully understand how or if it is possible to segue together Codea (Lua) and Xcode in a relatively simple way?
Any suggestions on what to research and where to start with this would be very welcome.
Thanks - J</p>
]]></description>
   </item>
   <item>
      <title>Utility: reproduce an image in code</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/2296/utility%3A-reproduce-an-image-in-code</link>
      <pubDate>Mon, 25 Feb 2013 08:50:15 -0500</pubDate>
      <dc:creator>Ignatz</dc:creator>
      <guid isPermaLink="false">2296@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>It may be convenient to encode some images (ie use code to draw them) rather than having to include them separately. This utility creates the code to reproduce any image within reason. It uses RLE compression so is quite efficient, but could be improved if there was demand for it.</p>

<p><a href="http://pastebin.com/embed_js.php?i=9BJvrPJt" target="_blank" rel="nofollow">http://pastebin.com/embed_js.php?i=9BJvrPJt</a></p>

<p>Don't be put off by the size of the code provided, there are some big examples that take up most of the space!</p>

<p>Comments and suggestions welcome, I am still learning.</p>
]]></description>
   </item>
   <item>
      <title>Can you create an image from a jpg file using image(filename)?</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/2439/can-you-create-an-image-from-a-jpg-file-using-image-filename</link>
      <pubDate>Thu, 14 Mar 2013 00:34:53 -0400</pubDate>
      <dc:creator>UberGoober</dc:creator>
      <guid isPermaLink="false">2439@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Can you create an image from a jpg file using image(filename)?</p>

<p>Reason is I want to be able to detect size of a sprite based on the arbitrary jpg it's made from.  Thought if I used the jpg to make an image instance, I could use image.width and image.height for the purpose. No?</p>
]]></description>
   </item>
   <item>
      <title>Tutorial 26 - RLE Compression for Spritely Images</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/2295/tutorial-26-rle-compression-for-spritely-images</link>
      <pubDate>Mon, 25 Feb 2013 05:16:13 -0500</pubDate>
      <dc:creator>Reefwing</dc:creator>
      <guid isPermaLink="false">2295@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Todays tutorial is brought to you courtesy of <a rel="nofollow" href="/Codea/Talk/profile/Ignatz">@Ignatz</a> from the lovely city of Perth (the most remote city on Earth according to Bill Bryson). He noted that Spritely (the image editor which comes with Codea) produces some fairly large and unwieldy image files. Given his background in compression he immediately worked out a way to dramatically reduce these files in size and is happy to share his coding and decoding classes.</p>

<p>As an example, running this compression on the images used in MineSweeper created files 28 times smaller. You can see the tutorial here: <a href="http://codeatuts.blogspot.com.au/2013/02/tutorial-26-rle-image-compression-for.html" target="_blank" rel="nofollow">http://codeatuts.blogspot.com.au/2013/02/tutorial-26-rle-image-compression-for.html</a></p>

<p>Comments welcome as always.</p>

<p>.<a rel="nofollow" href="/Codea/Talk/profile/Mark">@Mark</a> - maybe you could build this into the next version of Spritely?</p>
]]></description>
   </item>
   <item>
      <title>Rotating a sprite</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/2096/rotating-a-sprite</link>
      <pubDate>Wed, 16 Jan 2013 14:57:38 -0500</pubDate>
      <dc:creator>edat44</dc:creator>
      <guid isPermaLink="false">2096@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>I have a sprite that needs to be rotated at a custom angle. I know there is a math.rotate() function, but can this function be transferred to a sprite or image? I need to be able to individually rotate many sprites, all at custom rotations. Finding the right rotation value will be difficult in it self, but I want to know how rotating sprites works before I get started.</p>
]]></description>
   </item>
   <item>
      <title>image.clear() ?</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/858/image-clear</link>
      <pubDate>Sun, 22 Apr 2012 04:21:05 -0400</pubDate>
      <dc:creator>frosty</dc:creator>
      <guid isPermaLink="false">858@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Is there any way that I've missed to clear an image? I need to update an image every frame, and it contains transparent areas so I can't just draw over the top. I'd ideally like to be able to blank it down and start again, much the way the main draw loop works.</p>

<p>If not, is there any chance this could be added in a future update?</p>
]]></description>
   </item>
   <item>
      <title>http.request + Google Static Map API</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1758/http-request-google-static-map-api</link>
      <pubDate>Wed, 03 Oct 2012 09:45:20 -0400</pubDate>
      <dc:creator>Mark</dc:creator>
      <guid isPermaLink="false">1758@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>I'm probably the last person in the world to figure this out.  But just in case, give this a try...</p>

<pre><code>displayMode(FULLSCREEN)

function setup()
    map = nil
    http.request('<a href="http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=400x400&amp;sensor=false'" target="_blank" rel="nofollow">http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=400x400&amp;sensor=false'</a>, didGetImage)
end

function didGetImage(theImage, status, head)
    map = theImage
end

function draw()
    background(226, 226, 226, 255)
    if map ~= nil then
        sprite(map, WIDTH/2, HEIGHT/2)
    end
end
</code></pre>

<p>Pretty spiffy. And if you look at the static maps API, you'll find there's a lot you can do with it.</p>

<p>Now, imagine if we had the compass heading and GPS values.  We'd be well on our way to our own Codea-based mapping tool.</p>
]]></description>
   </item>
   <item>
      <title>Golden Angle: an experiment with phi, large images and HSV</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1732/golden-angle%3A-an-experiment-with-phi-large-images-and-hsv</link>
      <pubDate>Fri, 28 Sep 2012 16:28:16 -0400</pubDate>
      <dc:creator>mpilgrem</dc:creator>
      <guid isPermaLink="false">1732@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>The code below, for Codea version 1.4.6(15), creates a rotating coloured background with a hypnotic dynamic.</p>

<p>The background is made up of four <code>image</code> panes, because of the limitation in rendering to large images discussed <a rel="nofollow" href="http://twolivesleft.com/Codea/Talk/discussion/comment/14196#Comment_14196">here</a>. To keep things simple, the background pattern is drawn four times, each time being clipped to one of the panes. With <code>displayMode(STANDARD)</code>, hairline gaps appear between the panes that spoil the effect. They disappear with <code>displayMode(FULLSCREEN)</code>.</p>

<p>The colouring makes use of the relationship between <a rel="nofollow" href="http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV">HSV and RGB</a> to create a spectrum.</p>

<p>The pattern is based on the <a rel="nofollow" href="http://en.wikipedia.org/wiki/Golden_angle">golden angle</a> and <a rel="nofollow" href="http://www.sciencedirect.com/science/article/pii/0025556479900804">Helmut Vogel's construction of the sunflower head</a>(<a rel="nofollow" href="http://en.wikipedia.org/wiki/Fermat%27s_spiral">Fermat's spiral</a>).</p>

<pre>
--
-- Golden Angle
-- 

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
    scale, dot, spin = 6, 10, 24
    local pi2 = 2 * math.pi
    local phi = (1 + math.sqrt(5)) / 2 -- Golden ratio
    local ga = pi2 / phi ^ 2           -- Golden angle (radians)
    w2, h2 = WIDTH / 2, HEIGHT / 2
    local radius = math.sqrt(w2 * w2 + h2 * h2)
    local max = (radius / scale) ^ 2   -- Number of dots
    len2 = (radius * 2 + dot) / 2      -- Size of each quarter tile
    img, ox, oy = {}, {}, {}
    for j = 0, 3 do
        img[j] = image(len2, len2)
        setContext(img[j])
        ox[j] = -(j % 2) * len2
        oy[j] = -(1 - math.floor(j / 2)) * len2
        local ang = 0
        for i = 1, max do 
            local l = math.sqrt(i) * scale
            local x, y = l * math.cos(ang), l * math.sin(ang)
            local r, g, b = H2RGB(l / radius)
            fill(r, g, b)
            ellipse(x - ox[j], y - oy[j], dot)
            ang = (ang + ga) % pi2
        end
        setContext()
    end
    spriteMode(CORNER)
end

function draw()
    background(0)
    translate(w2, h2)
    rotate(ElapsedTime * spin % 360)
    for i = 0, 3 do sprite(img[i], ox[i], oy[i]) end
end

-- Hue (nil or [0, 1)) to RGB; (S = 1, V = 1)
function H2RGB(h)
    if not h then return 0, 0, 0 end
    local r, g, b
    local h1 = h * 6
    local x = (1 - math.abs(h1 % 2 - 1))
    if h1 &lt; 1 then r, g, b = 1, x, 0
    elseif h1 &lt; 2 then r, g, b = x, 1, 0
    elseif h1 &lt; 3 then r, g, b = 0, 1, x
    elseif h1 &lt; 4 then r, g, b = 0, x, 1
    elseif h1 &lt; 5 then r, g, b = x, 0, 1
    elseif h1 &lt; 6 then r, g, b = 1, 0, x end
    return 255 * r, 255 * g, 255 * b
end
</pre>
]]></description>
   </item>
   <item>
      <title>MAPPING an image, is there another way to do that ?</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1730/mapping-an-image-is-there-another-way-to-do-that</link>
      <pubDate>Fri, 28 Sep 2012 12:54:48 -0400</pubDate>
      <dc:creator>letaief</dc:creator>
      <guid isPermaLink="false">1730@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Importing images worked perfectly, Thanks to Simeon for his reply. Now what about performing à mapped image I am about to program à course for my students in whome iI havé curves and at any portion related explanations are givin With possible links to web pages. I am about to put the curves as background images, to delineate portions on m'y curves and by searching using image.get the color I will get m'y maps. is there an other issue?</p>
]]></description>
   </item>
   <item>
      <title>Simple question</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1487/simple-question</link>
      <pubDate>Tue, 07 Aug 2012 01:54:32 -0400</pubDate>
      <dc:creator>eloi67</dc:creator>
      <guid isPermaLink="false">1487@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>How can I set an image in background ?
Thanks</p>
]]></description>
   </item>
   <item>
      <title>Image distortion</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1238/image-distortion</link>
      <pubDate>Fri, 22 Jun 2012 13:34:21 -0400</pubDate>
      <dc:creator>MurielleG</dc:creator>
      <guid isPermaLink="false">1238@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Clumsy attempt to use a grid mesh to distort an image.</p>

<h1>Main (part 1 of 3)</h1>

<pre><code>dothidden=false

function setup()
    saveProjectInfo("Description","Distort picture using a grid mesh")
    
    print("2 finger tap --- toggle full screen")
    print("1 finger tap --- toggle control points")
    print("Move Points to distort")
    
    touches=0
    gesture=0
    
    -- pFIXBORDERS=false 
    FIXBORDERS = false -- Border points are movable
    
    pnX=1 -- n columns
    iparameter("nX",2,16,4)
    pnY=1 -- n rows
    iparameter("nY",2,16,4)
    
    pstate=0 -- cumulate distortion
    iparameter("Savestate",0,1,0)
    
    iparameter("DoWave",0,1,0) -- apply saw effect
    iparameter("HWave",0,2,0) -- horz 0, vert 1, both 2
    
    iparameter("DoReset",0,1,0) -- reset to prior saved state
    
    ImgW=0
    ImgH=0
    theMesh=mesh()
    ActivePoint=nil
    ActiveId=-1   
    CpGrid={} -- control points
    CpRect={} -- grid cells
    
    -- LOAD YOUR OWN HERE
    -- local BaseImg = readImage("Planet Cute:Icon")
    local BaseImg =  CreateMyImage(600,600)
    
    theMesh.texture=BaseImg
    ImgW=BaseImg.width
    ImgH=BaseImg.height
    
    OrigW=ImgW
    OrigH=ImgH
    
    local Tw,Th,Zom=ResizeToFit(ImgW,ImgH,WIDTH,HEIGHT)
    ImgW=Tw
    ImgH=Th
    CreateControlPoints(nX,nY)  
    CreateCells(nX,nY)
    PW=WIDTH
    PH=HEIGHT
end


function touched(touch)
    
    if touch.state == BEGAN then 
        if touches == 0 then gesture=1 end
        touches = touches +  1 
        end
        
    if (not dothidden) and touch.state==BEGAN and touches==1 and ActiveId == -1 then 
        ActivePoint=nil
        local found=false
        for i=1,nX+1 do
            if found == false then 
                for j=1,nY+1 do
                if found == false then 
                    local z = CpGrid[i][j]
                    local dd = (touch.x - z.c.x) ^ 2 + (touch.y - z.c.y) ^ 2
                    if dd &lt; 300 then 
                        found=true
                        if CpGrid[i][j].movable then ActivePoint = CpGrid[i][j] end
                    end
                    end --endif
                end -- end j
            end -- endif
        end -- i
        if ActivePoint ~= nil then ActiveId=touch.id end   
    end
    
    if touch.state==MOVING and ActiveId==touch.id and ActivePoint ~= nil then 
        ActivePoint.c.x=touch.x
        ActivePoint.c.y=touch.y
        end
        
    if touch.state==ENDED then 
        if ActivePoint==nil and touches == 1 and gesture==1 then
            dothidden = (not dothidden)
            gesture=0
            end
         if ActivePoint == nil and touches==2 and gesture==1 then
            local tmode =displayMode()
            if tmode==STANDARD then
                displayMode(FULLSCREEN)
                else
                displayMode(STANDARD)
                end
            gesture=0
            end
            
        touches = touches - 1
        if touches==0 then gesture=0 end
        ActivePoint=nil
        ActiveId=-1
        end
        
end -- function
    
function ResetPoints()      
    for i=1,nX+1 do
        for j=1,nY+1 do
            local tobj = CpGrid[i][j]
            local tx=tobj.i.x * ImgW
            local ty=tobj.i.y * ImgH
            if tobj.movable then
                tobj.c.x=tx
                tobj.c.y=ty
                end
        end
    end
end
        
function draw()
    
    -- Resize picture for orientation or FullScreen
    if PW ~= WIDTH or PH~=HEIGHT then
       resetSize()
       PW=WIDTH
       PH=HEIGHT
       end
        
    -- change of rows columns 
    if pnX ~= nX or pnY ~= nY then
        InitGrids()
        pnX=nX
        pnY=nY
        end
    
    -- reset to last saved state    
    if DoReset==1 then
        DoReset=0
        ResetPoints()
        end
        
    -- apply saw to control points    
    if DoWave == 1 then
        Dowave=0
        local inc = 0.50
        for i=1,nX+1 do
        for j=1,nY+1 do
            
            local tobj = CpGrid[i][j]
            local tx=tobj.c.x
            local ty=tobj.c.y
            
            if HWave == 0 and nX &gt; 3 and nY &gt; 3 then -- horizontal
                if i%2 == 0 and j &gt; 1 then ty = ty + inc end
            end
            if HWave == 1 and nX &gt; 3 and nY &gt; 3 then -- vertical
                if j%2 == 0 and i &gt; 1 then tx = tx + inc end
            end
            if HWave == 2 and nX &gt; 3 and nY &gt; 3 then -- both
                if i%2 == 0 then tx = tx + inc end
                if j%2 == 0 then ty = ty + inc end
            end
            
            if tx &lt; 0 then tx = 0 end
            if tx &gt; WIDTH then tx = WIDTH end
            if ty &lt; 0 then ty = 0 end
            if ty &gt; HEIGHT then ty = HEIGHT end
            
            if tobj.movable then
                tobj.c.x=tx
                tobj.c.y=ty
                end 
            end
        end
        
        DoWave=0
        end
    
    if Savestate ~= pstate and Savestate == 1 then
        ApplyAndContinue()
        InitGrids()
        Savestate=0
        pstate=Savestate
        end
    
    background(40, 40, 40)
    fill(255,255,255,255)

    for i=1,nX do
        for j=1,nY do
            local z = CpRect[i][j]
            z:draw(theMesh)
        end
    end
    
    for i=1,nX+1 do
    for j=1,nY+1 do
    local z = CpGrid[i][j]
    z:draw()
    end
    end
    
end
</code></pre>
]]></description>
   </item>
   <item>
      <title>I have just published &quot;StripGrid&quot;, an Image Selector library for Codea projects</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1318/i-have-just-published-stripgrid-an-image-selector-library-for-codea-projects</link>
      <pubDate>Sat, 07 Jul 2012 13:44:46 -0400</pubDate>
      <dc:creator>LightDye</dc:creator>
      <guid isPermaLink="false">1318@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I've been working on a project in Codea and I had to code an image selector for my project. Since this functionality is quite generic and it can be useful for other people / projects, I want to share it. Suggestions and bug reports or fixes are welcome. I published the code here:</p>

<p><a href="https://bitbucket.org/jortizg/stripgrid/src" target="_blank" rel="nofollow">https://bitbucket.org/jortizg/stripgrid/src</a></p>

<p>Please explore the Main file for options. I tried to make it quite flexible and generic, so it is not limited to sprites. It can be used to display any content in a grid with the ability to browse it swiping horizontally or vertically.</p>

<p></p><div class="Video"><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/jHD_nu9c64o&amp;hl=en_US&amp;fs=1&amp;" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed src="http://www.youtube.com/v/jHD_nu9c64o&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" width="640" height="385" /></object></div>
]]></description>
   </item>
   <item>
      <title>Disabling the image resizing anti-alias.</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/1119/disabling-the-image-resizing-anti-alias</link>
      <pubDate>Thu, 31 May 2012 11:27:37 -0400</pubDate>
      <dc:creator>oddgoo</dc:creator>
      <guid isPermaLink="false">1119@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Greetings!</p>

<p>I am new here and already my eyes are wide open with excitement about this tool. I was wondering if it's possible to disable the anti-aliasing that occurs when you resize an image (for style purposes), either in the app or tinkering around with the runtime library on the mac.</p>

<p>Thanks in advance for your help!</p>
]]></description>
   </item>
   <item>
      <title>Pic v1 is uploaded - draw into images</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/296/pic-v1-is-uploaded-draw-into-images</link>
      <pubDate>Sat, 10 Dec 2011 03:20:42 -0500</pubDate>
      <dc:creator>Bortels</dc:creator>
      <guid isPermaLink="false">296@/Codea/Talk/discussions</guid>
      <description><![CDATA[So - I have this fault where nothing ever is "done" - I will tweak things forever if I'm allowed to. <br /><br />In the spirit of trying to break that habit, I present Pic version 1. <br /><br /><a href="http://bortels.posterous.com/pic-v1" target="_blank" rel="nofollow">http://bortels.posterous.com/pic-v1</a><br /><br />Pic is a wrapper library for Codea's image() call that adds line drawing, regular n-gons, irregular polygons, and filled irregular polygons. Missing but planned to be added are filled regular polygons, flood fill, pseudo-3D Sphere drawing, and whatever else my fevered mind comes up with. I am open to suggestions, constructive criticism, and patches. <br /><br />See the Main tab for examples of use, and the ugliest moose evar. Yes, it's a moose. Or it's supposed to be. I've been sick, let's see you do better doped up on painkillers from a root canal. It used to be an upside-down moose, but Simeon fixed that accidentally :-)<br /><br />I chose Pic because image was already in use. and because it's short. I'm not 100% happy with the name, open to better suggestions. <br /><br />Note the calling convention is generally to pass a table with named parameters, *or* a bunch of arguments - both should work, and missing arguments will be filled with reasonable defaults when possible. <br /><br />Note also that when fill() starts returning current fill colors, I'll be defaulting to those when you make a Pic object rather than boring old white.]]></description>
   </item>
   <item>
      <title>Mesh textures</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/821/mesh-textures</link>
      <pubDate>Mon, 02 Apr 2012 02:34:38 -0400</pubDate>
      <dc:creator>rashedlatif</dc:creator>
      <guid isPermaLink="false">821@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>I got a query. Is it possible to texturize a mesh object with an image object? I tried but failed to do. If its possible can some one give an example code to show how to do it?</p>
]]></description>
   </item>
   <item>
      <title>Basic MathStudio type app</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/788/basic-mathstudio-type-app</link>
      <pubDate>Tue, 20 Mar 2012 08:34:41 -0400</pubDate>
      <dc:creator>rashedlatif</dc:creator>
      <guid isPermaLink="false">788@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Tried to write a code similar to app called "MathStudio" but with a very basic functionality. I have used Simeon's "Buffer" class here. Thanks Simeon.</p>

<p>Demo:
<object width="640" height="480"><param name="movie" value="http://www.youtube.com/v/stcLLFxwyJw?version=3&amp;hl=en_US&amp;rel=0" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed src="http://www.youtube.com/v/stcLLFxwyJw?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="640" height="480" /></object></p>

<p>Main:</p>

<pre><code>-- Use this function to perform your initial setup
function setup()
    displayMode(STANDARD)
    displayMode(FULLSCREEN)
    screenWidth = 500
    screenHeight = 400
    drawFlag = false
    initFlag = false
    buffer = Buffer()
    xcounter = 0
    result = ""
    errorMsg = ""

    graphTable = {}

    -- Initializing Textfields
    textField = TextField("Formula", 500, 80)
    resultField = TextField("Result", 500,40)
    -- Initializing Buttons
    button = {}
    titles = {"sin()", "cos()", "tan()", "asin()", "acos()", "atan()", "log10()", "log()", "exp()","pow()", "sqrt()", "pi", "+", "-", "*", "/", "%", "(", ")", ",", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",".", "x", "Solve", "Plot", "Clear","Del", "&lt;==", "==&gt;",}

    counter = 1
    for _, v in pairs (titles) do

        if counter &lt; 13 then
            fill(61, 71, 94, 156)
            r,g,b,a = fill()

        elseif counter &gt;= 13 and counter &lt;= 20 then
            fill(61, 113, 31, 155)
            r,g,b,a = fill()

        else 
            fill(0, 0, 0, 160)
            r,g,b,a = fill()

        end
        table.insert(button,Buttons(v,r,g,b,a,255,255,255,255,15,24))
        counter = counter + 1
    end
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(173, 173, 173, 93)

    initializeScreen()

    drawButtons()
    textField.pos = vec2(centerPnt.x,HEIGHT - HEIGHT*0.1)
    textField:draw() 

    resultField.pos = vec2(centerPnt.x,HEIGHT - HEIGHT*0.18)
    resultField:draw() 

    equationStr = buffer:toString()

    if initFlag then  
        generateEquation()
        if equationStr ~= "y=" then
                initializeTable()
                executeEquation()
                result = y
        else
            errorMsg = "Not a valid equation"
        end
    end
    fontSize(16)
    l,t = textSize(result)
    text(result, resultField.pos.x-resultField.size.x/2+l/2+5,resultField.pos.y )
    text(errorMsg,WIDTH*0.2,HEIGHT-HEIGHT*0.1)

    if drawFlag==true and equationStr ~= "y=" then
       drawCurves()
       spriteMode(CENTER)
       sprite(graph,centerPnt.x,centerPnt.y)
    else
        drawFlag=false
    end 
    buffer:draw()
end

function drawButtons()
    left = WIDTH - WIDTH*0.92
    top = HEIGHT - HEIGHT * 0.265
    counter = 1

    for _, b in pairs(button) do
        b.pos = vec2(left,top)
        b:draw()

        left=left+b.size.x+5
        if counter == 4 then
            counter = 1
            left = WIDTH - WIDTH * 0.92
            top = top - b.size.y-5
        else
            counter = counter + 1
        end
    end
end

function touched (touch)

    for _, b in pairs (button) do
        b:touched (touch)
    end    
end
</code></pre>

<p>Buffer:</p>

<pre><code>Buffer = class()

function Buffer:init()
    self.buffer = {}

    self.font = "Inconsolata"
    self.fontSize = 20

    -- x = line, y = pos
    self.cursor = vec2(1,1)

    self.t = 0
    self.cursorBlink = 0
end

function Buffer:setStyle()
    textMode(CORNER)
    font( self.font )
    fill(0, 0, 0, 255)
    fontSize( self.fontSize )
    textWrapWidth(500)
end

function Buffer:cursorToScreen(c)
    -- Get a subset of the buffer
    local lines = table_slice( self.buffer, 1, c.x )
    local l = self.buffer[c.x]

    local upToStr = self:bufferToString(lines)
    local lstr = nil

    if l then
        lstr = table.concat(l)
    end

    pushStyle()

    self:setStyle()

    local lw = 0

    local _,lh = textSize("A")
    local emptyLine = true

    if lstr and lstr ~= "" then
        lw,lh = textSize(string.sub(lstr,1,c.y - 1))
        emptyLine = false
    end

    local pw,ph = textSize(upToStr)

    if emptyLine then
        ph = ph + lh
    end

    popStyle()

    return lw,(ph - lh/2)
end

function Buffer:bufferToString(b)
    local bstrings = {}
    for k,v in pairs(b) do
        table.insert(bstrings, table.concat( b[k] ) )
    end

    return table.concat( bstrings, "\n" )
end

function Buffer:moveCursor(o)
    self.cursor = self.cursor + o

    self.cursor.x = math.max(1, math.min(self.cursor.x, #self.buffer))

    local l = self.buffer[self.cursor.x]
    local y = self.cursor.y

    y = math.max(1, math.min(y, #l + 1))
    self.cursor.y = y
end

function Buffer:insertCharacter(c)
    if c == "x" then
        xcounter = xcounter + 1
    end
    local l = self.buffer[self.cursor.x]

    if l == nil then
        l = {}
        self.buffer[self.cursor.x] = l
    end

    if c == "\n" then
        local start = table_slice(l,1,self.cursor.y)
        local tail = table_slice(l,self.cursor.y+1,#l)


        table[self.cursor.x] = start
        table.insert(self.buffer, self.cursor.x+1, tail)

        self.cursor = vec2( self.cursor.x + 1, 1 )
    elseif c == "Del" then
        if self.cursor.y == 1 then
            -- delete line
            local prevLine = self.buffer[self.cursor.x - 1]

            table.remove(self.buffer, self.cursor.x)

            if prevLine then
                self.cursor = vec2(self.cursor.x - 1, #prevLine + 1)
                table_append( prevLine, l )
            end
        else
            -- delete character

            if (l[self.cursor.y-1] == "x") then
                xcounter = xcounter-1
            end

            table.remove(l, self.cursor.y - 1 )

            self.cursor = vec2(self.cursor.x, self.cursor.y - 1 )
        end
    else
        table.insert(l, self.cursor.y, c)

        self.cursor = vec2( self.cursor.x, self.cursor.y + 1 )

    end

end

function Buffer:draw()
    self.t = self.t + 8 * DeltaTime
    self.cursorBlink = (math.sin(self.t) + 1) * 128

    pushStyle()

    self:setStyle()

    local str = self:toString()
    local w,h = textSize(str)

    pushMatrix()

    translate(textField.pos.x-textField.size.x/2+5,-40)
    text(str, 0, HEIGHT - h)


    -- Draw cursor
    -- Cursor pos x,y
    local cpx,cpy = self:cursorToScreen(self.cursor)

    fill(0, 87, 255, self.cursorBlink)
    rectMode(CENTER)
    rect(cpx,HEIGHT - cpy,5,30)

    popMatrix()
    popStyle()
end

function Buffer:clear()
    self.cursor = vec2(1,1)
    self.buffer = {}
end

function Buffer:toString()
    return self:bufferToString(self.buffer)
end

function Buffer:toStringWithoutActiveLine()
    local bstrings = {}
    for k,v in pairs(self.buffer) do
        if k ~= self.cursor.x then
            table.insert(bstrings, table.concat( self.buffer[k] ) )
        end
    end

    return table.concat( bstrings, "\n" )
end
</code></pre>

<p>Other classes and function file is given in the next post as its not allowing to enter more characters in this post.</p>
]]></description>
   </item>
   <item>
      <title>Capturing the screen image through code</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/619/capturing-the-screen-image-through-code</link>
      <pubDate>Sat, 04 Feb 2012 20:52:12 -0500</pubDate>
      <dc:creator>Zoyt</dc:creator>
      <guid isPermaLink="false">619@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Hello,<br />
As the title explains, I'm wondering if it's possible to capture the screen image with code. For example <code>image = getScreenImage(x,y,width,height)</code>. I know I can use <code>setContext()</code> and just draw normally, but I would like to use multiple contexts without worrying about getting the screen data.<br />
Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Tile image function</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/587/tile-image-function</link>
      <pubDate>Tue, 31 Jan 2012 15:12:33 -0500</pubDate>
      <dc:creator>Zoyt</dc:creator>
      <guid isPermaLink="false">587@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Since I've seen no one do this yet with the new sprite zsize function, it thought I might as well. It was extremely easy, but here is the code:</p>

<pre><code>function setup()
    mx = 0
    my = 0
end

function tileImage(image,movex,movey,iscale)
    local oldScale = scale
    local currentScale = 1
    scale = function( d )
        if d == nil then
            return currentScale
        else
            currentScale = currentScale * d 
            oldScale(d)
        end
    end
    bsmode = spriteMode()
    currentScale = scale()
    bscale = currentScale
    spriteMode(CORNER)
    scale(iscale)
    ssx, ssy = spriteSize(image)
    mx = mx + movex
    my = my + movey
    for y = -1, HEIGHT/ssy/iscale do
        for x = -1, WIDTH/ssx/iscale do
            if mx &gt;= ssx or mx &lt;= -ssx then
                mx = 0
            elseif my &gt;= ssy or my &lt;= -ssy then
                my = 0
            end
            sprite(image, x * ssx+mx, y * ssy+my)
        end
    end
    spriteMode(bsmode)
    scale(bscale)
end
</code></pre>

<p>That was easy. But it's still full of bugs and needs improvement. Here's what's on my list:<br />
1.  Fix the jolt when repeating the images when moving<br />
2.  Fix the problem when you tell it to move mor pixels than the image is<br />
3.  Fix the returning to the original scale and sprite mode<br />
4.  Madage to contain all the variables within the function<br />
5.  Speed up the process. It really slows down the program and even crashes Codea when you use some pixel art.<br />
6.  Add option to tell it if it's a block or not and it will automatically offset it correctly and draw the blocks right.</p>
]]></description>
   </item>
   <item>
      <title>Help for Enlarging pictures</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/600/help-for-enlarging-pictures</link>
      <pubDate>Thu, 02 Feb 2012 07:16:06 -0500</pubDate>
      <dc:creator>goalrex</dc:creator>
      <guid isPermaLink="false">600@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>So i have recently started using Codea.
I have a 32 by 32 sprite which is about 1 cm big on my iPad screen, and i want to enlarge it so it looks 4cm bi. I look through some of the code and couldn't find anything useful. 
I am taking a guess that i would need to use scale except i am not sure, can someone help me?</p>
]]></description>
   </item>
   <item>
      <title>Snake Illusion</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/546/snake-illusion</link>
      <pubDate>Fri, 27 Jan 2012 22:07:30 -0500</pubDate>
      <dc:creator>Herwig</dc:creator>
      <guid isPermaLink="false">546@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>An example of how to use Codea to create 'complex' images. The image looks like it is moving, but that is just an illusion.</p>

<pre><code>-- snake illusion
-- Herwig Van Marck

function setup()
    print("Change parameters and tap image to recalculate")
    print("Set hide to 1 to go fullscreen, and tap to return")
    parameter("factor",1,10,readProjectData("factor") or 3.37)
    iparameter("init_size",50,HEIGHT,readProjectData("init_size") or 150)
    iparameter("levels",1,30,readProjectData("levels") or 18)
    iparameter("hide",0,1,0)
    hidden=0
    recalc()
end

function touched(touch)
    if (touch.state==BEGAN) then
        if (hidden==0) then
            saveProjectData("factor",factor)
            saveProjectData("init_size",init_size)
            saveProjectData("levels",levels)
            recalc()
        else
            displayMode(STANDARD)
            hidden=0
        end
    end
end

function recalc()
    img=image(init_size*13/6,init_size*13/6)
    local r=init_size
    local size=init_size/24.0
    setContext(img)
    pushMatrix()
    ellipseMode(CENTER)
    translate(init_size*13/12,init_size*13/12)
    fill(255, 255, 255, 255)
    ellipse(0,0,26*init_size/12,26*init_size/12)
    for j=1,levels do
        for i=1,36 do
            fill(0, 0, 0, 255)
            rect(-size,r-2*size,size*2,size*4)
            fill(210, 210, 99, 255)
            ellipse(-size,r,size*2,size*4)
            fill(99, 108, 210, 255)
            ellipse(size,r,size*2,size*4)
            rotate(10)
        end
        rotate(5)
        r,size=r-factor*size,size*r/(r+factor*size)
    end
    popMatrix()
    setContext()
end

-- This function gets called once every frame
function draw()
    if hide==1 then
        displayMode(FULLSCREEN_NO_BUTTONS)
        hidden=1
        hide=0
    end
    
    background(255, 255, 255, 255)

    spriteMode(CENTER)
    pushMatrix()
    for m=1,2 do
        pushMatrix()
        for l=1,math.ceil(HEIGHT/init_size) do
            pushMatrix()
            for k=1,math.ceil(WIDTH/init_size) do
                sprite(img,0,0)                
                translate(26*init_size/12,0)
            end
            popMatrix()
            translate(0,26*init_size/12)
        end
        popMatrix()
        translate(13*init_size/12,13*init_size/12)
    end
    popMatrix()
end


</code></pre>
]]></description>
   </item>
   <item>
      <title>Repeated calls to image() and sprite() crash Codea</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/521/repeated-calls-to-image-and-sprite-crash-codea</link>
      <pubDate>Sat, 21 Jan 2012 13:02:42 -0500</pubDate>
      <dc:creator>Martin</dc:creator>
      <guid isPermaLink="false">521@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>It seems the following crashes Codea after around 120 iterations. I guess the relevant GL resource leaks and is exhausted. I was hoping I could be lazy but it seems this isn't handled gracefully. Oh, on looking at the docs it seems there isn't a free for the codeimage types so even if went to the trouble to release them I can't?</p>

<p>function draw()
  local i=image(400,400)
  sprite(i,0,0)
end</p>

<p>PS Loving Codea!</p>
]]></description>
   </item>
   <item>
      <title>Living image()s</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/477/living-image-s</link>
      <pubDate>Wed, 11 Jan 2012 00:34:44 -0500</pubDate>
      <dc:creator>Ipad41001</dc:creator>
      <guid isPermaLink="false">477@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>This is the beginnings of a cross between artifical life and recode based on using the values within the pixels of objects to define thier behavior.</p>

<p>Picture <a href="http://pic.twitter.com/O2mDYWbw" target="_blank" rel="nofollow">http://pic.twitter.com/O2mDYWbw</a></p>

<p>This may not be what the wiki is intended for but the code along with a lengthy discussion of what it attempts to represent can be found here <a href="https://bitbucket.org/TwoLivesLeft/codea/wiki/Limage" target="_blank" rel="nofollow">https://bitbucket.org/TwoLivesLeft/codea/wiki/Limage</a></p>
]]></description>
   </item>
   <item>
      <title>Pic v3 - December 14 2011 - flood fill added</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/312/pic-v3-december-14-2011-flood-fill-added</link>
      <pubDate>Mon, 12 Dec 2011 17:42:12 -0500</pubDate>
      <dc:creator>Bortels</dc:creator>
      <guid isPermaLink="false">312@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Will upload this evening (no outgoing email from my ipad at work for reasons to nutty to go into).</p>

<p>Added 3D spheres. Screenshot: <a href="https://twitter.com/#!/bortels/status/146358741888024578/photo/1" target="_blank" rel="nofollow">https://twitter.com/#!/bortels/status/146358741888024578/photo/1</a></p>
]]></description>
   </item>
   <item>
      <title>How to get a selection of an image [ANSWERED]</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/366/how-to-get-a-selection-of-an-image-answered</link>
      <pubDate>Thu, 22 Dec 2011 18:13:40 -0500</pubDate>
      <dc:creator>Zoyt</dc:creator>
      <guid isPermaLink="false">366@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Is it possible to get a selection of an image instead of not getting the whole image? Is that what image.get is? If so please tell me how.</p>
]]></description>
   </item>
   <item>
      <title>Using new update for fun!!!</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/274/using-new-update-for-fun</link>
      <pubDate>Thu, 08 Dec 2011 02:45:53 -0500</pubDate>
      <dc:creator>Sajjad</dc:creator>
      <guid isPermaLink="false">274@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p><a href="http://pastebin.com/zBSNXyL6" target="_blank" rel="nofollow">http://pastebin.com/zBSNXyL6</a></p>

<p>Plz tell me what u think about it</p>
]]></description>
   </item>
   <item>
      <title>Image import (or &quot;do you like my fez?&quot;)</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/268/image-import-or-do-you-like-my-fez</link>
      <pubDate>Tue, 06 Dec 2011 22:04:50 -0500</pubDate>
      <dc:creator>Bortels</dc:creator>
      <guid isPermaLink="false">268@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Managed to import an image without hackery - code to come, but feast your eyeballs on this:</p>

<p><a href="https://twitter.com/#!/bortels/status/144248682827616259/photo/1" target="_blank" rel="nofollow">https://twitter.com/#!/bortels/status/144248682827616259/photo/1</a></p>

<p>Things I learned:</p>

<p>1) print() is <em>really slow</em></p>

<p>2) my base64 stuff doesn't work</p>

<p>3) string.gsub does not modify in place (that had me stuck for a few hours)</p>

<p>4) I look DAMN GOOD in a fez. But - I knew that.</p>

<p>5) Image data is really big.</p>
]]></description>
   </item>
   <item>
      <title>Image save and load</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/260/image-save-and-load</link>
      <pubDate>Tue, 06 Dec 2011 00:32:45 -0500</pubDate>
      <dc:creator>Ipad41001</dc:creator>
      <guid isPermaLink="false">260@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>Slow, primitive, and wasteful but it works</p>

<pre>

--image save and load
function setup()
    --make image
    myimage = image(10,10)
    for i = 5, 10 do
        for j = 1, 10 do
            myimage:set(i,j,math.random(256),math.random(256),math.random(256),255)
        end
    end   
    --saveimage
    saveimage = myimage.width .. "," .. myimage.height .. ","
    for i = 1, myimage.width do
        for j = 1, myimage.height do
            a,b,c,d = myimage:get(i,j)
            saveimage = saveimage .. a .. "," .. b .. "," .. c .. "," .. d .. ","
        end
    end    
    saveLocalData("x",saveimage)
    --loadimage
    loadimage = readLocalData("x")
    k = 1
    l = string.find(loadimage,",",k)
    lw = string.sub(loadimage,k,l-1)
    lw = lw + 0
    k = l + 1
    l = string.find(loadimage,",",k)
    lh = string.sub(loadimage,k,l-1)
    k = l + 1
    loadedimage = image(lw,lh)
    for i = 1, lw do
        for j = 1, lh do
            l = string.find(loadimage,",",k)
            a = string.sub(loadimage,k,l-1)
            k = l + 1
            l = string.find(loadimage,",",k)
            b = string.sub(loadimage,k,l-1)
            k = l + 1
            l = string.find(loadimage,",",k)
            c = string.sub(loadimage,k,l-1)
            k = l + 1
            l = string.find(loadimage,",",k)
            d = string.sub(loadimage,k,l-1)
            k = l + 1
            loadedimage:set(i,j,a,b,c,d)
        end
    end    
end

function draw()
    rect(0,0,10,10)
    background(0, 0, "095")
    scale(10)
    sprite(myimage,10,10)
    sprite(loadedimage,30,30)
end

</pre>

<p>Edit: that's not a comment on the image command, it's a comment on this method I wrote.</p>

<p>This is a bridge until a real format can be used.</p>
]]></description>
   </item>
   <item>
      <title>image() - what am I missing?</title>
      <link>http://twolivesleft.com/Codea/Talk/discussion/258/image-what-am-i-missing</link>
      <pubDate>Mon, 05 Dec 2011 21:59:11 -0500</pubDate>
      <dc:creator>Bortels</dc:creator>
      <guid isPermaLink="false">258@/Codea/Talk/discussions</guid>
      <description><![CDATA[<p>So - I can make an image() - and I can set and get pixels. And I can copy parts of an image to another image, and I can plot that on the screen.</p>

<p>Is there a way to get an image <em>from</em> the screen? ie. is the screen an image() as well that we can copy to/from? it doesn't seem to be, but maybe I am missing something. What I'd like to do is draw my teh awesome thing, then grab that drawing and blit it around - possible? (If not, I'm gonna be writing some line-drawing routines!)</p>

<p>Time to go write image decoders...</p>
]]></description>
   </item>
   </channel>
</rss>