Moon

Here’s something that might be of interest to someone. It’s a high res image of the moon with added green dots over certain points of interest. Move the moon image to position a green dot inside the white circle to display the name of the point of interest. The moon can be resized with the usual 2 finger slide apart or close. If you tap the screen 3 times, the green dots, white circle, and names aren’t shown. Tap 3 times to bring them back. When the program is started, the program will read the moon image from the Dropbox folder. If it’s not found, it will download the moon image and save it in Dropbox. The image is a 1400x1400 pixel png image. More names can be added to the moonTab table which contains the x,y, and name. To get the x,y position, while the white circle is showing, position the point of interest inside the circle and read the x,y value at the top of the screen. Just add those values to the table with the name. Pay attention if the value is positive or negative. I tried this on my iPad 1 and it took a few seconds to load the moon image. Also, I had to remove the integer divide // from one of the statements in the draw function because of the older Codea version.


--# Main

displayMode(FULLSCREEN)

function setup()
    str="Reading moon image, please wait."
    moonImage=readImage("Dropbox:moon1")
    if moonImage==nil then
        url="http://lroc.sese.asu.edu/news/uploads/lroc_wac_nearside_noslew.png"
        http.request(url,goodResponse,badResponse)
    end
    tab={}
    moonTab=
    {   {x=-128,y=64,n="Copernicus"},
        {x=-38,y=296,n="Plato"},
        {x=13,y=286,n="Alpine Valley"},
        {x=-15,y=124,n="Apennine Mts"},
        {x=-54,y=-261,n="Tycho"},
        {x=72,y=292,n="Aristoteles"},
        {x=76,y=265,n="Eudoxus"},
        {x=-23,y=188,n="Archimedes"},
        {x=-47,y=-143,n="Straight Wall"},    
        {x=-91,y=203,n="Mare Imbrium"},
        {x=109,y=170,n="Mare Serenitatis"},
        {x=-93,y=-133,n="Mare Nubium"},
        {x=-232,y=53,n="Kepler"},
        {x=-73,y=94,n="Eratosthenes"},
        {x=-148,y=21,n="Reinhold"},
        {x=-170,y=-3,n="Landsberg C"},
        {x=-135,y=-135,n="Bullialdus"},
        {x=-283,y=56,n="Oceanus Procellarum"},
        {x=-224,y=-151,n="Mare Humorum"},
        {x=180,y=53,n="Mare Tranquillitatis"},
        {x=307,y=113,n="Mare Crisium"},
        {x=286,y=-7,n="Mare Foecunditatis"},
        {x=203,y=-100,n="Mare Nectaris"},
        {x=21,y=90,n="Mare Vaporum"},
        {x=-232,y=-114,n="Gassendi"},
        {x=-12,y=-61,n="Ptolemaeus"},
        {x=-18,y=-88,n="Alphonsus"},
        {x=6,y=211,n="Aristillus"},
        {x=8,y=194,n="Autolycus"},
        {x=-77,y=170,n="Timocharis"},
        {x=-160,y=99,n="Carpathian Mts"},
        {x=48,y=219,n="Caucasus Mts"},
        {x=102,y=308,n="Mare Frigoris"},
        {x=-223,y=-265,n="Schickard"},
        {x=-50,y=-323,n="Clavius"},
        {x=329,y=-58,n="Langrenus"},
        {x=166,y=-77,n="Theophilus"},
        {x=-172,y=-48,n="Riphaeus Mts"},
        {x=-157,y=277,n="Jura Mts"},
        {x=-257,y=153,n="Aristarchus"},
        {x=164,y=276,n="Hercules"},
        {x=161,y=201,n="Posidonius"},
        {x=146,y=101,n="Plinius"},
        {x=26,y=-76,n="Albategnius"},
    }
    size=760
    d1,d2=0,0
    dx,dy=WIDTH/2,HEIGHT/2
    cx,cy=dx,dy  
    pct=size/760  
    show=true
end

function goodResponse(picture,status,headers)
    moonImage=picture
    saveImage("Dropbox:moon1",moonImage)
end

function badResponse(picture,status,headers)
    str="Error reading moon image file."
end

function draw()
    background(0)
    if moonImage==nil then
        fill(255)
        text(str,WIDTH/2,HEIGHT/2)
        return
    end
    sprite(moonImage,dx,dy,size)
    dfx=(cx-dx)/pct
    dfy=(cy-dy)/pct
    if show then
        stroke(255)
        strokeWidth(2)
        noFill()
        ellipse(WIDTH/2,HEIGHT/2,20)
        fill(255)
        for a,b in pairs(moonTab) do
            if dfx>b.x-3 and dfx<b.x+3 and dfy>b.y-3 and dfy<b.y+3 then
                text(b.n,WIDTH/2,HEIGHT/2+30)
                break
            end
        end
        text(((cx-dx)/pct//1).."  "..((cy-dy)/pct//1),WIDTH/2,HEIGHT-40)
        fill(0,255,0)
        for a,b in pairs(moonTab) do
            ellipse(dx+b.x*pct,dy+b.y*pct,5)
        end        
    end
end

function touched(t)
    if t.state==BEGAN then
        if t.tapCount==3 then   -- turn points on / off
            show=not show
            return
        end
        d1,d2=0,0
        table.insert(tab,vec3(t.x,t.y,t.id))
    end
    if t.state==MOVING then -- shrink or enlarge moon image
        if #tab == 2 then
            for z=1,2 do
                if t.id==tab[z].z then
                    tab[z].x=t.x
                    tab[z].y=t.y
                end
            end
            d1=math.sqrt((tab[1].x-tab[2].x)^2+(tab[1].y-tab[2].y)^2)
            if d2==0 then
                d2=d1           
            end
            size=size+(d1-d2)*3
            if size<760 then    -- dont allow moon to go smaller than this
                size=760
            end
            d2=d1
        else
            dx=dx+t.deltaX
            dy=dy+t.deltaY
        end
    end        
    if t.state==ENDED then  -- clear tab of ended touch id
        for z=1,#tab do
            if t.id==tab[z].z then
                table.remove(tab,z)
                return
            end
        end
    end 
    pct=size/760    -- recalculate size percent
end 

cool!

Now where is Apollo 11? :wink:

{x=-165,y=14,n=“Apollo 11 Landing Site”}

smart alec!

If anyone uses this and adds more names to the moonTab, could you post a copy of the new table so others can use it.