Skip to content

Commit

Permalink
v2 revamp!
Browse files Browse the repository at this point in the history
v2 revamp
  • Loading branch information
tomasmaillo authored Jan 8, 2024
2 parents 46588ac + 15f9d87 commit 6d9cdcf
Show file tree
Hide file tree
Showing 24 changed files with 2,890 additions and 376 deletions.
1,711 changes: 1,697 additions & 14 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"preview": "vite preview"
},
"dependencies": {
"@pixi/react": "^7.1.1",
"@react-hook/window-size": "^3.1.1",
"framer-motion": "^10.16.0",
"pixi.js": "^7.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1",
"react-use": "^17.4.0",
"styled-components": "^6.0.1"
},
"devDependencies": {
Expand Down
Binary file modified public/media/logos/comp-soc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/media/logos/project-share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#root {
margin: 0 auto;
padding: 1rem;
overflow-x: hidden;
}
65 changes: 26 additions & 39 deletions src/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,40 @@
import styled from 'styled-components'
import SketchLines from '../components/SketchLines'
import Logo from '../components/Logo'
import { ACCENT_COLOR } from '../constants'

const StyledFooterWrapper = styled.div`
position: relative;
border: 5px solid #fcf6fe;
background: #7816f4;
width: inherit;
margin: 3vw;
margin-bottom: 4rem;
padding: 32px;
height: 50vh;
border-radius: 25px;
display: flex;
height: 15vh;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 2rem 0;
background-color: ${ACCENT_COLOR}09;
font-size: 0.75rem;
text-align: center;
z-index: 1;
gap: 32px;
user-select: none;
@media (max-width: 768px) {
flex-direction: column;
}
`

const Footer = () => {
return (
<SketchLines top bottom margin={5000}>
<StyledFooterWrapper>
<div
style={{
display: 'flex',
flexDirection: 'row',
gap: '0.5rem',
alignItems: 'center',
}}>
<Logo size={64} />
{'❤️'}
<img
src="./media/logos/comp-soc.png"
alt="CompSoc"
width="100px"
draggable={false}
/>
</div>
<span
style={{
color: 'black',
}}>
Project Share is a{' '}
<a href="https://comp-soc.com/special-interest-groups">CompSoc SIG</a>
</span>
</StyledFooterWrapper>
</SketchLines>
<StyledFooterWrapper>
<Logo animated color="#FBF6FD" size={126} /> ❤️
<a
href="https://comp-soc.com"
target="_blank"
rel="noreferrer">
<img
src="media/logos/comp-soc.png"
alt="CompSoc Logo"
style={{ height: '126px' }}
/>
</a>
</StyledFooterWrapper>
)
}

Expand Down
209 changes: 209 additions & 0 deletions src/Header/Boids.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import React, { useState, useEffect } from 'react'
import { Container, Graphics, useApp, useTick } from '@pixi/react'
import * as PIXI from 'pixi.js'
import { ACCENT_COLOR } from '../constants'

interface Vector {
x: number
y: number
}

interface Boid {
position: Vector
velocity: Vector
}

const BOID_COUNT = 50
const VIEW_RADIUS = 50
const MAX_SPEED = 5
const SEPARATION_DISTANCE = 50
const ALIGNMENT_RADIUS = 50
const COHESION_RADIUS = 50
const BOID_SIZE = 10

