[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Drawing sinusoidal wave

Posted on 1998-12-18
1
Medium Priority
?
1,035 Views
Last Modified: 2008-03-10
Hi all again!! do you have a function which draws a sin wave using the sin method of Math class? Or at least, can you guide me in programming that function by myself?

Thanks a lot in advance
jstuardo@aclaris.cl
0
Comment
Question by:skel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
malexiev earned 200 total points
ID: 1229731
Try this:

  import java.awt.*;  
  import java.applet.*;
 
  public class Test
  extends Applet {  
   
    private final double scale = 50;
    private double step = 1 / scale;
   
    public Test() {
    }    
   
    public void drawSin(Graphics g, double x0, double x1) {
     
      g.setColor(Color.red);      
      int i = 0;      
      int y0 = getBounds().height >> 1;
      for (double f = x0; f < x1; f += step,i++) {
        g.drawLine(i, (int)((Math.sin(f)) * scale + y0),
                   i, (int)((Math.sin(f)) * scale + y0));
       
      }
    }
   
    public void paint(Graphics g) {
      drawSin(g, -Math.PI, Math.PI);
    }
  }

Hope this helps.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question