import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
public class Heart extends JFrame{
static int amount;
public static void main(String[]args){
Heart frame = new Heart();
frame.setSize(800,640);
frame.setVisible(true);
}
Heart(){
System.out.println("Enter positive distance from lens (in cm) - Enter one of these values: 1, 2, 3, 4, 5 or 6:");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextInt();
}
public void paint (Graphics page)
{
final int MID = 150;
final int TOP = 50;
setTitle("Convex lens");
double x;
double x1;
double x2;
double y1;
double y2;
double yr1;
double yr2;
double ox;
double o;
int oxo;
int oy;
int y11;
int y22;
int x11;
int x22;
x=0;
ox=0;
x1=0;
x2=800;
y1=0;
y2=0;
y11=0;
y22=0;
if (Heart.amount==1){
x=250;
System.out.println("Image is virtual, magnified and upright");}
if (Heart.amount==2){
x=200;
System.out.println("Image is virtual, magnified and upright");}
if (Heart.amount==3){
x=150;
System.out.println("Image is real, magnified and inverted");}
if (Heart.amount==4){
x=100;
System.out.println("Image is real, magnified and inverted");}
if (Heart.amount==5){
x=50;
System.out.println("Image is real, diminished and inverted");}
if (Heart.amount==6){
x=0;
System.out.println("Image is real, diminished and inverted");}
//System.out.println(x);
//ray1calc
y1 = -1*(((-50/(300-x))*(-x)) - 200);
y2 = -1*(((-50/(300-x))*(800 - x)) - 200);
//ray2calc
//yr1 = -1*(((-45.0/(100.0))*(-300.0)) - 250.0);
//yr2 = -1*(((-45.0/(100.0))*(800.0-300.0)) - 250.0);
y11 = (int) y1;
y22 = (int) y2;
int xo = (int) x;
x11 = (int) x1;
x22 = (int) x2;
//yr11 = (int) yr1;
//yr22 = (int) yr2;
//intersect calc
ox = (((-0.45*x) + 85)/((-50/(300-x))) + x);
oxo = (int) ox;
o = -1*(((-50/(300-x))*(ox - x)) - 200);
oy = (int) o;
page.drawOval(oxo,oy,10,10);
//System.out.println(y1);
//System.out.println(y2);
//lens
page.setColor (Color.blue);
page.fillArc (300, 150, 50, 200,90,180); // sun
//page.fillArc (300, 150, 50, 200,270,180);
//Focal Point
page.setColor (Color.red);
page.drawOval(400,245,10,10);
page.drawOval(200,245,10,10);
//Radius of Curvature
page.fillOval(500,245,10,10);
page.fillOval(100,245,10,10);
//Graphics2D g2 = (Graphics2D)page;
//g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
//RenderingHints.VALUE_ANTIALIAS_ON);
//Font font = new Font("Serif", Font.PLAIN, 10);
//g2.setFont(font);
//g2.drawString("Focal Point", 400, 270);
//WORDS
//page.drawString("Focal Point", 400, 270);
page.drawString("Focal Point", 200, 270);
page.drawString("Radius of Curvature", 100, 280);
//page.drawString("Radius of Curvature", 500, 280);
//Object
page.drawLine(xo, 250, xo, 200);
//Normal
page.drawLine(10, 250, 600, 250);
//Scale
page.setColor(Color.green);
page.drawLine(250, 250, 250, 240);
page.setColor(Color.green);
page.drawLine(200, 250, 200, 240);
page.setColor(Color.green);
page.drawLine(150, 250, 150, 240);
page.setColor(Color.green);
page.drawLine(100, 250, 100, 240);
page.setColor(Color.green);
page.drawLine(50, 250, 50, 240);
page.setColor(Color.green);
page.drawLine(0, 250, 0, 240);
//ray1
page.setColor(Color.orange);
page.drawLine(xo, 200, 300, 200);
//ray2
page.setColor(Color.yellow);
page.drawLine(0, 65, 600, 335);
//Write equation for this
//ray3
page.drawLine(x11,y11,x22,y22);
//ray1calc - intersect at (300,200)
//
//
}
}