Curve Stitching

This is a little program that does as it says… you can change the gridsize, switch on/off the 4 elements and the colours cycle. I made the rate different for each set of curves so it doesn’t repeat.

--# Main
-- Curve Stitching 4

displayMode (FULLSCREEN)

function setup()
    
    hueO,hueI,hueO2,hueI2 = 0,42,85,127  -- set initial colours
    parameter.integer ("gridSize", 2,250,65) -- has to be integer for symmetrical alignment   
    w = 768  -- width of square
    h = w/2  -- half width to define centre

end

function draw()

    background(40, 40, 50)
    strokeWidth(1)

    pixelSize = 768/gridSize  -- needs to be a factor of 768

    parameter.boolean("OUTSIDECurves", true)
    parameter.boolean("INTERNALCurves", true)
    parameter.boolean("OUTSIDECurves2", true)
    parameter.boolean("INTERNALCurves2", true)

if OUTSIDECurves == true then  -- 4 outside curves in corner
outsideCurves()
else end

if INTERNALCurves == true then  -- 4 internal curves inside central cross
internalCurves()
else end   

if OUTSIDECurves2 == true then  -- 4 outside curves from corner to half way up adjacent side
outsideCurves2()
else end

if INTERNALCurves2 == true then  -- 8 internal curves every 45 degrees
internalCurves2()
else end

end

--# Outside
function outsideCurves()
    
    for a = 0, w, pixelSize do
    b = w-a
    
    Hue(hueO)
    stroke(red,grn,blu,255)
    
    line(0, a, a, w)      -- top left 
    line(w, a, b, w)      -- top right
    line(0, b, a, 0)      -- bottom left
    line(a, 0, w, a)      -- bottom right
      
    hueO = hueO + 0.01
    if hueO > 255 then hueO = 0 end

    end

end
--# Internal
function internalCurves()

    for c = 0, h, pixelSize do
    d = h-c

    Hue(hueI)
    stroke(red,grn,blu,255)
    
    line(h, w-c, d, h)    -- top left
    line(h, w-c, h+c, h)  -- top right
    line(h, c, d, h)      -- bottom left
    line(h, c, h+c, h)    -- bottom right  
               
    hueI = hueI + 0.015
    if hueI > 255 then hueI = 0 end

    end

end
--# Outside2
function outsideCurves2()

    for a = 0, w, pixelSize do
    b = w-a
   
    Hue(hueO2)
    stroke(red,grn,blu,255)
   
    line(0, a, a/2, w)      -- top left 1
    line(b, w, 0, b/2+h)    -- top left 2
    line(w, a, b/2+h, w)    -- top right 1
    line(a, w, w, b/2+h)    -- top right 2 
    line(0, b, a/2, 0)      -- bottom left 1
    line(b, 0, 0,a/2)       -- bottom left 2   
    line(w, b, b/2+h, 0)    -- bottom right 1
    line(a, 0, w, a/2)      -- bottom right 2
        
    hueO2 = hueO2 + 0.02
    if hueO2 > 255 then hueO2 = 0 end
 
    end

end  
--# Internal2
function internalCurves2()

    for c = 0, h, pixelSize do
    d = h-c

    Hue(hueI2)
    stroke(red,grn,blu,255)
    
    line(c, h, d, c+h)      -- top left 1
    line(h, d+h, d, c+h)    -- top left 2
    line(h, d+h, c+h, c+h)  -- top right 1
    line(d+h, h, c+h, c+h)  -- top right 2
    
    line(h, c, d, d)        -- bottom left 1
    line(c, h, d, d)        -- bottom left 2
    line(d+h, h, c+h, d)    -- bottom right 1 
    line(h, c, c+h, d)      -- bottom right 2
                
    hueI2 = hueI2 + 0.025
    if hueI2 > 255 then hueI2 = 0 end

    end

end
--# Colour
function Hue(hue)

    if hue < 43 then red,grn,blu = 255,0,6*hue
    elseif hue < 86 then red,grn,blu = 510-6*hue,0,255
    elseif hue < 128 then red,grn,blu = 0,6*(hue-85),255
    elseif hue < 171 then red,grn,blu = 0,255,1020-6*hue
    elseif hue < 213 then red,grn,blu =  6*hue-1020,255,0
    elseif hue > 212 then red,grn,blu = 255,1530-6*hue,0 end   
  
end

Very, very cool. Thanks!

Looking really nice indeed

@David, you’re obsessed by graphical stuff…? first the mystic rose and now this… :wink:

@David this is so cool!

Thanks guys, glad you like :wink: Ha @stevon8ter, I certainly am atm. It’s a fun way to get into Codea.

@David it sure is, and you’re making great progress, I’m glad to see you’re learning stuff and don’t give up :slight_smile:
And don’t forget to ask question, we’re here to help :slight_smile: