I don't know if I'm properly calling a GOval method. My goal is to create the Target corporation logo but with 5 circles. I'm supposed to have the Target symbol centered in the window and have the number of the circles and dimensions controlled by the named constants.
I'm starting with GOval bigCircle and that is my most outer filled circle in color red. Am I properly incorporating the createFilledCircle method?
I only have three circles so far because we're building off a previous assignment and that assignment only had three circles. Also how does N_CIRCLE fit into the picture?
import acm.program.*;
import acm.graphics.*;
import java.awt.*;
public class TargetSymbol extends GraphicsProgram {
public void run(){
double x = getWidth() / 2;
double y = getHeight() / 2;
GOval bigCircle = createFilledCircle(x - OUTER_RADIUS, y - OUTER_RADIUS, 2 * OUTER_RADIUS, 2 * OUTER_RADIUS);
createFilledCircle.setFilled(true);
createFilledCircle.setColor(Color.RED);
add(createFilledCircle);
GOval middleCircle = new GOval(100, 100, 200, 200);
middleCircle.setFilled(true);
middleCircle.setColor(Color.WHITE);
add(middleCircle);
GOval innerCircle = new GOval(155, 150, 100, 100);
innerCircle.setFilled(true);
innerCircle.setColor(Color.RED);
add(innerCircle);
}
private GOval createFilledCircle(double x, double y, double r, Color color){
GOval circle = new GOval( x-r, x-y, 2 * r, 2 * r);
circle.setColor(color);
circle.setFilled(true);
return circle;
}
private static final int N_CIRCLE = 5;
private static final double OUTER_RADUS = 75;
private static final double INNER_RADIUS = 10;
I would say you have the right idea.
GOval bigCircle = createFilledCircle(x - OUTER_RADIUS, y - OUTER_RADIUS, 2 * OUTER_RADIUS, 2 * OUTER_RADIUS);
createFilledCircle.setFilled(true);
createFilledCircle.setColor(Color.RED);
There is no variable called createFilledCircle, so you can't set it to be filled, or set it's color. We could change it to bigCircle, but that would be redundan, as you're already setting those values in the createFilledCircle() method.
I would just recommend you get rid of those 2 parts altogether, leaving you with:
GOval bigCircle = createFilledCircle(x - OUTER_RADIUS, y - OUTER_RADIUS, 2 * OUTER_RADIUS, 2 * OUTER_RADIUS);
N_CIRCLE, I can only assume represents the number of circles there are. For example, if N_CIRCLE is 5, there's the red outer circle, the white circle inside that, a red circle inside that white circle, etc.
Thus you want to use a loop that creates the circles relative to the amount of circles you have (N_CIRCLE).
e.g.
for(int a = 0; a < N_CIRCLE; a++)
{
Create a circle that is smaller than the outer one
Set it's color/fill etc.
}
I did this same assignment and I successfully completed it using this code. I apologize for it being sloppy and in bad form; I wrote it when I was first learning how to write in Java.
/*
* File: Target.java
* Name:
* Section Leader:
* -----------------
* This file is the starter file for the Target problem.
*/
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class Target extends GraphicsProgram {
public void run() {
/* You fill this in. */
double moveX = getWidth()/2 - 36;
double moveY = getHeight()/2 - 36;
GOval outerRed = new GOval(72, 72);
outerRed.setFilled(true);
outerRed.setColor(Color.RED);
outerRed.setFillColor(Color.RED);
outerRed.move(moveX, moveY);
GOval middleWhite = new GOval(12.6, 12.6, 46.8, 46.8);
middleWhite.setFilled(true);
middleWhite.setColor(Color.WHITE);
middleWhite.setFillColor(Color.WHITE);
middleWhite.move(moveX, moveY);
GOval innerRed = new GOval(25.2, 25.2, 21.6, 21.6);
innerRed.setFilled(true);
innerRed.setColor(Color.RED);
innerRed.setFillColor(Color.RED);
innerRed.move(moveX, moveY);
add(outerRed);
add(middleWhite);
add(innerRed);
}
}
Here is my solution to this using constants:
/*
* File: Target.java
* Name:
* Section Leader:
* -----------------
* This file is the starter file for the Target problem.
*/
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class Target extends GraphicsProgram {
private static final int RADIUS_OUTER_CIRCLE = 72;
private static final int RADIUS_MID_CIRCLE = 54;
private static final int RADIUS_INNER_CIRCLE = 32;
public void run() {
GOval outerCircle = new GOval(getWidth()/2 - RADIUS_OUTER_CIRCLE/2 , getHeight()/2 - RADIUS_OUTER_CIRCLE/2, RADIUS_OUTER_CIRCLE, RADIUS_OUTER_CIRCLE);
outerCircle.setFilled(true);
outerCircle.setFillColor(Color.RED);
add(outerCircle);
GOval midCircle = new GOval(getWidth()/2 - RADIUS_MID_CIRCLE/2 , getHeight()/2 - RADIUS_MID_CIRCLE/2, RADIUS_MID_CIRCLE, RADIUS_MID_CIRCLE);
midCircle.setFilled(true);
midCircle.setFillColor(Color.WHITE);
add(midCircle);
GOval innerCircle = new GOval(getWidth()/2 - RADIUS_INNER_CIRCLE/2 , getHeight()/2 - RADIUS_INNER_CIRCLE/2, RADIUS_INNER_CIRCLE, RADIUS_INNER_CIRCLE);
innerCircle.setFilled(true);
innerCircle.setFillColor(Color.RED);
add(innerCircle);
}
}
Related
For the purposes of my project, I'm trying to simulate a phyllotaxis pattern by creating multiple circles in real time using the formulas given.
So recently, I've decided to try out GUI programming in Java using JFrame and swing, and I've hit a wall trying to figure out how to get everything running properly. My idea was to slowly print out circle after circle with their x and y coordinates being calculated from the "r = cos/sin(theta)" formulas documented in the phyllotaxis instructions. Unfortunately, while the x and y values are constantly changing, only one circle is printed. Is there something I am missing?
package gExample;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.Timer;
public class GraphicsExample extends Canvas implements ActionListener {
private final static int HEIGHT = 600;
private final static int WIDTH = 600;
private int n = 0;
private int x, y;
Timer t = new Timer(20, this);
public static void main(String args[]) {
JFrame frame = new JFrame();
GraphicsExample canvas = new GraphicsExample();
canvas.setSize(WIDTH, HEIGHT);
frame.add(canvas);
frame.pack();
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas.setBackground(Color.black);
}
public void paint(Graphics g){
Random rand = new Random();
Color col = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
g.setColor(col);
/*each time paint() is called, I expect a new circle to be printed in the
x and y position that was updated by actionPerformed(), but only one inital circle is created. */
g.fillOval(x, y, 8, 8);
t.start();
}
#Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int c = 9;
double r = c * Math.sqrt(n);
double angle = n * 137.5;
//here, every time the method is called, the x and y values are updated,
//which will be used to fill in a new circle
int x = (int) (r * Math.cos(angle * (Math.PI / 180) )) + (WIDTH / 2);
int y = (int) (r * Math.sin(angle * (Math.PI / 180) )) + (HEIGHT / 2);
//when the program is running, this line of code is executed multiple times.
System.out.println("x: " + x + " y: " + y);
n++;
}
}
public class Hexagon extends JPanel {
// Team that controls the hexagon
public int controller; // 0 neutral // 1 is team 1 // 2 is team 2
// Color of the hexagon
// /* All attributes of the board, used for size an boarder etc... */ Board board
// /* Determines where the hexagon sits on the game board */ int position
public static void main(String args[])
{
JFrame j = new JFrame();
j.setSize(350, 250);
for(int i = 0; i < 121; i++)
{
Hexagon hex = new Hexagon();
j.add(hex);
}
j.setVisible(true);
}
#Override
public void paintComponent(Graphics shape)
{
super.paintComponent(shape);
Polygon hexagon = new Polygon();
// x, y coordinate centers, r is radius from center
Double x, y;
// Define sides of polygon for hexagon
for(int i = 0; i < 6; i++)
{
x = 25 + 22 * Math.cos(i * 2 * Math.PI / 6);
y = 25 + 22 * Math.sin(i * 2 * Math.PI / 6);
hexagon.addPoint(x.intValue(), y.intValue());
}
// Automatic translate
hexagon.translate(10, 10);
// How do I manually control translate?
shape.drawPolygon(hexagon);
}
}
How do I manually translate a polygon? I need to do it to create a game board. So far I've only accomplished automatic translation of polygons which is definitely what I don't need.
I mean like parameterize it so that it's not always 10.
Then you need parameters for your class:
Create a method in your class like `setTranslation(int x, int y) and save the x/y values to instance variables.
In the paintComponent() method you reference these instance variables
Then when you create the Hexagon you can manually set the translation.
Something like:
public void setTranslation(int translationX, int translationY)
{
this.translationX = translationX;
this.translationY = translationY;
}
...
//hexagon.translate(10, 10);
hexagon.translate(translateX, translateY);
...
Hexagon hex = new Hexagon();
hex.setTranslation(10, 10);
Or, you can just pass the translation values as parameters to the constructor of your Hexagon class. The point is you need to have custom properties in your Hexagon class if you want each Hexagon to have a different translation.
I have limited Java experience and am using the program below to teach a high school level student introductory Java. Most programs from the class should work as is before extending it, like the program below. I am able to get the program running in Eclipse and drawing a Blue ball like it states in the code. BUT, I can not get the ball to move up, down, left, or right. Was something left out of this 'starter' code that draws the ball, but does not respond to the arrow keys? It's as if all my keyPressed() code is ignored. Any insights are much appreciated.
.
import java.awt.*;
import java.awt.event.*; // #1
import javax.swing.*;
/******************************************************************************
*
* KeyListenerDemo.java
* Demonstrates getting keyboard input using the KeyListener interface.
*
* Program 18: Extend this program by adding a few more keystroke commands:
* z (VK_Z) - Cause the ball to jump to a random new location.
* s (VK_S) - Make the ball smaller - multiply its diameter 1/2.
* b (VK_B) - Make the ball bigger - multiply its diameter by 2.
* c (VK_C) - Change the color (in any way you'd like).
*
* In addition, modify the program to ensure the following:
* - The ball goes all the way to the edge of the screen but stays
* completely on the screen.
* - If a doubled diameter doesn't fit, make it as large as possible.
* - Be sure the ball never completely disappears.
*
*****************************************************************************/
public class KeyListenerDemo extends JFrame
implements KeyListener // #2
{
// Class Scope Finals
private static final int SCREEN_WIDTH = 1000;
private static final int SCREEN_HEIGHT = 800;
private static final int START_RADIUS = 25;
private static final int START_X = 100;
private static final int START_Y = 100;
private static final int STEP_SIZE = 10;
// Class Scope Variables
private static int x = START_X; // x at center of the ball
private static int y = START_Y; // y at center of the ball
private static int radius = START_RADIUS; // radius of the ball
// Methods
/**
* Create the window and register this as a KeyListener
*
* #param args
*/
public static void main (String[] args)
{
// Set up the JFrame window.
KeyListenerDemo gp = new KeyListenerDemo();
gp.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
gp.setVisible(true);
gp.addKeyListener(gp); // #3
// If this class had a constructor and you moved this line into
// that constructor it could not refer to gp since that variable
// is local to this method. Instead you would write::
// addKeyListener(this);
}
/**
* Called when a key is first pressed
* Required for any KeyListener
*
* #param e Contains info about the key pressed
*/
public void keyPressed(KeyEvent e) // #4A
{
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT)
{
x = x - STEP_SIZE;
}
else if (keyCode == KeyEvent.VK_RIGHT)
{
x = x + STEP_SIZE;
}
else if (keyCode == KeyEvent.VK_UP)
{
y = y - STEP_SIZE;
}
else if (keyCode == KeyEvent.VK_DOWN)
{
y = y + STEP_SIZE;
}
repaint();
}
/**
* Called when typing of a key is completed
* Required for any KeyListener
*
* #param e Contains info about the key typed
*/
public void keyTyped(KeyEvent e) // #4B
{
}
/**
* Called when a key is released
* Required for any KeyListener
*
* #param e Contains info about the key released
*/
public void keyReleased(KeyEvent e) // #4C
{
}
/**
* paint - draw the figure
*
* #param g Graphics object to draw in
*/
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
g.setColor(Color.blue);
g.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
}
}
I'm trying to initialize the breakout game so that the game starts with the paddle added to the canvas at a specified location then have the same paddle move with the mouse.
So, 1. create paddle and add on canvas
2. move paddle as it tracks the mouse's position.
PROBLEM: Paddle added to canvas stays where it is but another paddle NOT ADDED to canvas moves according to event listener. One paddle stays stationary and another tracks the mouse.
I have moved the add(paddle) statement to the mouse
ENV: Mac OSX 10.8.4 , JVM 1.6 (installed with OSX)
Is there some kind of setting in java that needs to be set to refresh the paddle upon mouse event? or is it an environmental issue?
/*
* File: Breakout.java
* -------------------
* Name:
* Section Leader:
*
* This file will eventually implement the game of Breakout.
*/
import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Breakout extends GraphicsProgram {
/** Width and height of application window in pixels */
public static final int APPLICATION_WIDTH = 400;
public static final int APPLICATION_HEIGHT = 600;
/** Dimensions of game board
* Should not be used directly (use getWidth()/getHeight() instead).
* * */
private static final int WIDTH = APPLICATION_WIDTH;
private static final int HEIGHT = APPLICATION_HEIGHT;
/** Dimensions of the paddle */
private static final int PADDLE_WIDTH = 60;
private static final int PADDLE_HEIGHT = 10;
/** Offset of the paddle up from the bottom */
private static final int PADDLE_Y_OFFSET = 30;
/** Number of bricks per row */
private static final int NBRICKS_PER_ROW = 10;
/** Number of rows of bricks */
private static final int NBRICK_ROWS = 10;
/** Separation between bricks */
private static final int BRICK_SEP = 4;
/** Width of a brick */
private static final int BRICK_WIDTH =
(WIDTH - (NBRICKS_PER_ROW - 1) * BRICK_SEP) / NBRICKS_PER_ROW;
/** Height of a brick */
private static final int BRICK_HEIGHT = 8;
/** Radius of the ball in pixels */
private static final int BALL_RADIUS = 10;
/** Offset of the top brick row from the top */
private static final int BRICK_Y_OFFSET = 70;
/** Number of turns */
private static final int NTURNS = 3;
/** ADDED KNM Private Instance Variables */
private GRect paddle;
/* Method: run() */
/** Runs the Breakout program. */
public void run() {
/* You fill this in, along with any subsidiary methods */
init();
}
public void init(){
addMouseListeners();
setSize(APPLICATION_WIDTH,APPLICATION_HEIGHT);
prepTiles();
prepPaddle();
}
private void prepTiles(){
for (int i = 1; i <= NBRICK_ROWS; i++){
int x_pos_start = 0;//(CANVAS_MIDDLE - BRICK_WIDTH/2) - (NBRICKS_PER_ROW/2 - 2)*BRICK_WIDTH;
int y_pos = BRICK_Y_OFFSET + (i-1)*(BRICK_HEIGHT+BRICK_SEP);
Color BRICK_COLOR = getBRICK_COLOR(i);
//case for color fills
for(int y = 1; y <= NBRICKS_PER_ROW; y++ ){
//adjust to beginning of row then add bricks
int x_pos = x_pos_start + ((y-1)*(BRICK_WIDTH+BRICK_SEP));
G3DRect grect = new G3DRect(x_pos, y_pos, BRICK_WIDTH, BRICK_HEIGHT);
grect.setFilled(true);
grect.setColor(BRICK_COLOR);
add(grect);
}
}
}
public void prepPaddle(){
double x_pos = APPLICATION_WIDTH/2 - PADDLE_WIDTH/2;
double y_pos = APPLICATION_HEIGHT - PADDLE_HEIGHT - PADDLE_Y_OFFSET;
paddle = new GRect(x_pos, y_pos, PADDLE_WIDTH, PADDLE_HEIGHT);
paddle.setFilled(true);
paddle.setColor(Color.DARK_GRAY);
add(paddle); // want to keep this.
}
public void mouseMoved(MouseEvent e){
// add(paddle); // I tried moveing the statement here but, that doesn't create the paddle until the mouse hovers above the application canvas.
paddle.setLocation(e.getX() - PADDLE_WIDTH/2, paddle.getY());
if (paddle.getX() <= 0) paddle.setLocation(0, paddle.getY());
if (paddle.getX() + PADDLE_WIDTH >= getWidth()) paddle.setLocation(getWidth() - PADDLE_WIDTH, paddle.getY());
}
private Color getBRICK_COLOR(int i_row){
switch (i_row){
case 1 :
case 2 : return Color.RED;
case 3 :
case 4 : return Color.ORANGE;
case 5 :
case 6 : return Color.yellow;
case 7 :
case 8 : return Color.green;
case 9 :
case 10: return Color.cyan;
default: return Color.black;
}
}
}
You probably just need to call repaint() after moving the paddle.
turns out i was calling init() procedure for the wrong reasons. I renamed the called caused the problem. i changed the function to something else and it all worked out fine. trying to figure out what happened ther
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;
}
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))
}
Including a sin(x) or cos(x) in your function will provide a regular wave pattern, irregular pattern needs a more sophisticated function
I know you already accepted an answer, but here's something to draw additional inspiration from that I whipped up...
package wavy;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Wavy {
public static void main(String[] args) {
final JFrame frame = new JFrame("Wavy!");
final WavyPanel wp = new WavyPanel();
frame.getContentPane().add(wp, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final Ticker t = new Ticker(wp);
final Repainter r = new Repainter(wp);
frame.pack();
frame.setVisible(true);
final Timer tickTimer = new Timer();
final Timer paintTimer = new Timer();
paintTimer.schedule(r, 1000, 50);
tickTimer.schedule(t, 1000, 10);
}
private static class WavyPanel extends JPanel {
private final Dimension size = new Dimension(640, 480);
private int amplitude = 50;
private int frequency = 5;
private int x = 0;
private double y = size.height / 2;
private int yBase = 0;
WavyPanel() {
super(true);
}
#Override
protected void paintComponent(final Graphics g) {
final Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, size.width, size.height);
g2.setColor(Color.BLACK);
g2.fillOval(x, (int)y, 30, 30);
}
#Override
public Dimension getPreferredSize() {
return size;
}
#Override
public Dimension getMinimumSize() {
return size;
}
#Override
public Dimension getMaximumSize() {
return size;
}
public void tick() {
//Move a pixel to the right; loop over to the left when reaching edge
x = (++x) % size.width;
//Length of one full wave = panel width divided by frequency
final int waveLength = size.width / frequency;
//Incrementing yBase; capping off at wavelength
yBase = (++yBase) % waveLength;
//Normalizing to [0..1]
final double normalized = (double)yBase / (double)waveLength;
//Full wave at 2*pi, means...
final double radians = normalized * Math.PI * 2;
//Getting the sine
final double sine = Math.sin(radians);
//Multiplying with amplitude, add to center position and we have our y
y = (int)(sine * amplitude) + size.height/2;
}
}
private static class Ticker extends TimerTask {
private final WavyPanel panel;
Ticker(final WavyPanel panel) {
this.panel = panel;
}
#Override
public void run() {
panel.tick();
}
}
private static class Repainter extends TimerTask {
private final WavyPanel panel;
Repainter(final WavyPanel panel) {
this.panel = panel;
}
#Override
public void run() {
panel.repaint();
}
}
}
This should run at an approximate 20 frames per second. You can increase this by setting the second argument of paintTimer.schedule(r, 1000, 50) lower. The speed of movement can be altered by lowering (speeding up) or increasing (slower) the second argument of tickTimer.schedule(t, 1000, 50).
Changing the amplitude field of WavyPanel will change how high/low the circle moves. Changing the frequency to a higher value will result in shorter waves, while a lower value will produce longer waves.
With some additional work you could add in controls to change the amplitude and frequency on-the-fly. Some additional notes:
You may wish to add some safeguard to the tick() method to make sure that when one invocation is already running, additional ones are skipped until the first one is done. Otherwise the calculations could fail for short tick intervals. A semaphore could be used here.
Since trigonometric calculations aren't exactly the cheapest, you may consider caching some results (e.g. in an array) for re-use if many similar animations are to be played or if there's a lot more drawing going on.
I hope I'm interpreting this right. Could use the sine or cosine of either your x or y coordinate. I'm not at a machine with java so I can't make an example at the moment..
You're right that you need to update both the x and y variables to get a wavy line. Here's the general strategy for a horizontal line that is wavy up and down:
Choose a function f(x) that has the shape you want. This will be used to calculate values for y. (For instance, you can use y = amplitude * Math.sin(frequency * x) to get a regular sine wave of a given amplitude and frequency.)
If necessary, write the code that implements your function.
Set x to some initial value.
In draw, before you paint the oval, calculate y = f(x);. Paint the oval and then increment x. If necessary, reset x so it stays in range.
If you want a vertical line that is wavy left and right, just reverse the roles of x and y in the above. If you want the oval to go in the reverse direction, just decrement instead of increment in step 4.
this sample is for point(Line with one length) on sinus graph and clock using.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RunSwing extends JPanel {
static int x1 = 500;
static int y1 = 500;
static int x2 = x1;
static int y2 = y1;
final static int vectorLength = 100;
final static int sinx2 = x2;
final static int siny2 = y2;
static double count = 0;
private static RunSwing run = new RunSwing();
final Timer print = new Timer(1000, new ActionListener() {
#Override
public void actionPerformed(final ActionEvent e) {
//increaseSinusGraph();
increaseClockVector();
count+=6; //for clock for 1 second
/*count++;//for sinus*/
if (count % 360 == 0)
System.out.println((count / 360) + " minute passed");
}
});
RunSwing() {
print.start();
}
public static void main(String[] args) {
JFrame frame = new JFrame("amir");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(run);
frame.setSize(1100, 700);
frame.setVisible(true);
}
static void increaseClockVector() {
double cos = Math.cos(Math.toRadians(count));
double sin = Math.sin(Math.toRadians(count));
y2 = siny2 + (int) (vectorLength * sin);
x2 = sinx2 + (int) (vectorLength * cos);
}
static void increaseSinusGraph() {
double sin = Math.sin(Math.toRadians(count));
y2 = siny2 + (int) (vectorLength * sin);
x2++;
}
private void createPoint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.drawLine(x2, y2, x2 + 1, y2 + 1);
}
#Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(new Color(0, 0, 0));
g.drawLine(x1, y1, x2, y2);//for clock
/*g.drawLine(x2, y2, x2+1, y2+1);//for sinus*/
repaint();
}
}