-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
6,194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/Muun/ | ||
/Pot/ | ||
/Std/ | ||
main.js | ||
/checker.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
The code of several works on [oimo.io/works](https://oimo.io/works) | ||
--- | ||
|
||
## When you try to compile | ||
- Use the latest [Haxe](https://haxe.org/) | ||
- Copy personal libs from [here](https://github.com/saharan/haxelibs/) | ||
- **I often add breaking changes to the personal libs and projects, do not always expect successful compilations!** | ||
|
||
## Bubbles | ||
[![](imgs/bubbles.png)](https://oimo.io/works/bubbles) | ||
Code: [`/bubbles`](bubbles) | ||
|
||
## Jelly | ||
[![](imgs/jelly.png)](https://oimo.io/works/jelly) | ||
Code: [`/jelly`](jelly) | ||
|
||
## Clock | ||
[![](imgs/clock.png)](https://oimo.io/works/clock) | ||
Code: [`/clock`](clock) | ||
|
||
## Water | ||
[![](imgs/water.png)](https://oimo.io/works/water) | ||
Code: [`/water`](water) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Haxe Interpreter", | ||
"type": "haxe-eval", | ||
"request": "launch" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "haxe", | ||
"args": "active configuration", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0"> | ||
<meta name="twitter:card" content="summary_large_image"> | ||
<meta name="twitter:site" content="@shr_id"> | ||
<meta name="twitter:creator" content="@shr_id"> | ||
<meta name="og:title" content="Bubbles"> | ||
<meta name="og:image" content="https://oimo.io/thumbs/bubbles.png"> | ||
<title>Bubbles</title> | ||
<style> | ||
html { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
body { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
overflow: hidden; | ||
} | ||
|
||
#wrapper { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
#canvas { | ||
width: 100%; | ||
height: 100%; | ||
display: block; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<a href="https://oimo.io/" style="display:block;position:fixed;top:8px;right:8px;width:24px;height:24px;mix-blend-mode:exclusion;z-index:256;"> | ||
<svg class="logo" viewBox="0 0 48 48"> | ||
<path stroke-width="4" stroke="#fff" fill="#fff" d="M 44 4 c 0 10 0 14 -2 20 s -7 9 -10 10 c -12 4 -22 -6 -18 -18 c 1 -3 4 -8 10 -10 s 10 -2 20 -2 Z M 22 6 C 14 8 8 14 6 22 S 4 35 4 44 c 10 0 15 0 22 -2 s 14 -9 16 -16 s 2 -13 2 -22 C 34 4 30 4 22 6 Z"></path> | ||
<path fill="#fff" d="M 20 23 A 8 8 0 1 0 36 23 A 8 8 0 1 0 20 23 Z M 32 11 A 3 3 0 1 0 38 11 A 3 3 0 1 0 32 11 Z"></path> | ||
</svg> | ||
</a> | ||
<div id="wrapper"><canvas id="canvas"></canvas></div> | ||
<script src="main.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-cp src | ||
-cp ../Pot/src | ||
-cp ../Muun/src | ||
-L hgsl | ||
-D analyzer-optimize | ||
-D js-es=6 | ||
-main Main | ||
--js bin/main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import muun.la.Vec2; | ||
|
||
class Bubble { | ||
public var area:Float; | ||
public var anchor:HalfEdge; | ||
public var dead:Bool = false; | ||
|
||
public function new(area:Float, anchor:HalfEdge) { | ||
this.area = area; | ||
this.anchor = anchor; | ||
forEachEdge(e -> e.bubble = this); | ||
} | ||
|
||
public function updateEdges():Void { | ||
forEachEdge(e -> e.bubble = this); | ||
} | ||
|
||
public function preSolve():Void { | ||
updateEdges(); | ||
} | ||
|
||
public function solve():Void { | ||
var currentArea = 0.0; | ||
var length = 0.0; | ||
final nsum = Vec2.zero; | ||
var numVs = 0; | ||
|
||
forEachEdge(e -> { | ||
final v1 = e.v; | ||
final v2 = e.next.v; | ||
final p1 = v1.pos + v1.vel; | ||
final p2 = v2.pos + v2.vel; | ||
v1.updateNormal(e); | ||
nsum << nsum + v1.n; | ||
currentArea += 0.5 * p1.cross(p2); | ||
if (e.twin.bubble != this) { | ||
length += (p2 - p1).length; | ||
numVs++; | ||
} | ||
}); | ||
final pCoeff = 0.2; | ||
final pressure = (area - currentArea) / length * pCoeff; | ||
final shift = -nsum * (pressure / numVs); | ||
forEachEdge(e -> { | ||
if (e.twin.bubble != this) { | ||
final v = e.v; | ||
v.vel << v.vel + v.n * pressure + shift; | ||
} | ||
}); | ||
} | ||
|
||
public function size():Int { | ||
var res = 0; | ||
forEachEdge(e -> res++); | ||
return res; | ||
} | ||
|
||
public function isSmall():Bool { | ||
var e = anchor; | ||
var count = 0; | ||
do { | ||
if (++count > 8) | ||
return false; | ||
e = e.next; | ||
} while (e != anchor); | ||
return true; | ||
} | ||
|
||
public function destroy():Void { | ||
forEachEdge(e -> e.bubble = null); | ||
dead = true; | ||
} | ||
|
||
extern public inline function forEachEdge(f:(e:HalfEdge) -> Void):Void { | ||
var e = anchor; | ||
var count = 0; | ||
do { | ||
if (++count > 10000) { | ||
var e = anchor; | ||
final a = []; | ||
for (_ in 0...100) { | ||
final end = a.contains(e.id); | ||
a.push(e.id); | ||
if (end) | ||
break; | ||
e = e.next; | ||
} | ||
throw "wrong topology: " + a; | ||
} | ||
f(e); | ||
e = e.next; | ||
} while (e != anchor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum abstract ItemKind(Int) { | ||
var Wand; | ||
var Fan; | ||
var Needle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import muun.la.Vec2; | ||
|
||
class Edge { | ||
public var v1(get, never):Vertex; | ||
public var v2(get, never):Vertex; | ||
public final e:HalfEdge; | ||
|
||
public var doNotSwapCount:Int = 0; | ||
public var dyingCount:Int = 0; | ||
public var dead:Bool = false; | ||
|
||
final imp:Vec2 = Vec2.zero; | ||
|
||
public function new(e:HalfEdge) { | ||
this.e = e; | ||
e.e = this; | ||
e.twin.e = this; | ||
} | ||
|
||
extern inline function get_v1():Vertex { | ||
return e.v; | ||
} | ||
|
||
extern inline function get_v2():Vertex { | ||
return e.twin.v; | ||
} | ||
|
||
public function preSolve():Void { | ||
imp << Vec2.zero; | ||
} | ||
|
||
public function solve():Void { | ||
if (v1.invMass == 0 && v2.invMass == 0) | ||
return; | ||
final p1 = v1.pos + v1.vel; | ||
final p2 = v2.pos + v2.vel; | ||
final d = p1 - p2; | ||
final m = 1 / (v1.invMass + v2.invMass); | ||
final cfm = 4; | ||
final dimp = (-d * m - cfm * imp) / (1 + cfm); | ||
final pimp = imp.copy(); | ||
imp += dimp; | ||
final maxImp = 2; | ||
if (imp.lengthSq > maxImp * maxImp) { | ||
imp *= maxImp / imp.length; | ||
} | ||
dimp << imp - pimp; | ||
v1.vel += v1.invMass * dimp; | ||
v2.vel -= v2.invMass * dimp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import haxe.ds.Vector; | ||
|
||
class Grid<V> { | ||
public static inline final HASH_SHIFT:Int = 20; | ||
public static inline final HASH_SIZE:Int = 1 << HASH_SHIFT; | ||
public static inline final HASH_MASK:Int = HASH_SIZE - 1; | ||
|
||
final times:Vector<Int> = new Vector<Int>(HASH_SIZE); | ||
final firsts:Vector<VertexIndex> = new Vector<VertexIndex>(HASH_SIZE); | ||
final nexts:Array<VertexIndex> = []; | ||
final vertices:Array<V> = []; | ||
final pool:Array<VertexIndex> = []; | ||
|
||
var time:Int = 0; | ||
|
||
public function new() { | ||
for (i in 0...HASH_SIZE) { | ||
times[i] = 0; | ||
firsts[i] = VertexIndex.NULL; | ||
} | ||
} | ||
|
||
public function createVertex(v:V = null):VertexIndex { | ||
if (pool.length > 0) { | ||
final vi = pool.pop(); | ||
vertices[vi] = v; | ||
return vi; | ||
} | ||
var i = nexts.length; | ||
nexts.push(VertexIndex.NULL); | ||
vertices.push(v); | ||
return new VertexIndex(i); | ||
} | ||
|
||
public function setVertex(vi:VertexIndex, v:V):Void { | ||
vertices[vi] = v; | ||
} | ||
|
||
public function destroyVertex(vi:VertexIndex):Void { | ||
nexts[vi] = VertexIndex.NULL; | ||
vertices[vi] = null; | ||
pool.push(vi); | ||
} | ||
|
||
public function destroyVertices():Void { | ||
nexts.resize(0); | ||
vertices.resize(0); | ||
time++; | ||
} | ||
|
||
public function clear():Void { | ||
time++; | ||
} | ||
|
||
extern public inline function getIndex(gx:Int, gy:Int):GridIndex { | ||
var hash = 17; | ||
hash = (hash << 5) - hash + gx; | ||
hash = (hash << 5) - hash + gy; | ||
return new GridIndex(hash & HASH_MASK); | ||
} | ||
|
||
extern public inline function register(vi:VertexIndex, gi:GridIndex):Void { | ||
if (times[gi] != time) { | ||
times[gi] = time; | ||
firsts[gi] = VertexIndex.NULL; | ||
} | ||
nexts[vi] = firsts[gi]; | ||
firsts[gi] = vi; | ||
} | ||
|
||
extern public inline function forEach(gi:GridIndex, f:(vi:VertexIndex, v:V) -> Void):Void { | ||
if (times[gi] != time) | ||
return; | ||
var vi = firsts[gi]; | ||
while (vi != VertexIndex.NULL) { | ||
f(vi, vertices[vi]); | ||
vi = nexts[vi]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
abstract GridIndex(Int) to Int { | ||
public static final NULL:GridIndex = new GridIndex(-1); | ||
|
||
@:allow(Grid) | ||
inline function new(index:Int) { | ||
this = index; | ||
} | ||
} |
Oops, something went wrong.