Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Sine Waves — Gideros Forum

Sine Waves

HarrisonHarrison Member
edited June 2014 in Step by step tutorials
Just a bit ago i learned about how cool waves are and i figured that i should share it with you guys! So here it is:
y=h*math.sin(u*x)
where h is height and u is oscillation speed (up and down)
x is the x and y is the y :D
oh! and dont forget to update the x or it wont move!
x=x+1
the sample code:
-- load 
blimpx=10
blimpy=blimpx
local blimp = Bitmap.new(Texture.new("images/blimp.png"))
blimp:setPosition(20, 20)
blimp:setScale(0.5,0.5)
stage:addChild(blimp)
function onEnterFrame(event)
blimpx=blimpx+1
blimpy=10*math.sin(0.1*blimpx)
blimp:setPosition(blimpx, blimpy)
end
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
There you go, when you put it all together you get a cool sine wave effect that is fun to mess around with.
cosine is almost the same, but the wobbles are in a different spot- try it out.
Now, you may ask, what does this have to do with app dev?
Sine waves are (or can be) used in many games, whenever you see something wobble while moving forward!
I will post here when i find out more useful line formulas!
Feel free to post what you did with sine waves.
Note:you will have to add the image manually in gideros. make a folder called images (in gideros) and put blimp.png (findable in the .zip) in it.
The sample game:

Likes: SinisterSoft

“ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • altaialtai Member
    Cool :) @Harrison thanks, you can add with
    < pre lang="lua">
    --your codes
    < /pre>

    remove first whitespaces from the tags
  • Is it possible to move image without waves? Straight.
  • @Harrison, Brilliant!
    Please keep us informed if you find a new formula!

    @unlying, why do you need to move image without wave, if you can move it with waves?!? :-?
  • HarrisonHarrison Member
    edited April 2014
    @unlying
    if you want to move it straight, it would be
    y=1
    x=x+1
    is that what you are wondering?
    “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
  • ar2rsawseenar2rsawseen Maintainer
    Looks like flappy bird :D
    But blimp file was missing, though
  • @Harrison not really. We have a sine waves movement. So we need to compensate these vibration to move it straight, yes? May be you have to make it as library for move things. Sine, cos, straight and other? I think it should be a free to play version of this library. Sine is free and others for money. And of course move it vertically.
  • whenever i play hill climb.. i wonder...
    “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
  • HarrisonHarrison Member
    edited April 2014
    @unlying
    So.. you want square waves?
    or you just want a flat sine wave?
    perhaps the next wave i do will be a square one...
    edit:
    @ar2sawseen image added!
    “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
  • @Harrison. Nice little tutorial, nicely explained and should help a lot of people just starting out. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • @unlying, Appetite comes with eating

    @Harrison, flate wave would be very useful in my project. Please start with it!
  • HarrisonHarrison Member
    edited April 2014
    @asakharov
    Square waves are hard to do, but you can compromise and make almost square waves:
    square, but a just a little wobbly at the top and bottom:
    y=a*math.sin(2*math.sin(2*math.sin(2*math.sin(x))))
    where a makes it taller.
    i have not tested it but adding in (l*x) would probably allow you to adjust length.
    “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
Sign In or Register to comment.