Fun Graphique

This commit is contained in:
HORVILLE 2022-10-06 14:58:27 +02:00
parent 9bca200351
commit 081d95d9dc
6 changed files with 120 additions and 30 deletions

View File

@ -1,15 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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;
}

View File

@ -1,6 +0,0 @@
#ifndef NEWMEM
#define NEWMEM
void* newmalloc(size_t size);
#endif

View File

@ -1,9 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "newmem.h"
int main(void) {
char* t = (char*)newmalloc(15);
printf("%d", t != NULL);
}

View File

@ -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();
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}