add weather gen basics
This commit is contained in:
14
src/ambient.d.ts
vendored
Normal file
14
src/ambient.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
type WeatherDataCurrent = {
|
||||||
|
time: Date;
|
||||||
|
temperature2m: number;
|
||||||
|
relativeHumidity2m: number;
|
||||||
|
isDay: number;
|
||||||
|
precipitation: number;
|
||||||
|
cloudCover: number;
|
||||||
|
pressureMsl: number;
|
||||||
|
windSpeed10m: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
type WeatherData = {
|
||||||
|
current: WeatherDataCurrent
|
||||||
|
}
|
||||||
2
src/app.d.ts
vendored
2
src/app.d.ts
vendored
@@ -10,4 +10,4 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export { };
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<!-- TODO: ADD TONEJS GENERATOR -->
|
|
||||||
<!-- https://www.npmjs.com/package/tonal -->
|
|
||||||
<!-- https://www.npmjs.com/package/tone -->
|
|
||||||
37
src/lib/generators/weather/WeatherGen.svelte
Normal file
37
src/lib/generators/weather/WeatherGen.svelte
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Synth, Loop, type SynthOptions, getTransport } from 'tone';
|
||||||
|
|
||||||
|
let { currentWeather } = $props();
|
||||||
|
|
||||||
|
const synthOptions = {
|
||||||
|
oscillator: {
|
||||||
|
type: 'triangle'
|
||||||
|
},
|
||||||
|
envelope: {
|
||||||
|
attack: 0.005,
|
||||||
|
decay: 0.3,
|
||||||
|
sustain: 0.1,
|
||||||
|
release: 0.1
|
||||||
|
}
|
||||||
|
} as SynthOptions;
|
||||||
|
|
||||||
|
// getTransport().scheduleRepeat((time) => {
|
||||||
|
// // use the callback time to schedule events
|
||||||
|
// osc.start(time).stop(time + 0.1);
|
||||||
|
// }, '8n');
|
||||||
|
// // transport must be started before it starts invoking events
|
||||||
|
// Tone.Transport.start();
|
||||||
|
|
||||||
|
function setupAndPlay() {
|
||||||
|
getTransport().bpm.value = 60;
|
||||||
|
const synth = new Synth(synthOptions).toDestination();
|
||||||
|
const loop = new Loop((time) => {
|
||||||
|
synth.triggerAttackRelease('C2', '8n');
|
||||||
|
}, '8n').start(0);
|
||||||
|
getTransport().stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
setupAndPlay();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex min-h-screen flex-col items-center justify-center">WEATHERGEN</div>
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<!-- TODO: ADD TONEJS GENERATOR -->
|
|
||||||
<!-- https://www.npmjs.com/package/tonal -->
|
|
||||||
<!-- https://www.npmjs.com/package/tone -->
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state';
|
import WeatherGen from '$lib/generators/weather/WeatherGen.svelte';
|
||||||
|
|
||||||
const lat = $derived(page.url.searchParams.get('lat'));
|
import type { PageProps } from './$types';
|
||||||
const long = $derived(page.url.searchParams.get('long'));
|
|
||||||
|
|
||||||
$inspect(lat);
|
const { data }: PageProps = $props();
|
||||||
$inspect(long);
|
const currentWeather = data.current;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<WeatherGen {currentWeather}></WeatherGen>
|
||||||
|
|||||||
@@ -1,32 +1,38 @@
|
|||||||
//TODO: LOAD ALL API DATA FOR WEATHER, AIR QUALITY, ETC
|
|
||||||
import { fetchWeatherApi } from 'openmeteo';
|
import { fetchWeatherApi } from 'openmeteo';
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
const params = {
|
export const load: PageLoad = async ({ url }) => {
|
||||||
"latitude": 52.52,
|
|
||||||
"longitude": 13.41,
|
const lat = url.searchParams.get('lat');
|
||||||
"current": ["temperature_2m", "relative_humidity_2m", "is_day", "precipitation", "cloud_cover", "pressure_msl", "wind_speed_10m"]
|
const long = url.searchParams.get('long');
|
||||||
};
|
|
||||||
const url = "https://api.open-meteo.com/v1/forecast";
|
const apiParams = {
|
||||||
const responses = await fetchWeatherApi(url, params);
|
"latitude": lat,
|
||||||
|
"longitude": long,
|
||||||
// Process first location. Add a for-loop for multiple locations or weather models
|
"current": ["temperature_2m", "relative_humidity_2m", "is_day", "precipitation", "cloud_cover", "pressure_msl", "wind_speed_10m"]
|
||||||
const response = responses[0];
|
};
|
||||||
|
|
||||||
// Attributes for timezone and location
|
const apiUrl = "https://api.open-meteo.com/v1/forecast";
|
||||||
const utcOffsetSeconds = response.utcOffsetSeconds();
|
const responses = await fetchWeatherApi(apiUrl, apiParams);
|
||||||
|
|
||||||
const current = response.current()!;
|
const response = responses[0];
|
||||||
|
const utcOffsetSeconds = response.utcOffsetSeconds();
|
||||||
// Note: The order of weather variables in the URL query and the indices below need to match!
|
|
||||||
const weatherData = {
|
const current = response.current()!;
|
||||||
current: {
|
|
||||||
time: new Date((Number(current.time()) + utcOffsetSeconds) * 1000),
|
// Note: The order of weather variables in the URL query and the indices below need to match!
|
||||||
temperature2m: current.variables(0)!.value(),
|
const weatherData: WeatherData = {
|
||||||
relativeHumidity2m: current.variables(1)!.value(),
|
current: {
|
||||||
isDay: current.variables(2)!.value(),
|
time: new Date((Number(current.time()) + utcOffsetSeconds) * 1000),
|
||||||
precipitation: current.variables(3)!.value(),
|
temperature2m: current.variables(0)!.value(),
|
||||||
cloudCover: current.variables(4)!.value(),
|
relativeHumidity2m: current.variables(1)!.value(),
|
||||||
pressureMsl: current.variables(5)!.value(),
|
isDay: current.variables(2)!.value(),
|
||||||
windSpeed10m: current.variables(6)!.value(),
|
precipitation: current.variables(3)!.value(),
|
||||||
},
|
cloudCover: current.variables(4)!.value(),
|
||||||
|
pressureMsl: current.variables(5)!.value(),
|
||||||
|
windSpeed10m: current.variables(6)!.value(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return weatherData
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user