Computer aided Designs

@Bri_G What do you mean by collapsible collections. How, where?

@dave1707 - when you use fileapp to look at the Codea folder in 103 things seem to have changed, but I need to check a few things first.

One thing that I think is new is if you enter project folders(called collections) by creating folders in Fileapp e.g. utilities.collection then you will get a > symbol followed by that title in Fileapp. Whilst in Fileapp you can transfer projects into the utilities.collection and then see them on the Codea Project page by clicking on the > utilities.collection entry. This allows you to tidy up your projects, but it also makes it less onerous to scroll through the projects as, by clicking on the > utilities.collection you can alternately open and collapse that collection.

I’ve set a 1Dependencies collection up and put the cameras in it, hoping I could see it reflected in the Dependencies list but no joy. I think we need the same management system on the Dependencies.

Sorry about the delay in replying - had to recharge my pad.

@Bri_G So it’s the Files app. I thought it was something new in Codea that I didn’t see. What would be nice is selecting a Codea project in the Files app, it switches to Codea and opens that project, lets you do whatever you want and when you close the project, it goes back to the Files app where you started. I don’t use the Files app for anything right now, but that might make things a little easier for those that want to group their projects.

@dave1707 - it’s like I said, useful if you want to organise your projects - especially if you have many live projects. But you do need Backup to record the collection structure with the files to make this a really useful tool. Otherwise you are going to spend a lot of time shuffling projects.

Here’s a variation to my code above that drew 20 Bézier curves using Craft spheres. This version draws tubes instead of the spheres. Some changes made by @LoopSpace. It takes several seconds for the image to show.

displayMode(FULLSCREEN)

function setup()
    diameter=6
    sides=10
    assert(craft, "Please include Craft as a dependency")
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
    scene = craft.scene()
    v=scene.camera:add(OrbitViewer,vec3(0,0,0), 700, 0, 2000)
    v.camera.farPlane=3000
    v.ry=60
    for z=1,20 do
        pos,ind,col,nor={},{},{},{}
        bezier()
        createSkin()
        createTube()
    end
    createSphere(vec3(0,0,-200),20) --  starting red sphere
    createSphere(vec3(0,0,200),20)  --  ending red sphere  
end

function draw()
    update(DeltaTime)
    scene:draw() 
    text("Slide your finger around the screen to rotate the image.",WIDTH/2,HEIGHT-25)
    text("Use two fingers to zoom in, zoom out or to move the image.",WIDTH/2,HEIGHT-50)
end

function update(dt)
    scene:update(dt)
end

