This commit is contained in:
BIN
src/lab3_Loops/03-expression-test-loop-fr.pdf
Normal file
BIN
src/lab3_Loops/03-expression-test-loop-fr.pdf
Normal file
Binary file not shown.
47
src/lab3_Loops/DrawArrow.java
Normal file
47
src/lab3_Loops/DrawArrow.java
Normal file
@ -0,0 +1,47 @@
|
||||
package lab3_Loops;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Class using FunGraphics class to draw an arrow.
|
||||
*/
|
||||
public class DrawArrow {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
final int WIDTH = 640;
|
||||
final int HEIGHT = 480;
|
||||
|
||||
// Create and set the windows up
|
||||
FunGraphics display = new FunGraphics(WIDTH, HEIGHT);
|
||||
|
||||
//Set the drawing color to black
|
||||
display.setColor(Color.black);
|
||||
|
||||
/*
|
||||
* Here, you have to modify the code to draw an arrow using setPixel()
|
||||
*/
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
display.setPixel(200+i, 200);;
|
||||
wait(10);
|
||||
}
|
||||
for (int i = 0; i < 20; i++) {
|
||||
display.setPixel(300-i, 200+i);
|
||||
wait(10);
|
||||
}
|
||||
for (int i = 0; i < 20; i++) {
|
||||
display.setPixel(300-i, 200-i);
|
||||
wait(10);
|
||||
}
|
||||
}
|
||||
}
|
74
src/lab3_Loops/Input.java
Normal file
74
src/lab3_Loops/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab3_Loops;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
78
src/lab3_Loops/SimpleCalculator.java
Normal file
78
src/lab3_Loops/SimpleCalculator.java
Normal file
@ -0,0 +1,78 @@
|
||||
package lab3_Loops;
|
||||
/**
|
||||
* This class offers a simple calculator which computes three standard
|
||||
* operations on two numbers entered with the console
|
||||
*
|
||||
* @author Pierre-Andre Mudry (pandre.mudry@hevs.ch)
|
||||
* @author Pierre Roduit (pierre.roduit@hevs.ch)
|
||||
* @version 2.1
|
||||
* @date October 11th 2017
|
||||
*
|
||||
*/
|
||||
public class SimpleCalculator {
|
||||
|
||||
/**
|
||||
* Starting point of the program
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
int x = 0, y = 0;
|
||||
boolean loop = true;
|
||||
|
||||
// Integer used to choose the operator type
|
||||
String operatorType = "0";
|
||||
|
||||
while (loop) {
|
||||
// Display the kind of operations that we can handle
|
||||
System.out.println("Choose now the operator, by entering a number between 1 and 3:\n"
|
||||
+ "1 - Addition\n"
|
||||
+ "2 - Subtraction\n"
|
||||
+ "3 - Multiplication\n"
|
||||
+ "quit - Quitter\n");
|
||||
|
||||
// Read the operator from the console
|
||||
System.out.print("Enter your choice : ");
|
||||
operatorType = Input.readString();
|
||||
if (operatorType.equals("quit")) {
|
||||
System.out.println("finishing");
|
||||
break;
|
||||
} else {
|
||||
System.out.println("debug1");
|
||||
System.out.println(operatorType);
|
||||
}
|
||||
|
||||
// Display the message
|
||||
System.out.println("Take care to enter only integer numbers !");
|
||||
System.out.print("Enter first integer: ");
|
||||
|
||||
// Read the two numbers from the console
|
||||
x = Input.readInt();
|
||||
System.out.print("Enter the second integer: ");
|
||||
y = Input.readInt();
|
||||
|
||||
// Decision tree (The place where you will insert a switch operator)
|
||||
|
||||
switch (operatorType) {
|
||||
case "1":
|
||||
// Display a text and the result of the operation
|
||||
System.out.println("Result of the addition is: " + (x + y));
|
||||
break;
|
||||
|
||||
case "2":
|
||||
// Display a text and the result of the operation
|
||||
System.out.println("Result of the subtraction is: " + (x - y));
|
||||
break;
|
||||
|
||||
case "3":
|
||||
// Display a text and the result of the operation
|
||||
System.out.println("Result of the multiplication is: " + (x * y));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Display an error message
|
||||
System.out.println("You did not enter a correct number for the operation.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
src/lab3_Loops/task1.java
Normal file
14
src/lab3_Loops/task1.java
Normal file
@ -0,0 +1,14 @@
|
||||
package lab3_Loops;
|
||||
|
||||
public class task1 {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int x = 2147480000;
|
||||
for (int i = 0; i < 10; x++) {
|
||||
System.out.println("Number: " + x);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
src/lab3_Loops/task4.java
Normal file
32
src/lab3_Loops/task4.java
Normal file
@ -0,0 +1,32 @@
|
||||
package lab3_Loops;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class task4 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int WIDTH = 640;
|
||||
final int HEIGHT = 480;
|
||||
|
||||
// Create and set the windows up
|
||||
FunGraphics display = new FunGraphics(WIDTH, HEIGHT);
|
||||
for (int i = 0; i < WIDTH; i++) {
|
||||
for (int j = 0; j < HEIGHT; j++) {
|
||||
display.setPixel(i, j, Color.BLUE);
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
src/lab3_Loops/task5.java
Normal file
31
src/lab3_Loops/task5.java
Normal file
@ -0,0 +1,31 @@
|
||||
package lab3_Loops;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class task5 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int WIDTH = 256;
|
||||
final int HEIGHT = 256;
|
||||
|
||||
// Create and set the windows up
|
||||
FunGraphics display = new FunGraphics(WIDTH, HEIGHT);
|
||||
for (int i = 0; i < WIDTH; i++) {
|
||||
for (int j = 0; j < HEIGHT; j++) {
|
||||
display.setPixel(i, j, new Color(i, 0, j));
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
src/lab3_Loops/task6.java
Normal file
33
src/lab3_Loops/task6.java
Normal file
@ -0,0 +1,33 @@
|
||||
package lab3_Loops;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class task6 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int width = 400;
|
||||
int height = 400;
|
||||
boolean condition = false;
|
||||
FunGraphics display = new FunGraphics(width, height);
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
condition = false;
|
||||
int dist_x = Math.abs(i-200);
|
||||
int dist_y = Math.abs(j-200);
|
||||
int distance = (int) Math.sqrt( Math.pow(dist_x, 2) + Math.pow(dist_y, 2));
|
||||
// pythagore pour distance
|
||||
if (distance < 100) {
|
||||
condition = true;
|
||||
}
|
||||
|
||||
if (condition) {
|
||||
display.setPixel(i, j, Color.BLUE);
|
||||
} else {
|
||||
display.setPixel(i, j, Color.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
34
src/lab3_Loops/task7.java
Normal file
34
src/lab3_Loops/task7.java
Normal file
@ -0,0 +1,34 @@
|
||||
package lab3_Loops;
|
||||
import hevs.graphics.FunGraphics;
|
||||
//import java.awt.Color;
|
||||
|
||||
public class task7 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
int width = 1000;
|
||||
int height = 1000;
|
||||
int delay = 1;
|
||||
int tps_total = 600000;
|
||||
FunGraphics display = new FunGraphics(width, height);
|
||||
|
||||
|
||||
for (double i = 0; i < (tps_total/delay); i+= 0.01) {
|
||||
display.setPixel( (int)(400*Math.sin(i) / (1+Math.cos(i)*Math.cos(i))+500) , (int)((400*Math.sin(i)*Math.cos(i)) / (1+Math.cos(i)*Math.cos(i))+500));
|
||||
wait(delay);
|
||||
//mieux par gestion du framreate (voir sur le site https://inf1.begincoding.net/la-librairie-fungraphics-2/)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user