Simple Graphics Effects with Sin and Cos

Hey, just working on some fancy game graphics. It’s a pretty simple function that makes the image pulse, and if you change one sin to cos it gives the image a sort of underwater effect

function setup()
    
end

function draw()
    background(40, 40, 50)
    sprite("Tyrian Remastered:Blimp Boss",WIDTH/2,HEIGHT/2,
    math.sin(10*ElapsedTime)*50+500,math.sin(10*ElapsedTime)*50+500)
end

Nice. You might find tweens more efficient (no need for trig functions)

function setup()
    size=vec2(450,550)
    tween( 0.5, size, { x = 550, y=450 }, { easing = tween.easing.linear, 
                                        loop = tween.loop.pingpong } )
end

function draw()
    background(40, 40, 50)
    sprite("Tyrian Remastered:Blimp Boss",WIDTH/2,HEIGHT/2,size.x,size.y)
end

I think the trig example feels more fluid, and using tweens feels a bit more rigid. Tweens do provide a larger range of effects, though, so it all depends on the personality you want

Tweens have a sin easing function too.

I’m not sure tweens are necessarily more efficient in this case. Same math is done in both cases, and trigonometry functions are implemented in C anyway. I’d actually expect the no-tweens solution to use less resources… but no easy way to check.

( Adding FPS counter doesn’t resolve the dispute one way or the other :slight_smile: - solid 60 for both )

@yojimbo2000 the sine tween still has a completely different effect

interesting tween effects?very nice