Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:35:14+00:00 2026-05-27T04:35:14+00:00

I know the following code will move an object in a straight line. How

  • 0

I know the following code will move an object in a straight line. How can I get the object to travel in a wavy line? I know that something extra is required for the x variable.

public void draw(Graphics2D g) 
        {
            g.setColor(Color.WHITE);
            g.fillOval ((int) (x - r), (int) (y - r), (int)
                    (2 * r),
                    (int) (2 * r));

            y++;


            if (y - r > height)
                y = -r;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:35:15+00:00Added an answer on May 27, 2026 at 4:35 am

    Use the sine or cosine function to calculate y as a function of x.

    Multiply the sine or cosine function to increase the amplitude (how high it goes)

    y = 100 * sin(x) // will make it have peaks of -100 and 100
    

    Divide the x to increase the period. (distance between peaks)

    y = sin(x/2) // will make it take twice the x distance between peaks.
    

    Something like this:

    public void draw(Graphics2D g) 
        {
            g.setColor(Color.WHITE);
            g.fillOval ((int) (x - r), (int) (y - r), (int)
                    (2 * r),
                    (int) (2 * r));
    
            x++; // Left to right movement
            // Example, modify the multipliers as necessary
            y = 100 * Math.sin(Math.toDegrees(x/4))
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how I can get rid of the following assembler warning? Code
I have the following code in a UIView subclass that will move it off
I know that the following code should show and hide a tiny circular progress
I learned that auto-variables aren't initialized to zero. So the following code will behave
first let me say I know the following code will be considered bad practices..
I have a problem want to know answer, Why the following code will print
I know C, but I'm not good at C++. The following code will crash
I know the following code could extract whole texts of the docx document, however,
I know why the following code doesn't compile: public class Main { public static
Does anybody know why the following code only has effect in FF? $(document).ready(function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.