Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Emroni committed Aug 2, 2024
2 parents 613e5e3 + ae03132 commit b47715d
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 159 deletions.
65 changes: 0 additions & 65 deletions old/src/experiments/sphere/1.ts

This file was deleted.

69 changes: 0 additions & 69 deletions old/src/experiments/sphere/2.ts

This file was deleted.

Binary file added public/assets/images/sphere-1.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 added public/assets/images/sphere-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app/cubic/1/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class Cubic1 extends React.Component<any, ExperimentControlItems>
shapes: Shape[] = [];

state = {
// TODO: Add layers
delay: { min: 0, max: 2, value: 1 },
speed: { min: 1, max: 10, step: 1, value: 1 },
};
Expand Down
1 change: 1 addition & 0 deletions src/app/cubic/2/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class Cubic2 extends React.Component<any, ExperimentControlItems>
shapes: Shape[] = [];

state = {
// TODO: Add layers
delay: { min: 0, max: 2, value: 1 },
speed: { min: 1, max: 10, step: 1, value: 1 },
};
Expand Down
1 change: 1 addition & 0 deletions src/app/cubic/3/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class Cubic3 extends React.Component<any, ExperimentControlItems>
particles: Particle[] = [];

state = {
// TODO: Add layers
delay: { min: 0, max: 2, value: 1 },
speed: { min: 1, max: 10, step: 1, value: 1 },
};
Expand Down
36 changes: 23 additions & 13 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
'use client';
import { experiments } from '@/setup';
import { Card, CardActionArea, CardHeader, CardMedia, Grid } from '@mui/material';
import { Box, Card, CardActionArea, CardContent, CardHeader, CardMedia, Grid, Typography } from '@mui/material';

export default function Home() {

return <Grid container overflow="auto" padding={3} spacing={3}>
{experiments.map((experiment, index) => !experiment.disabled && (
<Grid item key={index} xs={12} md={6} lg={4} xl={3}>
<CardActionArea href={experiment.path}>
<Card>
<CardMedia image={experiment.image} sx={{ paddingTop: '100%' }} />
<CardHeader subheader={experiment.index} title={experiment.title} />
</Card>
</CardActionArea>
</Grid>
))}
</Grid>;
return <Box overflow="auto" padding={3}>
<Card>
<CardHeader title="Experimental" />
<CardContent>
<Typography>
Just some experimental digital artwork
</Typography>
</CardContent>
</Card>
<Grid container marginTop={0} overflow="auto" spacing={3}>
{experiments.map((experiment, index) => !experiment.disabled && (
<Grid item key={index} xs={12} md={6} lg={4} xl={3}>
<CardActionArea href={experiment.path}>
<Card>
<CardMedia image={experiment.image} sx={{ paddingTop: '100%' }} />
<CardHeader subheader={experiment.index} title={experiment.title} />
</Card>
</CardActionArea>
</Grid>
))}
</Grid>
</Box>;

}
105 changes: 105 additions & 0 deletions src/app/sphere/1/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'use client';
import { ExperimentControls, ThreePlayer } from '@/components';
import { PI, PI_D2, PI_M2 } from '@/setup';
import React from 'react';
import * as THREE from 'three';

export default class Sphere1 extends React.Component<any, ExperimentControlItems> {

color = 0xFFFFFF;
container = new THREE.Group();
depth = 400;
particles: THREE.Object3D[] = [];
particleSize = 100;

mesh: THREE.Mesh;

state = {
particles: { min: 10, max: 1000, step: 1, value: 200 },
radius: { min: 10, max: 1000, step: 1, value: 200 },
size: { min: 1, max: 100, step: 1, value: 20 },
speed: { min: 1, max: 10, step: 1, value: 1 },
};

handleInit = (scene: THREE.Scene, camera: THREE.PerspectiveCamera) => {
camera.far = 10000;
camera.position.z = this.depth;
scene.add(this.container);

// Add lights
const ambient = new THREE.AmbientLight(this.color, 0.1);
scene.add(ambient);

const light = new THREE.PointLight(this.color, this.depth ** 2);
scene.add(light);

// Get particle mesh
const geometry = new THREE.BoxGeometry(this.particleSize, this.particleSize, Math.ceil(this.particleSize / 10));
const material = new THREE.MeshPhongMaterial({
side: THREE.DoubleSide,
});
this.mesh = new THREE.Mesh(geometry, material);

// Trigger state change
this.setState({});
}

componentDidUpdate() {
const { particles, radius, size } = this.state;

// Add missing particles
for (let i = this.particles.length; i < particles.value; i++) {
const particle = new THREE.Object3D();
this.particles.push(particle);

particle.userData.plane = this.mesh.clone();
particle.add(particle.userData.plane);
}

// Remove particles from container
this.container.children.forEach(particle => particle.removeFromParent());

// Add particles
const f = 2 / particles.value;
for (let i = 0; i < particles.value; i++) {
const particle = this.particles[i];
this.container.add(particle);

const n = (i * f) - 1 + (f / 2);
const r = Math.sqrt(1 - (n * n)) * radius.value;
const alpha = (i % particles.value) * PI * (3 - Math.sqrt(5));

particle.position.x = Math.cos(alpha) * r;
particle.position.y = -n * radius.value;
particle.position.z = Math.sin(alpha) * r;
particle.scale.setScalar(size.value / this.particleSize);
particle.lookAt(0, 0, 0);
}
}

handleTick = (progress: number) => {
const { speed } = this.state;
const tick = (progress * speed.value) % 1;

this.container.rotation.y = PI_M2 * tick;

for (const face of this.container.children) {
face.userData.plane.rotation.x = PI_D2 * (Math.sin(PI_M2 * tick * 2) + 1);
face.userData.plane.rotation.z = PI * tick;
}
}

render() {
return <>
<ExperimentControls
items={this.state}
onChange={items => this.setState(items)}
/>
<ThreePlayer
onInit={this.handleInit}
onTick={this.handleTick}
/>
</>;
}

}
Loading

0 comments on commit b47715d

Please sign in to comment.