Skip to content

Commit

Permalink
Bil
Browse files Browse the repository at this point in the history
  • Loading branch information
alexristinmaa committed Apr 19, 2024
1 parent d0f4ced commit 056df06
Show file tree
Hide file tree
Showing 10 changed files with 681 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import * as fs from 'fs';
import {marked} from 'marked';
import parseMD from 'parse-md';

marked.use({
gfm: true
})

export function generateStaticParams() {
const experiments =
fs.readdirSync('./app/(experiments)', {withFileTypes: true})
Expand Down
18 changes: 18 additions & 0 deletions alexanderristinmaa/app/(experiments)/mandelbrot/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// nextjs
import Script from 'next/script';

export default function Home() {
return (
<div>
<Script src='/mandelbrot/wasm_exec.js' strategy='beforeInteractive'></Script>
<Script strategy='beforeInteractive'>
{`
const go = new Go();
WebAssembly.instantiateStreaming(fetch("/mandelbrot/wasm.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
`}
</Script>
</div>
)
}
2 changes: 1 addition & 1 deletion alexanderristinmaa/app/(homepage)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function Home() {
</div>
<div id={styles.imgDiv}>
<img id ={styles.img} src="/Alexander Ristinmaa.JPG" alt="Cool img" />
<p><i>Kebnekaise toppstuga och en räddningshelikopter</i></p>
<p><i>Kebnekaise toppstuga och <Link href="/loveochotto">en</Link> räddningshelikopter</i></p>
</div>

</div>
Expand Down
16 changes: 16 additions & 0 deletions alexanderristinmaa/app/loveochotto/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
6 changes: 6 additions & 0 deletions alexanderristinmaa/app/loveochotto/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#bil {
position: fixed;
left: 0;
top: 0;
z-index: -1;
}
26 changes: 26 additions & 0 deletions alexanderristinmaa/app/loveochotto/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import styles from './page.module.css';

export default function Home() {
let korBil = () => {
let bil = document.getElementById(styles.bil);

let count = 0;

let animate = () => {
bil!.style.left = count + "px";
count++;
requestAnimationFrame(animate);
}

animate();
}
return (
<div>
<p>Love bil</p>
<button onClick={korBil}>KÖR BARA KÖR</button>
<img id={styles.bil} src="/bil.png" alt="bil" />
</div>
);
}
Binary file added alexanderristinmaa/public/bil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions alexanderristinmaa/public/mandelbrot/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//go:build js && wasm

package main

import (
"math/cmplx"
"syscall/js"
)

func main() {
js.Global().Set("greet", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
if len(args) == 0 {
return "Hello, World!"
}

return []interface{}{1, 2}
}))

select {}
}

//export mandelbrot
func mandelbrot(pixels [][]*int, xStart, xEnd, yStart, yEnd float64, resX, resY, iterations int) {
deltaX := complex((xEnd-xStart)/float64(resX), 0)
deltaY := complex(0, (yEnd-yStart)/float64(resY))

coord := complex(xStart, yStart)

for x := 0; x < resX; x++ {
coord = complex(0, imag(coord))
for y := 0; y < resY; y++ {
*pixels[x][y] = testPoint(coord, iterations)
coord += deltaY
}

coord += deltaX
}
}

func testPoint(c complex128, iterations int) int {
z := complex(0, 0)
i := 0

for ; i < iterations; i++ {
z = z*z + c

if cmplx.Abs(z) > 2 {
break
}
}

return i
}
Binary file added alexanderristinmaa/public/mandelbrot/wasm.wasm
Binary file not shown.
Loading

0 comments on commit 056df06

Please sign in to comment.