Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Computer aided Designs

edited July 22 in General Posts: 15

A design, (written in another langauge),
The code is not to long, but it would be good to put on the code shareing section. Its from a Youtube video, needs translation it to LUA...
The video : Learn programming 67: Circular motion: sine and her cousin_.
I'm not to sure if this is going to be to much work, but I would like the fourm to take a little peek.

function setup ( )
float a = 0
float b = 0
float co = 0 -- co stands for color
function draw ( )
background (40, 40, 50)
fill (255, 255, 255, 255)
strokeWidth(1)
float x0 = map(sin(a), -1, 1 2-, width -20) -- math.sin ?
float y0 = map(cos(a), -1, 1 2-, height -20)
float x1 = map(sin(b), -1, 1 2-, width -20)
float y1 = map(cos(b), -1, 1 2-, height-20)
line(x0, y0, x1, y1)
line(x0, y0, x1, y1)
co = co + 1
if (co > 100) {
co = 0
}
end
11.jpg 45.1K

Comments

  • dave1707dave1707 Mod
    Posts: 5,996

    @kendog400 To post code correctly, put ~~~ on a line before and after the code. I added them to your code above. Maybe instead of posting code that someone has to convert to Codea, you can convert it yourself. That would be a great way for you to learn how to use Codea. If you run into trouble, just ask and you'll get a lot of help from us. That's how a lot of members learned how to program Codea. They wrote small programs and then increased the size as they learned more.

  • dave1707dave1707 Mod
    Posts: 5,996

    @kendog400 Here a Codea version. Change the slider values to change the design.

    supportedOrientations(LANDSCAPE_ANY)
    
    function setup()
        parameter.integer("a1",1,30,3,reset)
        parameter.integer("b1",1,30,5,reset)
        a,b=0,0
        backingMode(RETAINED)
    end
    
    function draw()
        stroke(0, 213, 255, 255)
        strokeWidth(1)    
        x0=math.sin(a)*WIDTH/2+WIDTH/2
        y0=math.cos(a)*HEIGHT/2+HEIGHT/2
        x1=math.sin(b)*WIDTH/2+WIDTH/2
        y1=math.cos(b)*HEIGHT/2+HEIGHT/2
        line(x0,y0,x1,y1)
        line(x0,y0,x1,y1) 
        a=a+a1/100
        b=b+b1/100
        if a1==b1 then
            fill(255)
            text("a1 and b1 shouldn't be equal",WIDTH/2,HEIGHT/2)
        end
    end
    
    function reset()
        a,b=0,0
        backingMode(RETAINED)
    end
    
  • dave1707dave1707 Mod
    Posts: 5,996

    Here's a version with 3 lines and colors.

    supportedOrientations(LANDSCAPE_ANY)
    
    function setup()
        parameter.integer("a1",1,30,3,reset)
        parameter.integer("b1",1,30,5,reset)
        parameter.integer("c1",1,30,7,reset)
        a,b,c=0,0,0
        backingMode(RETAINED)
    end
    
    function draw()
        stroke(0, 213, 255, 255)
        strokeWidth(1)    
        x0=math.sin(a)*WIDTH/2+WIDTH/2
        y0=math.cos(a)*HEIGHT/2+HEIGHT/2
        x1=math.sin(b)*WIDTH/2+WIDTH/2
        y1=math.cos(b)*HEIGHT/2+HEIGHT/2
        x2=math.sin(c)*WIDTH/2+WIDTH/2
        y2=math.cos(c)*HEIGHT/2+HEIGHT/2
        stroke(255,0,0)
        line(x0,y0,x1,y1)
        stroke(0,255,0)
        line(x0,y0,x2,y2) 
        stroke(0,0,255)
        line(x1,y1,x2,y2) 
        a=a+a1/100
        b=b+b1/100
        c=c+c1/100
    end
    
    function reset()
        a,b,c=0,0,0
        backingMode(RETAINED)
    end
    
  • Posts: 15

    Thank you very much.....

Sign In or Register to comment.