Solved

Drawing sinusoidal wave

Posted on 1998-12-18
1
1,021 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
1 Comment
 
LVL 1

Accepted Solution

by:
malexiev earned 50 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now