Skip to content

Commit

Permalink
slight refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonRadtke committed Dec 3, 2023
1 parent 63d2432 commit fcd73cc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/azure-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: deploy to https://nosrac.me

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [ "master" ]
branches: ["master"]

env:
APP_LOCATION: "www"
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ clean:
rm -rf www/assets/scripts/index.js www/assets/wasm/pkg

format:
prettier . --write
prettier --write ui
cd animation && cargo fmt
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# nosrac.me

https://nosrac.me

### Running Locally

tl;dr:

```
$ make serve
```

There are three main components:

1. `animation/` contains the rust code that compiles to web assembley and takes care of
the logic for particles and for the particle system
2. `ui/` contains the typescript code that compiles to javascript and takes care of
manipulating the DOM as well as initializing the canvas
the logic for particles and for the particle system
2. `ui/` contains the typescript code that compiles to javascript and takes care of
manipulating the DOM as well as initializing the canvas
3. `www/` is the site's root directory and all generated code is ultimately moved there
26 changes: 11 additions & 15 deletions animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ impl System {
};
}

pub fn pos(&self) -> String {
return format!("({}, {})", self.width, self.height);
pub fn add_particle(&mut self, home_x: f64, home_y: f64) {
self.particles.push(Particle {
x: self.width * rand::random::<f64>(),
y: self.height * rand::random::<f64>(),
home_x,
home_y,
});
}

pub fn tick(&mut self, mouse_x: f64, mouse_y: f64, ctx: &CanvasRenderingContext2d) {
fn update_particles(&mut self, mouse_x: f64, mouse_y: f64) {
for particle in self.particles.iter_mut() {
let Particle { x, y, .. } = particle;
{
Expand All @@ -56,21 +61,12 @@ impl System {
}
particle.tick()
}
self.render(ctx)
}

pub fn add_particle(&mut self, home_x: f64, home_y: f64) {
self.particles.push(Particle {
x: self.width * rand::random::<f64>(),
y: self.height * rand::random::<f64>(),
home_x,
home_y,
});
}

fn render(&self, ctx: &CanvasRenderingContext2d) {
pub fn tick(&mut self, mouse_x: f64, mouse_y: f64, ctx: &CanvasRenderingContext2d) {
self.draw_background(ctx);
self.draw_particles(ctx);
self.update_particles(mouse_x, mouse_y);
self.draw_particles(ctx)
}

fn draw_background(&self, ctx: &CanvasRenderingContext2d) {
Expand Down
1 change: 0 additions & 1 deletion ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function setupParticles(
) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillText("Carson Radtke", canvas.width / 2, canvas.height / 2);

const filteredData = Array.from(
ctx.getImageData(0, 0, canvas.width, canvas.height).data,
)
Expand Down
59 changes: 21 additions & 38 deletions www/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<html>
<head>
<title>Carson Radtke</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p"
crossorigin="anonymous"
/>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
crossorigin="anonymous" />
<link rel="stylesheet"
href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p"
crossorigin="anonymous" />
<link href="./assets/styles/index.css" rel="stylesheet" />
</head>

<body>
<div class="container">
<div class="row h-25"></div>
Expand All @@ -23,33 +18,26 @@
<div class="row h-50">
<canvas id="my_canvas"></canvas>
</div>

<div class="row h-50 align-content-center">
<ul class="list-group w-100 list-group-horizontal">
<li class="list-group-item border-0 flex-fill text-center">
<a
title="LinkedIn | carsonRadtke"
class="opaque_hover text-dark"
href="https://www.linkedin.com/in/carsonradtke/"
>
<a title="LinkedIn | carsonRadtke"
class="opaque_hover text-dark"
href="https://www.linkedin.com/in/carsonradtke/">
<i class="fab fa-linkedin-in fa-9x card-img-top"></i>
</a>
</li>
<li class="list-group-item border-0 flex-fill text-center">
<a
title="GitHub | carsonRadtke"
class="opaque_hover text-dark"
href="https://github.com/carsonRadtke"
>
<a title="GitHub | carsonRadtke"
class="opaque_hover text-dark"
href="https://github.com/carsonRadtke">
<i class="fab fa-github fa-9x card-img-top"></i>
</a>
</li>
<li class="list-group-item border-0 flex-fill text-center">
<a
title="Resume"
class="opaque_hover text-dark"
href="./assets/docs/cradtke_resume.pdf"
>
<a title="Resume"
class="opaque_hover text-dark"
href="./assets/docs/cradtke_resume.pdf">
<i class="far fa-file fa-9x card-img-top"></i>
</a>
</li>
Expand All @@ -65,14 +53,9 @@
</div>
</body>
</html>

<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
crossorigin="anonymous"
></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
crossorigin="anonymous"></script>
<script type="module" src="./assets/scripts/index.js"></script>

0 comments on commit fcd73cc

Please sign in to comment.