Using Pixels on CoronaSDK

Many developers that have graduated from the tags of a beginner have asked if they can have pixel level control. i.e. getPixel(x,y) and setPixel(x,y) now that is and isn't possible but there is a workaround that we had been working on, it is not complete, but it is one of the features that is present in this 3rd Party Library

First, let us see a couple of videos of pixel manipulation

1. Batman

2. Robin

These videos demonstrate that pixel manipulation is possible in CoronaSDK but cannot be used with normal objects and images. Vector Art, lines, rects, circles, arcs, Pies, etc can all be made as seen in this video here



Here's a sample of using Vector Graphics
newVect:setForeColor({255,255,0})
newVect:polygon({{50,200},{70,0},{20,-90},{-90,20},{20,90},{-20,-20}})

newVect:setForeColor({255,0,0})
newVect:circle(50,50,30)

newVect:setForeColor({255,255,255})
newVect:rectangle(20,100,200,75)

timer.performWithDelay(1000,function()
newVect:setForeColor({0,0,255})
newVect:floodfill(30,110)
end)

timer.performWithDelay(2000,function()
newVect:setForeColor({255,0,0})
newVect:floodfill(50,50)
end)

timer.performWithDelay(3000,function()
newVect:setForeColor({255,255,0})
newVect:floodfill(70,150)
end)


and the same can also be used in applications that can use the pixel graphics in better ways as demonstrated here


Here is the code that maked this Sprite Editor as shown above
display.setStatusBar(display.HiddenStatusBar)

local a = require ("enzyme")  -- This is the temp name for this library

a.newBoard(16)
local board = a.getBoard()

local i,j
for j=0, board.visRows do
        for i=0,board.visCols do
                a.newSquare(i,j,{color={255,255,255}})
        end
end

a.board.on_TouchBegan=function(event) 
        local t = a.getSquareProperty(event.row, event.col, "bit")
        a.setSquareProperty(event.row,event.col, "bit", not t)
        if t == true then
                a.changeSquareColor(event.row,event.col,{255,255,255})
        else
                a.changeSquareColor(event.row,event.col,{0,0,0})
        end
        
end

a.drawBoardGrid()


Sidenote - Amusing facts

Just a few questions,
1. How many coronaSDK readers read this
2. How many actually understand anything without going "Ah, my head is going to spin" or "That's too advanced for me"
3. How many actually need functionality like this
4. How much would the number of people left (that responded to the above questions) willing to pay for something like this?

Now let us put that into context as Price people are willing to pay (from response in Q# 4 above) and divide that by the number of hours spend towards making a library. That should indicate the community support. BTW Zero divided by any number is always Zero...

Don't kill the Indie Market, remember that you are also part of it, unless you are an organisation that is making millions. You kill of a few developers by not supporting them, tomorrow you get killed by other developers that wouldn't support you, because the market trend would have become *FREE* or NADA.

Comments

  1. Ironically, the side note was more for the developers that want information / assistance but are unwilling to participate and do something on their parts.

    What is the answer expected of this, none just self realisation for the reader that when an article / tool is helpful or useful, share something (an action on your part), not necessarily *money* and not necessarily with *this site* but with anyone, basically spread the Good Karma...

    Buy from / support Indie developers (not by paying 50 cents on Indie Humble Bundle sales).

    Anonymous, I hope that answers your question.

    ReplyDelete
  2. Very nice.
    Have been playing with this aswell.
    I have converted 2 processing scriüts into Corona and was in need of a display.newPolygon feature to colorize the sides - but couldn't find a satisfying solution:

    http://developer.anscamobile.com/forum/2011/11/15/adding-displaynewpolygon-or-simila

    I guess your solution wouldn't be fast enough (since it would need to paint several items in an enterframe)

    ReplyDelete
  3. Chris, are you Fantaxxx?

    BTW, the scripts *can* be very optimised and made to be very *fast* it is all about how it is used. Right now, I have other projects on hand, I might make a video later on using these in games that can show the speeds.

    on enterFrame, I prefer to use other techniques than enterFrame, I still think enterFrame are the remains of what was Flash, an unnecessary overhead.

    Still, I think you did well at converting those to Corona, I was thinking of adding a coloring code to the same. It needs to be looked at differently to achieve the output required than just replicating the code.

    I would have looked at spending the CPU cycles to determine what does *not* need to be rendered, that will leave me with a smaller number of things to paint/color.

    ReplyDelete

Post a Comment

Popular Posts