This commit is contained in:
HORVILLE 2022-10-26 11:13:11 +02:00
parent 768f122da4
commit ca5a8516fd
15 changed files with 409 additions and 4 deletions

View File

@ -6,7 +6,6 @@ public class LumListener implements MouseListener {
public void mouseClicked(MouseEvent e) {
LumPanel p = (LumPanel)e.getSource();
p.removeParralel(e.getX(), e.getY());
}
@Override

View File

@ -1,17 +1,20 @@
import javax.swing.JPanel;
import java.awt.*;
import java.util.LinkedList;
import java.util.Random;
public class LumPanel extends JPanel {
private ListChain<Color> l;
private LinkedList<Color> l;
int width = 30;
int offset = 30;
int height = 60;
int spacing = 5;
int mx, my = 0;
public LumPanel() {
l = new ListChain<Color>();
l = new LinkedList<Color>();
Random r = new Random();
for (int i = 0; i < 10; i++) {
@ -41,6 +44,18 @@ public class LumPanel extends JPanel {
}
}
public void setMCoords(int x, int y) {
double dx = (double)x;
double dy = (double)y;
dx -= lerp(offset, 0, dy / (double)height);
dx -= spacing * Math.floor(dx / width);
this.mx = (int)dx;
this.my = (int)dy;
repaint();
}
@Override
protected void paintComponent(Graphics g) {
Graphics gg = g.create();
@ -61,6 +76,9 @@ public class LumPanel extends JPanel {
p.addPoint(x + width, getY() + height);
p.addPoint(x, getY() + height);
gg.setColor(Color.BLACK);
gg.fillOval(mx-3, my-3, 6, 6);
gg.setColor(c);
gg.fillPolygon(p);
gg.setColor(Color.BLACK);

View File

@ -1,5 +1,5 @@
import javax.swing.JFrame;
import java.awt.*;
/**
* Luminance
*/
@ -21,5 +21,10 @@ public class Luminance {
f.setVisible(true);
lm.addMouseListener(new LumListener());
while (true) {
Point p = MouseInfo.getPointerInfo().getLocation();
lm.setMCoords(p.x - lm.getLocationOnScreen().x, p.y - lm.getLocationOnScreen().y);
}
}
}

View File

@ -0,0 +1,49 @@
import java.util.ArrayDeque;
/**
* Arithmetique
*/
public class Arithmetique {
public static void main(String[] args) {
ArrayDeque<Integer> pile = new ArrayDeque<>();
for (String arg : args) {
try {
int n = Integer.parseInt(arg);
pile.addFirst(n);
} catch (NumberFormatException e) {
if (pile.size() < 2) {
System.err.println("Invalid stack size.");
return;
}
int n2 = pile.pollFirst();
int n1 = pile.pollFirst();
switch (arg) {
case "+":
pile.addFirst(n1 + n2);
break;
case "-":
pile.addFirst(n1 - n2);
break;
case "/":
pile.addFirst(n1 / n2);
break;
case "x":
pile.addFirst(n1 * n2);
break;
default:
System.err.println("Invalid operator");
return;
}
}
}
System.out.println(pile.pollFirst());
}
}

View File

@ -0,0 +1,44 @@
public class Arithmetique {
public static void main(String[] args) {
ChainePile<Integer> pile = new ChainePile<>();
for (String arg : args) {
try {
int n = Integer.parseInt(arg);
pile.addFirst(n);
} catch (NumberFormatException e) {
if (pile.size() < 2) {
System.err.println("Invalid stack size.");
return;
}
int n2 = pile.pollFirst();
int n1 = pile.pollFirst();
switch (arg) {
case "+":
pile.addFirst(n1 + n2);
break;
case "-":
pile.addFirst(n1 - n2);
break;
case "/":
pile.addFirst(n1 / n2);
break;
case "x":
pile.addFirst(n1 * n2);
break;
default:
System.err.println("Invalid operator");
return;
}
}
}
System.out.println(pile.pollFirst());
}
}

View File

@ -0,0 +1,25 @@
public class Chaine<E> {
public Chaine() {
}
private E value;
private Chaine<E> next;
public E getValue() {
return value;
}
public void setValue(E value) {
this.value = value;
}
public Chaine<E> getNext() {
return next;
}
public void setNext(Chaine<E> next) {
this.next = next;
}
}

View File

@ -0,0 +1,47 @@
public class ChainePile<E> implements Pile<E> {
private Chaine<E> lastChain;
public ChainePile() {}
@Override
public E getFirst() {
if (lastChain != null) {
return lastChain.getValue();
} else {
return null;
}
}
@Override
public E pollFirst() {
if (lastChain != null) {
E value = lastChain.getValue();
lastChain = lastChain.getNext();
return value;
} else {
return null;
}
}
@Override
public void addFirst(E e) {
Chaine<E> link = new Chaine<E>();
link.setValue(e);
link.setNext(lastChain);
lastChain = link;
}
@Override
public int size() {
int count = 0;
Chaine<E> curr = lastChain;
while (curr != null) {
curr = curr.getNext();
count++;
}
return count;
}
}

View File

@ -0,0 +1,6 @@
public interface Pile<E> {
public E getFirst();
public E pollFirst();
public void addFirst(E e);
public int size();
}

View File

@ -0,0 +1,55 @@
public class ArrayPile<E> implements Pile<E>{
int size = 16;
int currentElement = 0;
E[] table;
public ArrayPile() {
table = (E[])new Object[size];
};
private void resizeStack() {
size *= 2;
E[] newTable = (E[])new Object[size];
for (int i = 0; i < table.length; i++) {
newTable[i] = table[i];
}
table = newTable;
}
@Override
public E getFirst() {
if (currentElement == 0) {
return null;
} else {
return table[currentElement-1];
}
}
@Override
public E pollFirst() {
if (currentElement == 0) {
return null;
} else {
E e = table[currentElement-1];
currentElement--;
return e;
}
}
@Override
public void addFirst(E e) {
if (currentElement >= table.length) resizeStack();
table[currentElement] = e;
currentElement++;
}
@Override
public int size() {
return currentElement;
}
}

View File

@ -0,0 +1,34 @@
public class Derecursif {
public static int f(int n) {
ArrayPile<Integer> pile = new ArrayPile<>();
pile.addFirst(n);
int result = 0;
while (pile.size() > 0) {
n = pile.pollFirst();
switch (n) {
case 0:
break;
case 1:
result += 1;
break;
default:
pile.addFirst(n / 2);
pile.addFirst(n / 3);
break;
}
}
return result;
}
public static void main(String[] args) {
System.out.println(f(150));
}
}

View File

@ -0,0 +1,6 @@
public interface Pile<E> {
public E getFirst();
public E pollFirst();
public void addFirst(E e);
public int size();
}

View File

@ -0,0 +1,12 @@
public class Recursif {
public static double f(double v) {
if (v == 0) return 0.0;
if (v == 1) return 1.0;
return v + f(Math.floor(v / 2)) - f(Math.floor(v / 3));
}
public static void main(String[] args) {
System.out.println(f(250));
}
}

View File

@ -0,0 +1,44 @@
public class Arithmetique {
public static void main(String[] args) {
ArrayPile<Integer> pile = new ArrayPile<>();
for (String arg : args) {
try {
int n = Integer.parseInt(arg);
pile.addFirst(n);
} catch (NumberFormatException e) {
if (pile.size() < 2) {
System.err.println("Invalid stack size.");
return;
}
int n2 = pile.pollFirst();
int n1 = pile.pollFirst();
switch (arg) {
case "+":
pile.addFirst(n1 + n2);
break;
case "-":
pile.addFirst(n1 - n2);
break;
case "/":
pile.addFirst(n1 / n2);
break;
case "x":
pile.addFirst(n1 * n2);
break;
default:
System.err.println("Invalid operator");
return;
}
}
}
System.out.println(pile.pollFirst());
}
}

View File

@ -0,0 +1,55 @@
public class ArrayPile<E> implements Pile<E>{
int size = 16;
int currentElement = 0;
E[] table;
public ArrayPile() {
table = (E[])new Object[size];
};
private void resizeStack() {
size *= 2;
E[] newTable = (E[])new Object[size];
for (int i = 0; i < table.length; i++) {
newTable[i] = table[i];
}
table = newTable;
}
@Override
public E getFirst() {
if (currentElement == 0) {
return null;
} else {
return table[currentElement-1];
}
}
@Override
public E pollFirst() {
if (currentElement == 0) {
return null;
} else {
E e = table[currentElement-1];
currentElement--;
return e;
}
}
@Override
public void addFirst(E e) {
if (currentElement >= table.length) resizeStack();
table[currentElement] = e;
currentElement++;
}
@Override
public int size() {
return currentElement;
}
}

View File

@ -0,0 +1,6 @@
public interface Pile<E> {
public E getFirst();
public E pollFirst();
public void addFirst(E e);
public int size();
}