[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
Medium Priority
1,035 Views
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?

jstuardo@aclaris.cl
0
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
1 Comment

LVL 1

Accepted Solution

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

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
Course of the Month14 days, 18 hours left to enroll