Drawing Into Ellipses

All,
Is there any sort of way to possibly use setContext() to draw into an ellipse instead of just a blank image??

Thanks in advance :slight_smile:

Do you want to place an image into an ellipse area. Not sure what you mean by draw into an ellipse.

@Creator27 - have you tried placing a sprite in front of a filled ellipse and then behind an unfilled ellipse making the ellipse stroke fairly thick?

Seems like the easiest way to do it. You can use Z layer level to adjust the order, but sprite() then ellipse() in that order should work.

Like this


function setup()
    sprt = asset.builtin.Cargo_Bot.Codea_Icon
end

function draw()
    background(40, 40, 50)
    fill(22, 51, 206)
    ellipse(WIDTH/2,HEIGHT/2,380,280)
    sprite(sprt,WIDTH/2,HEIGHT/2-10,240,240)
    noFill()
    stroke(250, 2, 230)
    strokeWidth(20)
    ellipse(WIDTH/2,HEIGHT/2,380,280)
end

@dave1707, that’s exactly what I wanted to do.

Is this something like what you’re after.

viewer.mode=FULLSCREEN

function setup()  
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
    scene = craft.scene()
    v=scene.camera:add(OrbitViewer,vec3(0,0,0), 200, 0, 1000)
    img=readImage(asset.builtin.Cargo_Bot.Startup_Screen)
    v.rx,v.ry=-180,180
    step=1
    radius=40
    p1=vec3(0,0,0)
    s1=vec2(.5,.5)
    xRad=.8 --  0 to 1  changes size of ellipse
    yRad=.95 --  0 to 1  changes size of ellipse
    for a=0,359,step do
        x=math.cos(math.rad(a))*xRad
        y=math.sin(math.rad(a))*yRad
        p2=vec3(x*radius,0,y*radius)
        s2=vec2(x*.5+.5,y*.5+.5)
        x=math.cos(math.rad(a+step))*xRad
        y=math.sin(math.rad(a+step))*yRad
        p3=vec3(x*radius,0,y*radius)
        s3=vec2(x*.5+.5,y*.5+.5)
        createSlice(p1,p2,p3,s1,s2,s3) 
    end
end

function draw()
    update(DeltaTime)
    scene:draw() 
end

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

function createSlice(p1,p2,p3,s1,s2,s3)
    local c=color(255, 255, 255, 255)
    local r=scene:entity()
    r.model = craft.model()
    r.model.positions={p1,p2,p3}
    r.model.indices={1,2,3,3,2,1}
    r.model.colors={c,c,c}
    r.model.uvs={s1,s2,s3}
    r.material = craft.material(asset.builtin.Materials.Basic)  
    r.material.map=img
end

@dave1707, thank you so much for your code, and yes that’s exactly what I’m after!