#Need helping making 2 classes into jfx

1 messages · Page 1 of 1 (latest)

night dune
#
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;

public class ApplicationWindow extends JFrame {
    public final int IMAGE_WIDTH;
    public final int IMAGE_HEIGHT;
    public BufferedImage buffer;

    public ApplicationWindow(int IMAGE_WIDTH, int IMAGE_HEIGHT) {
        super("Eulerian Fluid Simulation");
        this.IMAGE_WIDTH = IMAGE_WIDTH;
        this.IMAGE_HEIGHT = IMAGE_HEIGHT;
        setSize(IMAGE_WIDTH, IMAGE_HEIGHT + 30);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setFocusable(true);
        setVisible(true);
    }

    @Override
    public synchronized void paint(Graphics g) {
        if (buffer == null) {
            return;
        }

        g.drawImage(buffer, 0, 30, IMAGE_WIDTH, IMAGE_HEIGHT, null);
    }

    public synchronized void render(DataProvider pixelStream) {
        BufferedImage imageContainer = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_BYTE_GRAY);
        byte[] buffer = ((DataBufferByte) imageContainer.getRaster()
                .getDataBuffer()).getData();

        for (int y = 0; y < imageContainer.getHeight(); y++) {
            for (int x = 0; x < imageContainer.getWidth(); x++) {
                buffer[y * IMAGE_WIDTH + x] = pixelStream.provideData(x, y);
            }
        }

        this.buffer = imageContainer;
        repaint();
    }
}```
#

This one as well

#
import java.awt.event.MouseEvent;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

import static java.lang.Math.hypot;

public class MouseAdapter extends java.awt.event.MouseAdapter {
    private int[] previousCoords;
    private boolean mouseHeld = false;
    private List<FluidInput> sourceQueue;
    private Instant startAdd;

    public MouseAdapter() {
        sourceQueue = new ArrayList<>(); //TALK ABOUT LINKED LIST
        startAdd = Instant.now();
    }

    public void mousePressed(MouseEvent e) {
        previousCoords = new int[] { e.getX(), e.getY() };
        mouseHeld = true;
        startAdd = Instant.now();
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        mouseHeld = false;
    }

    public synchronized void mouseDragged(MouseEvent e) {
        double velocityX = 0;
        double velocityY = 0;
        double dragScalar = 5.0;

        if (previousCoords != null) {
            velocityX = dragScalar * ((double) e.getX() - previousCoords[0]);
            velocityY = dragScalar * ((double) e.getY() - previousCoords[1]);
        }

        startAdd = Instant.now();
        previousCoords = new int[] { e.getX(), e.getY() };
        sourceQueue.add(new FluidInput(previousCoords[0], previousCoords[1] - (30), velocityX, velocityY,
                6.0 * hypot(velocityX, velocityY)));
    }

    synchronized void consumeSources(Consumer<FluidInput> sourceConsumer) {
        if (mouseHeld) {
            long timeHeld = Duration.between(startAdd, Instant.now())
                    .toMillis();
            startAdd = Instant.now();
            sourceQueue.add(new FluidInput(previousCoords[0], previousCoords[1], 0, 0, timeHeld * 20.0));
        }

        for (FluidInput source : sourceQueue) {
            sourceConsumer.accept(source);
        }
        sourceQueue.clear();
    }
}```
stoic jayBOT
#

<@&987246487241105418> please have a look, thanks.

night dune
night dune
#

hey @jagged charm would it make my program lag if i try to store a cache of my previous fluid states?

#

like lets say i pause the fluid at a certain time

#

and i want to press a button to kinda like rewind it

night dune
jagged charm
#

why ?

night dune
jagged charm
#

and ?

night dune
jagged charm
night dune
jagged charm
night dune
#

it might sound stupid

night dune
jagged charm
#

you are only doing premature optimization here

#

keep it simple

night dune
#

oh ok

midnight quartz
#

for all you know, you could be worrying about something negligible