const Boids: React.FC = () => {
const [boids, setBoids] = useState<Boid[]>([])

const app = useApp()

const stageMargin = 50

useEffect(() => {
const initialBoids: Boid[] = new Array(BOID_COUNT).fill(null).map(() => ({
position: {
x: Math.random() * app.screen.width,
y: Math.random() * app.screen.height,
},
velocity: {
x: Math.random() * MAX_SPEED - MAX_SPEED / 2,
y: Math.random() * MAX_SPEED - MAX_SPEED / 2,
},
}))

setBoids(initialBoids)
}, [])

const addVectors = (v1: Vector, v2: Vector): Vector => ({
x: v1.x + v2.x,
y: v1.y + v2.y,
})

const multiplyVector = (v: Vector, scalar: number): Vector => ({
x: v.x * scalar,
y: v.y * scalar,
})

const limitVector = (v: Vector, max: number): Vector => {
const magnitude = Math.sqrt(v.x * v.x + v.y * v.y)
if (magnitude > max) {
return multiplyVector(v, max / magnitude)
}
return v
}

const separation = (boid: Boid, neighbors: Boid[]): Vector => {
let steer: Vector = { x: 0, y: 0 }
let total = 0
neighbors.forEach((other) => {
const distance = Math.sqrt(
Math.pow(boid.position.x - other.position.x, 2) +
Math.pow(boid.position.y - other.position.y, 2)
)
if (distance < SEPARATION_DISTANCE && distance > 0) {
const diff: Vector = {
x: boid.position.x - other.position.x,
y: boid.position.y - other.position.y,
}
steer = addVectors(steer, diff)
total++
}
})
if (total > 0) {
steer = multiplyVector(steer, 1 / total)
}
return steer
}

const alignment = (boid: Boid, neighbors: Boid[]): Vector => {
let averageVel: Vector = { x: 0, y: 0 }
neighbors.forEach((other) => {
averageVel = addVectors(averageVel, other.velocity)
})
if (neighbors.length > 0) {
averageVel = multiplyVector(averageVel, 1 / neighbors.length)
return limitVector(averageVel, MAX_SPEED)
}
return boid.velocity
}

const cohesion = (boid: Boid, neighbors: Boid[]): Vector => {
let centerOfMass: Vector = { x: 0, y: 0 }
neighbors.forEach((other) => {
centerOfMass = addVectors(centerOfMass, other.position)
})
if (neighbors.length > 0) {
centerOfMass = multiplyVector(centerOfMass, 1 / neighbors.length)
return {
x: centerOfMass.x - boid.position.x,
y: centerOfMass.y - boid.position.y,
}
}
return { x: 0, y: 0 }
}

const getNeighbors = (boid: Boid, radius: number): Boid[] => {
return boids.filter((other) => {
const distance = Math.sqrt(
Math.pow(boid.position.x - other.position.x, 2) +
Math.pow(boid.position.y - other.position.y, 2)
)
return distance < radius && distance > 0
})
}

useTick((delta) => {
const newBoids = boids.map((boid) => {
const neighbors = getNeighbors(boid, VIEW_RADIUS)

Check failure on line 126 in src/Header/Boids.tsx

View workflow job for this annotation

GitHub Actions / deploy

'neighbors' is declared but its value is never read.

// Apply behaviors
const sep = separation(boid, getNeighbors(boid, SEPARATION_DISTANCE))
const ali = alignment(boid, getNeighbors(boid, ALIGNMENT_RADIUS))
const coh = cohesion(boid, getNeighbors(boid, COHESION_RADIUS))

// Adjust velocity
boid.velocity = addVectors(boid.velocity, sep)
boid.velocity = addVectors(boid.velocity, ali)
boid.velocity = addVectors(boid.velocity, coh)
boid.velocity = limitVector(boid.velocity, MAX_SPEED)

// Update position and apply wrap-around
const newPosition = {
x: boid.position.x + boid.velocity.x * delta,
y: boid.position.y + boid.velocity.y * delta,
}

// Wrap-around logic for x-coordinate
if (newPosition.x < -stageMargin) {
newPosition.x = app.screen.width + stageMargin
} else if (newPosition.x > app.screen.width + stageMargin) {
newPosition.x = -stageMargin
}

// Wrap-around logic for y-coordinate
if (newPosition.y < -stageMargin) {
newPosition.y = app.screen.height + stageMargin
} else if (newPosition.y > app.screen.height + stageMargin) {
newPosition.y = -stageMargin
}

return {
...boid,
position: newPosition,
}
})

setBoids(newBoids)
})

const drawTriangle = (
g: PIXI.Graphics,
x: number,
y: number,
size: number,
rotation: number
) => {
g.drawPolygon([
x - size,
y + size, // Left corner
x + size,
y + size, // Right corner
x,
y - size, // Top corner
])
g.rotation = rotation
}

const color = new PIXI.Color(ACCENT_COLOR)

return (
<Container>
{boids.map((boid, index) => (
<Graphics
key={index}
draw={(g) => {
g.clear()
g.beginFill(color) // Purple color
const rotation =
Math.atan2(boid.velocity.y, boid.velocity.x) + Math.PI / 2
drawTriangle(g, 0, 0, BOID_SIZE, rotation) // Draw each boid as a triangle
g.endFill()
}}
x={boid.position.x}
y={boid.position.y}
/>
))}
</Container>
)
}

export default Boids
Loading

0 comments on commit 6d9cdcf

Please sign in to comment.