Codea Brush

I thought this was really cool. @Grant, a friend and colleague of mine made this while learning Codea. And painted the picture in it:

Codea Brush Pro

This is great! Steady line. Did your friend use a stylus?

I’m not too sure. I’ll ask him tomorrow. If he did then I want a stylus :slight_smile:

That’s the ugliest dog I ever did see. But nice picture! :slight_smile:

A dog? I thought it’s a cow! :smiley:

@Simeon. Wow, my respect! This is amazing! Never thought one can do that. With the primitives created I am more in the field of drawing cubic art from the mid 1930ies … Already this gives interesting results, but it’s using pure geometrical objects only. How long did you colleague work on that, and how did he solve the problem of deleting unwanted lines, dots, … With my fingers this is a bit difficult, maybe a stylus is the right tool for that…

@Simeon, great example. Want to add this example in next version? I want to know how was made it.
@Simeon, This example, gave me an idea. It’s about Color Picker, I see this app have few colors available, not all colors like a Color Picker. I suggest you to add new feature to Codea: Ability to open Color Picker inside Run Time App, for choose any color. For example: showColorPicker() this works like showKeyboard()
What you think?

I want this code too.

Incidentally, @Georgian, my extended colour class has a colour picker in it. It picks from a list, rather than a general colour picker, so isn’t always suitable.

AWSOME! Did it pose for him in this picture? here You should have put Codea on record and posted it in fat forward. It would’ve been awsome :slight_smile:

Hi all, a few answers - it was just my finger using only the circle with a single touch. Yes I think a stylus would be better.

I started the project with my nine year old son to intro him to coding.

At this point I change the color and brush size with the parameters. The limited color pallet was for my daughter who kept asking how to make skin color. The irony is I forgot to put skin color in.

Painting with white is the only way to delete, so it is more like oil painting where you just keep painting over if you make a mistake. After I had finished I thought dang I should have recorded it, but I didn’t think it would have turned out so well. I might do another some time.

The hardest part was remembering the RGB colors I used as I went. An eye dropper tool would make it simpler. Dylan had a good idea which I might try, but I do find SketchBook Pro better to use (not surprisingly). I might keep plugging away but I have an idea for a game I’d like to try.

All that said I was extremely happy with the results considering how limited my program currently is.

The code is probably simple and clumsy, as I really don’t get to do much coding anymore. I’ll post it so people can see. But I already have a few ideas to improve like layers.

Now if only there were a way to distinguish between a stylus and a finger. Then one could easily simulate pastel drawing.

Let me reiterate: I want that code. If you’ve nowhere to post it, send it to me and I’ll post it.

Nice work @Grant! And I second Andrew’s request.

Re: Sketchbook Pro… I find Procreate (another brilliant Oz iOS app) much (I mean really MUCH) better. If you are not aware of it you may want to check it out.


function setup()

    backingMode(RETAINED)
    count = 0
    thicknessTest = 0
    paletteSize = 35
    currentCol = 0
    yColSelect = 0
    
    parameter("thicknessFill", 2, 50, 25)
    parameter("red", 0, 255)
    parameter("green",0, 255)
    parameter("blue",0, 255)
    parameter("alpha", 0, 255, 255)
    
        -- This sets the background color to white
        bgCol = color(255, 255, 255, 255)
        background(bgCol)
    
end

-- This function gets called once every frame
function draw()
    
    noSmooth()
    globalCol = color(red, green, blue, alpha)

    -- the first touch creates an artifact of a single dark dot if alpha is less than 255
    -- i did turn off the ellipse, but then you cannot tap to draw a dot. 
    -- the tapTouch draws only one ellipse rather than repeated alpha ellipses as draw is called
    if CurrentTouch.state == BEGAN then
        pushStyle()
            if tapTouch == false then
                fill(globalCol)
                -- set the colour and thickness from the parameters
                ellipse(CurrentTouch.x, CurrentTouch.y, thicknessFill, thicknessFill)
                tapTouch = true
            end
        popStyle()
        
        elseif CurrentTouch.state == MOVING then
            pushStyle()
            stroke(globalCol)
            fill(globalCol)
        
            -- set the colour and thickness from the parrameters
            ellipse(CurrentTouch.x, CurrentTouch.y, thicknessFill, thicknessFill)
            popStyle()
            tapTouch = false
        
        elseif CurrentTouch.state == ENDED then
            pushStyle()
                fill(0, 0, 0, 255)
            popStyle()
            tapTouch = false
        end
    
    -- make the size snd colour indicator near top left screen
    -- give the ellipse a white outline so we can see when fill colour is black

    toolbar()
    
    
end