function bezier(cnt)
    local val=400
    local tab1={}
    local x0 = vec3(0,0,-200)
    local x1 = vec3(math.random(-val,val),math.random(-val,val),math.random(-val,val))
    local x2 = vec3(math.random(-val,val),math.random(-val,val),math.random(-val,val))
    local x3 = vec3(0,0,200)
    local xt
    for t=0,1.01,.02 do
        xt = (1-t)^3*x0 + 3*t*(1-t)^2*x1 + 3*t^2*(1-t)*x2 + t^3*x3         
        table.insert(tab1,xt)
    end
    for z=1,#tab1-1 do
        createLoop(tab1[z],tab1[z+1],false) -- createLoop on 1st to next to last point
    end
    createLoop(tab1[#tab1-1],tab1[#tab1],true)  -- createLoop on last point
end

function createLoop(p1,p2,last)
    local rp=vec3(1,1,1)
    local v1=rp-p1
    local r1=v1:cross(p2-p1)
    local s1=r1:cross(p2-p1)
    r1,s1=r1:normalize(),s1:normalize()    
    local n
    for a=0,359,360/sides do
        n = r1 * math.cos(math.rad(a)) + s1 * math.sin(math.rad(a))
        n=n*diameter
        if last then
            table.insert(pos,n + p2)    -- add p2 to last loop
        else
            table.insert(pos,n + p1)    -- add p1 to loop
        end
        table.insert(nor,n)
    end
end

function createSkin()
    o,p={1,2,3,4,5,6,3,2,1,6,5,4},{}
    for z=1,#pos-sides do
        p[1],p[2],p[3],p[4],p[5],p[6]=z,z+1,z+sides+1,z,z+sides+1,z+sides
        if z%sides==0 then
            p[2]=z-sides+1
            p[3]=z+1
            p[5]=z+1
        end
        for t=1,12 do
            table.insert(ind,p[o[t]])
        end
    end 
    for z=1,#pos do
        if (z-1)%1000==0 then   -- change color on each tube
            c=color(math.random(255),math.random(255),math.random(255))
        end
        table.insert(col,c)
    end
end

function createSphere(p,s)
    local pt=scene:entity()
    pt.position=p
    pt.model = craft.model.icosphere(s,2)
    pt.material = craft.material("Materials:Specular")
    pt.material.diffuse=color(255,0,0)
end

function createTube()
    local pt=scene:entity()
    pt.model = craft.model()
    pt.model.positions=pos
    pt.model.indices=ind
    pt.model.colors=col
    pt.model.normals=nor
    pt.material = craft.material("Materials:Specular")    
end

Corrected some code and removed some code to improve the above program.

I have a PGM, on youtube but it looks like its written in java script. I was wondering if anyone can help me out this in Lua. With java script you seem to have to declare variables first, and you have to start at 1, not 0…Its not to long…Van be viewed on youtube : fun programming 112 : array of objects hypnotic animation pt1…

Here is a screenshot of what it looks like

@kendog400 I couldn’t find a complete listing of the code you’re referring to, so I threw this together just for kicks.

displayMode(FULLSCREEN)

function setup()
    fill(255)
    c=0
end

function draw()
    background(0)
    for z=1,2000,2 do
        
        fill(0,0,255)
        x=math.cos(math.rad(z+c//2))*z//5
        y=math.sin(math.rad(z+c//4))*z//5
        ellipse(WIDTH/2+x,HEIGHT/2+y,z%15+8)

        fill(0,255,0)
        x=math.cos(math.rad(z-c//3))*z//5
        y=math.sin(math.rad(z-c//5))*z//5
        ellipse(WIDTH/2+x,HEIGHT/2+y,z%14+6)
        
        fill(255,0,0)
        x=math.cos(math.rad(z-c//4))*z//5
        y=math.sin(math.rad(z+c//6))*z//5
        ellipse(WIDTH/2+x,HEIGHT/2+y,z%13+4)
    end
    c=c+2
end

You tube video : Fun Programming 113 : Array of Objects : Hypnotic animation / Abe Pazos…

I tried to set a java pgm to lua…but I got lost…all I could get was a sphere that increases in size…

~~
– Computer designs
displayMode(OVERLAY) displayMode(FULLSCREEN)
function setup()
fill(0,0,255)
c=math.random(-20,20)
a=0
b=0
end

function draw()
background(0)
for z=1,500,5 do
a=a+.003
b=b+.002 fill(math.random(255),math.random(255),math.random(255))
x=math.sin(math.rad(c)/4) y=math.cos(math.rad(c)/4) ellipse(WIDTH/2+x,HEIGHT/2+y,a,b)
end
end
~~

That’s about all the program you posted does, just an ellipse increasing in size and changing color. Without seeing the original program, I don’t know what it’s supposed to do.

@dave1707 - it is one of the open processing examples - the following site:

https://www.openprocessing.org

There’s a YouTube video on Fun Programming 113.

https://www.youtube.com/watch?v=GMWmRkGTMbw

@kendog400 - you need to change the code limiters from ~~ to ~~~ in your code. Also, with cross platform coding like this I find it better to pull off the full code from the example, so you can see the big picture, and then translate from that. Following the video piece-meal can be quite messy.

@kendog400 - quick look at the tutorial, put this together - may need a few improvements. Had to add a map() function to get it to work (derived from a C function).

function setup()
    --
    smooth()
    noStroke()
    fill(255)
    orecuho = {}
    discs = 200
    cw,ch = WIDTH//2, HEIGHT//2
    for i = 1, discs do
        px = cw + math.cos(i/2)*i
        py = cw + math.sin(i/2)*i
        orecuho[i] = bug(px,py,0.05+(i/1000))
    end
end

function draw()
    -- This sets a dark background color 
    background(150, 0, 0)
    for i = 1, discs do
        orecuho[i]:draw()
    end
end

bug = class()

function bug:init(px,py,ts)
    --
    self.px = px
    self.py = py
    self.ts = ts
    self.sz = 0
    t = 0
end

function bug:draw()
    --
    self.sz = map(math.sin(t),-1,1,10,20)
    ellipse(self.px,self.py,self.sz,self.sz)
    t = t + self.ts  -- speed
end

function map(Vin,inMin,inMax,outMin,outMax)
    --
    return outMin+(Vin-inMin)*(outMax-outMin)/(inMax-inMin)
end

Have fun.

Edit: modified this to include variable speed and size for individual discs, but so fast you can’t tell. Needs to be slowed and possible rotating disc around centre to enhance effect.

Thanks, getting ready to give a peek…

Working perfectly !

Oops, I see I goofed ! :