Jump to content

Floatplane's login screen background in Rust

Cebolonha

I'm learning Rust, and I was trying to find something fun to code. 

The last WAN show featured Floatplane's login screen (https://www.floatplane.com/login), which is cool.

So I made this: https://github.com/ricardopieper/rust-particles

There's probably a lot to refactor, for instance, there are many methods expecting the same arguments on the Renderer impl. But I only have so much time.
I made it using Piston.

Currently featuring:

 - Connection strength: The longer 2 particles are near each other, the stronger the connection
 - Show only the connections near to the mouse position
 - A little bit of brightness around a particle that depends on the connection strength
 - The connected line opacity also depends on the connection strength.
 - Strength gradually increases/decreases depending on the distance. This means the connection lines have a fade-in/fade-out effect.
 - Particle speed depends on its size (the bigger, the faster)
 - Particles bounce off of walls


The effect is not identical to floatplane's but it's kinda similar.

 

image.thumb.png.74b60d0e5bbd4a6e21a0cbacec12f56f.png

Edited by Cebolonha
Added https://www.floatplane.com/login
Link to comment
Share on other sites

Link to post
Share on other sites

This is pretty cool! Nice work!

MochPot: AMD Ryzen 5 2600, 16GB 3200MHz DDR4, ASRock X370 Fatality K7, 8GB Nvidia GeForce GTX 1070, 256gb Salvaged Intel Rando NVME SSD, Corsair RM750x, Corsair Carbide 275R, Windows 10 Pro

 

ZenServerRequiem: AMD Ryzen 3 2200g, 32GB 3200MHz DDR4, MSI B450 Gaming Plus, 4GB Nvidia GeForce GTX 960, 2GB Nvidia Quadro P400, 500gb Salvaged Intel Rando NVME SSD (Cache Drive only), 3 x Seagate Baracuda 2TB, Corsair CX500, Corsair Carbine 750T, Limetech Unraid (Running Plex, Jackett, Sonarr, WireShark, Duck DNS, Ubuntu Server VM for MC server)

Link to comment
Share on other sites

Link to post
Share on other sites

pretty sure this is the code of the original

Spoiler

var canvas = document.getElementById("canvas"),
    ctx = canvas.getContext('2d');

canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

var stars = [], // Array that contains the stars
    FPS = 60, // Frames per second
    x = 100, // Number of stars
    mouse = {
      x: 0,
      y: 0
    };  // mouse location

// Push stars to array

for (var i = 0; i < x; i++) {
  stars.push({
    x: Math.random() * canvas.width,
    y: Math.random() * canvas.height,
    radius: Math.random() * 1 + 1,
    vx: Math.floor(Math.random() * 50) - 25,
    vy: Math.floor(Math.random() * 50) - 25
  });
}

// Draw the scene

function draw() {
  ctx.clearRect(0,0,canvas.width,canvas.height);
  
  ctx.globalCompositeOperation = "lighter";
  
  for (var i = 0, x = stars.length; i < x; i++) {
    var s = stars;
  
    ctx.fillStyle = "#fff";
    ctx.beginPath();
    ctx.arc(s.x, s.y, s.radius, 0, 2 * Math.PI);
    ctx.fill();
    ctx.fillStyle = 'black';
    ctx.stroke();
  }
  
  ctx.beginPath();
  for (var i = 0, x = stars.length; i < x; i++) {
    var starI = stars;
    ctx.moveTo(starI.x,starI.y); 
    if(distance(mouse, starI) < 150) ctx.lineTo(mouse.x, mouse.y);
    for (var j = 0, x = stars.length; j < x; j++) {
      var starII = stars[j];
      if(distance(starI, starII) < 150) {
        //ctx.globalAlpha = (1 / 150 * distance(starI, starII).toFixed(1));
        ctx.lineTo(starII.x,starII.y); 
      }
    }
  }
  ctx.lineWidth = 0.05;
  ctx.strokeStyle = 'white';
  ctx.stroke();
}

function distance( point1, point2 ){
  var xs = 0;
  var ys = 0;
 
  xs = point2.x - point1.x;
  xs = xs * xs;
 
  ys = point2.y - point1.y;
  ys = ys * ys;
 
  return Math.sqrt( xs + ys );
}

// Update star locations

function update() {
  for (var i = 0, x = stars.length; i < x; i++) {
    var s = stars;
  
    s.x += s.vx / FPS;
    s.y += s.vy / FPS;
    
    if (s.x < 0 || s.x > canvas.width) s.vx = -s.vx;
    if (s.y < 0 || s.y > canvas.height) s.vy = -s.vy;
  }
}

canvas.addEventListener('mousemove', function(e){
  mouse.x = e.clientX;
  mouse.y = e.clientY;
});

// Update and draw

function tick() {
  draw();
  update();
  requestAnimationFrame(tick);
}

tick();

from here: https://codepen.io/LeonGr/pen/yginI

with some adjustments

CPU: Ryzen 1700@3.9ghz; GPU: EVGA 560 Ti 1gb; RAM: 16gb 2x8 Corsair Vengeance LPX DDR4-3000; PCPP: https://pcpartpicker.com/list/b3xzzM

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×