From 081d95d9dc2f9c316f91628c6639bb3561ad04a1 Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Thu, 6 Oct 2022 14:58:27 +0200 Subject: [PATCH] Fun Graphique --- Fun/NewMalloc/newmem.c | 15 -------- Fun/NewMalloc/newmem.h | 6 --- Fun/NewMalloc/test.c | 9 ----- Fun/TestGraphique/Fun.java | 23 ++++++++++++ Fun/TestGraphique/FunPanel.java | 31 ++++++++++++++++ Fun/TestGraphique/Vector2.java | 66 +++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 30 deletions(-) delete mode 100644 Fun/NewMalloc/newmem.c delete mode 100644 Fun/NewMalloc/newmem.h delete mode 100644 Fun/NewMalloc/test.c create mode 100644 Fun/TestGraphique/Fun.java create mode 100644 Fun/TestGraphique/FunPanel.java create mode 100644 Fun/TestGraphique/Vector2.java diff --git a/Fun/NewMalloc/newmem.c b/Fun/NewMalloc/newmem.c deleted file mode 100644 index 5718c02..0000000 --- a/Fun/NewMalloc/newmem.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -#include "newmem.h" - -void* newmalloc(size_t size) { - void* start = sbrk(0); - void* finish = sbrk(size); - - printf("%d\n", finish); - - if (start == finish) return NULL; - return finish; -} \ No newline at end of file diff --git a/Fun/NewMalloc/newmem.h b/Fun/NewMalloc/newmem.h deleted file mode 100644 index 947bb94..0000000 --- a/Fun/NewMalloc/newmem.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef NEWMEM -#define NEWMEM - -void* newmalloc(size_t size); - -#endif \ No newline at end of file diff --git a/Fun/NewMalloc/test.c b/Fun/NewMalloc/test.c deleted file mode 100644 index 3b2fb44..0000000 --- a/Fun/NewMalloc/test.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include "newmem.h" - -int main(void) { - char* t = (char*)newmalloc(15); - - printf("%d", t != NULL); -} \ No newline at end of file diff --git a/Fun/TestGraphique/Fun.java b/Fun/TestGraphique/Fun.java new file mode 100644 index 0000000..7a9eb54 --- /dev/null +++ b/Fun/TestGraphique/Fun.java @@ -0,0 +1,23 @@ +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import javax.swing.JFrame; + +/** + * Fun + */ +public class Fun { + + public static void main(String[] args) { + FunPanel p = new FunPanel(); + + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocation(100, 100); + frame.setSize(700, 700); + frame.add(p); + + frame.setVisible(true); + p.repaint(); + } +} \ No newline at end of file diff --git a/Fun/TestGraphique/FunPanel.java b/Fun/TestGraphique/FunPanel.java new file mode 100644 index 0000000..287c260 --- /dev/null +++ b/Fun/TestGraphique/FunPanel.java @@ -0,0 +1,31 @@ +import javax.swing.JPanel; +import java.awt.*; + +public class FunPanel extends JPanel { + private int table = 3; + private int limit = 150; + + public FunPanel() { + super(); + } + + @Override + protected void paintComponent(Graphics g) { + Graphics gg = g.create(); + + if (this.isOpaque()) { + gg.setColor(getBackground()); + gg.fillRect(this.getX(), this.getY(), getWidth(), getHeight()); + } + + double size = (double)getX(); + System.out.println(size); + + gg.setColor(Color.RED); + for (double i = 0; i < limit; i++) { + double theta = (i / (double)limit) * Math.PI * 2; + + gg.fillOval((int)(Math.cos(theta) * size) + getX() / 2, (int)(Math.sin(theta) * size) + getY() / 2, 10, 10); + } + } +} diff --git a/Fun/TestGraphique/Vector2.java b/Fun/TestGraphique/Vector2.java new file mode 100644 index 0000000..4132482 --- /dev/null +++ b/Fun/TestGraphique/Vector2.java @@ -0,0 +1,66 @@ +import java.awt.Point; + +public class Vector2 extends Point { + public Vector2(int x, int y) { + super(x, y); + } + + public void add(Point p) { + this.x += p.x; + this.y += p.y; + } + + public void sub(Point p) { + this.x -= p.x; + this.y -= p.y; + } + + public void mul(Point p) { + this.x *= p.x; + this.y *= p.y; + } + + public void mul(int n) { + this.x *= n; + this.y *= n; + } + + public static Vector2 lerp(Point a, Point b, double t) { + double ax = (double)a.x; + double bx = (double)b.x; + double ay = (double)a.y; + double by = (double)b.y; + + return new Vector2((int)(ax + (bx - ax) * t), (int)(ay + (by - ay) * t)); + } + + public void lerpTo(Point a, double t) { + double ax = (double)this.x; + double bx = (double)a.x; + double ay = (double)this.y; + double by = (double)a.y; + + this.x = (int)(ax + (bx - ax) * t); + this.y = (int)(ay + (by - ay) * t); + } + + public double length() { + double x = (double)this.x; + double y = (double)this.y; + + return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); + } + + public void normalize() { + double x = (double)this.x; + double y = (double)this.y; + double length = this.length(); + + this.x = (int)(x / length); + this.y = (int)(y / length); + } + + public Vector2 toLocal(Point p) { + return new Vector2(p.x - this.x, p.y - this.y); + } +}