function toolbar()
    
    gradFactor = 1
    shadowWidth = 8
    baseCol = 200
    menuBar = 70

    -- bit of eyecandy drop shadow
    for shadow = 1, shadowWidth do
        gradFactor = 255-(baseCol/shadowWidth) * shadow
        fill(gradFactor, gradFactor, gradFactor, 255)
        rect(0, 0, menuBar + shadowWidth - shadow, HEIGHT)
    end
    
    fill(234, 234, 234, 255)
    rect(0, 0, 70, HEIGHT)
    
    --create the current brush style with white backing, white impotant when using alpha < 255
    pushStyle()
        stroke(255, 255, 255, 255)
        strokeWidth(1)
        fill(255)
        ellipse(paletteSize, HEIGHT - paletteSize, thicknessFill, thicknessFill)
        fill(globalCol)
        ellipse(paletteSize, HEIGHT - paletteSize, thicknessFill, thicknessFill)
    popStyle()
    
    startPoz = HEIGHT - 50
    --draw palette
    
    if CurrentTouch.state == BEGAN then
        if CurrentTouch.x < menuBar then
            handledColSelect = true
            yColSelect = CurrentTouch.y
            
        end
    elseif CurrentTouch.state == ENDED then

    end
    
    
    -- draw the color palette, and test for click
    for pCount = 1, 14 do
        -- 5 is offset between palette squares then need to add offset to allow for center draw
        topPalSquare = (startPoz - ((paletteSize + 5) * pCount)) + (paletteSize/2)
        botPalSquare = topPalSquare - paletteSize
        
        -- yColSelect having value > 0 means a touch on color palette as the handle touch has
        -- found that the touches x is on the palette
        -- find out which color
        
        if yColSelect < topPalSquare and yColSelect > botPalSquare then

            pushStyle()
                c = getCol(pCount)
                if handledColSelect then
                    red = c[1]
                    green = c[2]
                    blue = c[3]
                    handledColSelect = false
                else
                    
                end
                --alpha = c[4]
                fill(c)
                strokeWidth(2)
                stroke(255, 255, 255, 255)
                rectMode(CENTER)
                rect(paletteSize, (startPoz - (paletteSize + 5) * pCount), paletteSize -6 ,paletteSize - 6 )
            popStyle()
        else
            c = getCol(pCount)
            fill(c)
            pushStyle()
                rectMode(CENTER)
                rect(paletteSize, startPoz - (paletteSize + 5) * pCount, paletteSize, paletteSize )
            popStyle()
        end
        pushStyle()
        fill(255)
        --text(pCount, paletteSize, startPoz - (paletteSize + 5) * pCount)
        popStyle()
    end
    
    --[[ this is for a bg change but cannot use backingMode(RETAINED) and then change bg
    -- the new idea is to place the drawing into an image with setContext() could also create
    -- layers with a numbers of images
    
    if yColSelect < 100 and yColSelect > 70 then
        bgCol = globalCol
        
    end
        --draw the background color changer
    pushStyle()
        -- bg indicator
        stroke(255)
        fill(bgCol)
        rect(27, 80, 25, 25)
        -- forground color indicator
        stroke(0)
        fill(globalCol)
        strokeWidth(1)
        rect(17, 90, 25, 25)
    popStyle() ]]--
    
end



function getCol(index)
    
    if index == 1 then
        c = color(255, 0, 0, 255)
    elseif index == 2 then
        c = color(255, 127, 0, 255)
    elseif index == 3 then
        c = color(255, 255, 0, 255)
    elseif index == 4 then
        c = color(0, 255, 0, 255)
    elseif index == 5 then
        c = color(0, 255, 255, 255)
    elseif index == 6 then
        c = color(0, 0, 255, 255)
    elseif index == 7 then
        c = color(127, 0, 255, 255)
    elseif index == 8 then
        c = color(255, 0, 255, 255)
    elseif index == 9 then
        c = color(0, 0, 0, 255)
    elseif index == 10 then
        c = color(51, 51, 51, 255)
    elseif index == 11 then
        c = color(102, 102, 102, 255)
    elseif index == 12 then
        c = color(153, 153, 153, 255)
    elseif index == 13 then
        c = color(204, 204, 204, 255)
    elseif index == 14 then
        c = color(255, 255, 255, 255)
    end
    return (c)
end

If someone neatens it up please feel free to post back. As I have said I’m rusty.

Grant , the forum is using php markdown for formatting. You can ‘fence’ your code using three tilde marks ~~~ before and after to maintain your code’s formatting.

I’ve just added the code block stuff to the FAQ, too. I should have had it in there from the start.

Thanks for sharing your code, @Grant. It’s a really good example.

It’s kind of amazing to think that you can create your own drawing tool on an iPad and then draw a great picture in it.

 It's kind of amazing to think that you can create your own drawing tool on an iPad and then draw a great picture in it.

OTOH it’s also kind of amazing that the world has become a place where artists accept tools made by others in order to express themselves.

Edit: There is definitely something to be said for @Ipda41001’s statement and link the other day…

“Unless you make it yourself, it can’t truly be yours.”

http://www.journalpioneer.com/media/photos/unis/2011/10/07/photo_1872036_resize.jpg

Oh I don’t know, have you seen the TED talk about building a toaster from scratch? It’s almost impossible for one person to do because of the hierarchy of tools needed. Very, very few artists would create every tool in their arsenal (including the tools needed to create other tools).

That’s probally the best description on Codea. Yes, we use it for play and enjoy it but Codea is also tool that makes tools.

 Oh I don't know, have you seen the TED talk about building a toaster from scratch? It's almost impossible for one person to do because of the hierarchy of tools needed. Very, very few artists would create every tool in their arsenal (including the tools needed to create other tools).

Agreed @Simeon and @Ipda41001 – there is no argument to the fact that we all today “stand on the shoulders of giants.”

I just thought that it was “kind of amazing” that this has become so much part of our nature that we remark on (and appreciate) instances when it is not the case.

The older I get the more I appreciate the radicalness of McLuhan’s ‘message’ concerning the message: i.e. overt content is “merely eye candy” and the actual message is embedded within the form/medium/tool.

(At least this afternoon, and of course YMMV.)

It is interesting thought @Blanchot, and the closer you get to the origin of a craft, the more likely the practitioner would have made their own tools (a painter making their own brush), and these tools might best match the practioners needs (assuming they did a reasonable job at making them) it would at lease give them a unique result differentiating them from the rest. Even in a mature industry the practioners are likely to have the best idea of what they need from their tools, but specialisation and complexity means they no longer have the capability of making them.

Two Lives Left made Codea as they wanted to be able to do their craft on an iPad, in this case they can and have made a great tool and the community is helping shape it.

It begs the question can the practitioner with limited programming skills make a better tool than the best programmer who has little understanding of the practitioners craft? Naturally a person with an understanding of both might win hands down.