The Artima Developer Community
Sponsored Link

Java Answers Forum
scaling problem.....!??!!!!

2 replies on 1 page. Most recent reply: Oct 26, 2002 9:29 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
ravikumar

Posts: 10
Nickname: ji
Registered: Oct, 2002

scaling problem.....!??!!!! Posted: Oct 25, 2002 10:06 AM
Reply to this message Reply
Advertisement
hi ,
i know this is simple, but somehow i am not getting it....I am giving part of my code below....I want to plot Cosine graph...As long as i dont keep the variable 'value' i am getting the graph fine...but when i put the 'value' variable, it is plotting between the pixel values 64 and 65 only, so i cannot see any graph.....'value' is a very small number something like 0.01 to 0.00013.....so how do i scale it to show on the full applet? my applet size starts from (140,10) and ends at(500,140)....
----------------
initialx = 0;
initialy=0;
finalx = 0;
finaly = 0;
for(int i =0;i<=360;i++)
{
angle = i*2.0*Math.PI/360.0;
fx = value*Math.cos(2.0*angle);
finalx = i;
finaly = (int)((1.0 - fx)*65.0);
g.drawLine(initialx,initialy,finalx,finaly);
initialx = finalx;
initialy = finaly;
}


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: scaling problem.....!??!!!! Posted: Oct 26, 2002 8:15 AM
Reply to this message Reply
There is a sine wave grapher at:
http://www.quantumhyperspace.com/SourceBank/SineWaveGrapher.java

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: scaling problem.....!??!!!! Posted: Oct 26, 2002 9:29 AM
Reply to this message Reply

/** CosineWaveGrapher.java
* @author Charles Bell
* @version Oct 26, 2002
*/

import java.awt.*;
import javax.swing.*;

public class CosineWaveGrapher extends JFrame{

public CosineWaveGrapher(){
super("CosineWaveGrapher");
init();
}

public static void main(String[] args){
CosineWaveGrapher grapher = new CosineWaveGrapher();
}


public void init(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(new GrapherPanel(), BorderLayout.CENTER);
pack();
setLocationRelativeTo(null);
show();
}


class GrapherPanel extends JPanel{

public GrapherPanel(){
super();
setPreferredSize(new Dimension(620,420));
}

public void paint(Graphics g){
super.paintComponent(g);
g.setColor(Color.black);
g.translate(310, 210);
g.drawLine(-300, 200, 300, 200); //across top
g.drawLine(-300, 0, 300, 0); //across middle
g.drawLine(-300,-200, 300, -200); //across bottom
g.drawLine(-300, -200, -300, 200); //down left side
g.drawLine(-150, -200, -150, 200); //down left side
g.drawLine(0, -200, 0, 200); //down middle
g.drawLine(150, -200, 150, 200); //down right side
g.drawLine(300, -200, 300, 200); //down right side
char piChar = '\u03c0';
g.drawString("-2" + piChar, -290, -10);
g.drawString("-" + piChar , -140, -10);
g.drawString("0" , 10, -10);
g.drawString("+" +piChar, 160, -10);
g.drawString("+2" +piChar, 270, -10);
g.drawString("+1" , 10, -185);
g.drawString("-1" , 10, 195);
int x0 = -300;
int y0 = 0;
int x1 = -300;
int y1 = 0;
double pi = Math.PI;
for (double theta = -2 * pi; theta <= 2 * pi; theta=theta + pi/500){
x1 = (int) ((theta*300)/(2 * pi));
y1 = -(int)(200 * Math.cos(theta));
g.drawLine(x0,y0,x1,y1);
//System.out.println("x1: " + x1 + " y1: " + y1);
x0 = x1;
y0 = y1;
}
}
}
}

Flat View: This topic has 2 replies on 1 page
Topic: Array of parameters passing to Form in Java Previous Topic   Next Topic Topic: JToolBar

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use