Skip to content

Commit

Permalink
add info
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Nov 3, 2024
1 parent 599d673 commit 1105882
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
15 changes: 8 additions & 7 deletions js/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sqrt = Math.sqrt

export class Pringle extends Surf {
constructor(h:number=0.5,n:number=2) {
super()
super(`pringle h:${h} n:${n}`)

this.addBorder(t =>
[ cos(t),
Expand All @@ -32,7 +32,7 @@ export class Pringle extends Surf {

export class Catenoid extends Surf {
constructor(R:number=1, h:number=1) {
super()
super(`catenoid R:${R} h:${h}`)

this.addBorder(t => [R*cos(t), R*sin(t),0], 2*PI)
this.addBorder(t => [R*cos(t), R*sin(t),h], 2*PI)
Expand All @@ -52,7 +52,7 @@ export class Catenoid extends Surf {

export class Cube extends Surf {
constructor(simply_connected: boolean = true,sx: number = 1.0,sy: number = 1.0,sz: number = 1.0) {
super()
super(`cube sx:${sx} sy:${sy} sz:${sz} simply_connected:${simply_connected}`)

// 8 vertices cube
const v000 = this.addVertex(0,0,0)
Expand Down Expand Up @@ -130,7 +130,7 @@ export class Cube extends Surf {

export class Helicoid extends Surf {
constructor(R:number=1.0,r:number=0, h:number=1.0, N:number=2) {
super()
super(`helicoid R:${R} r:${r} h:${h} N:${N}`)

const PERIOD = 4.0
this.addBorder(t => {
Expand Down Expand Up @@ -169,7 +169,7 @@ export class Helicoid extends Surf {

export class Manu extends Surf {
constructor(depth:number=0.5, R:number=1.0, r:number=0.4, h:number=0.1, radius:number=0.7) {
super()
super(`manu depth:${depth} R:${R} r:${r} h:${h} radius:${radius}`)
let p:[number,number][] = []
const self = this

Expand Down Expand Up @@ -363,7 +363,7 @@ export class Manu extends Surf {

export class Marco extends Surf {
constructor(r:number=1.0, R:number=1.5, h:number=0.7, osc:number=0.1) {
super()
super(`marco r:${r} R:${R} h:${h} osc:${osc}`)

this.addBorder(t=>[r*cos(t),r*sin(t),h-osc*cos(2.0*t)], 2*PI)
this.addBorder(t=>[R*cos(t),R*sin(t),osc*cos(2.0*t)], 2*PI)
Expand Down Expand Up @@ -406,7 +406,7 @@ export class Marco extends Surf {

class MoebiusBase extends Surf {
constructor(R:number=1.0, r:number=0.4) {
super()
super(`moebius R:${R} r:${r}`)
/* t va da 0 a 4\pi */
this.addBorder(
t => [(R-r*cos(t/2.0))*cos(t),(R-r*cos(t/2.0))*sin(t),r*(sin(t/2.0))],
Expand Down Expand Up @@ -437,6 +437,7 @@ export class Moebius extends MoebiusBase {
export class MoebiusOriented extends MoebiusBase {
constructor(R:number=1.0, r:number=0.4) {
super(R,r)
this.name += " oriented"
const p = this.computeP()
this.addTriangle(p[4],p[3],p[5])
this.addQuad(p[0],p[2],p[3],p[5])
Expand Down
4 changes: 1 addition & 3 deletions js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
<body>
<h1>Surf</h1>
<canvas id="my-canvas" width="640" height="480"></canvas>
<div>
info
bla
<div id="my-info">
</div>
<script type="module" src="/main.ts"></script>
</body>
Expand Down
15 changes: 14 additions & 1 deletion js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class World {
this.controls.maxPolarAngle = Math.PI / 2;

this.load(new Pringle())
this.updateInfo()
document.addEventListener("keydown", evt => this.onDocumentKeyDown(evt), false);

this.animate()
Expand Down Expand Up @@ -108,6 +109,17 @@ class World {
this.replaceSurf(surf)
}

updateInfo() {
const surf = this.surfMesh?.surf
if (surf) {
const info = `${surf.name} vertices: ${surf.vertices.length} faces: ${surf.indices.length/3}`
const info_div = document.getElementById('my-info')
if (info_div) {
info_div.textContent = info
}
}
}

onDocumentKeyDown(event) {
var key= event.key
switch (key) {
Expand Down Expand Up @@ -148,7 +160,7 @@ class World {
break
case 'e':
console.log(`evolving`)
this.evolve()
this.evolve(0.05)
break
case 'r':
console.log('run')
Expand All @@ -173,6 +185,7 @@ class World {
default:
console.log(`unknown command. key: ${event.key} keyCode: ${event.which}`)
}
this.updateInfo()
}
}

Expand Down
4 changes: 3 additions & 1 deletion js/surf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Vector, scale_vector, vector_sum, vector_diff, number_product, squared_n
type Index = number

export default class Surf {
name: string
buffer: ArrayBuffer
vertices: Float32Array
indices: Index[]
Expand All @@ -13,7 +14,8 @@ export default class Surf {
closed: boolean
})[]

constructor() {
constructor(name) {
this.name = name
this.buffer = new ArrayBuffer(0)
this.vertices = new Float32Array()
this.indices = []
Expand Down
2 changes: 1 addition & 1 deletion js/surfs/octa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Vector, squared_norm, vector_diff} from '../algebra'
export class Octa extends Surf {
mode: string
constructor(s:string='brakke_1') {
super()
super(`Octa(${s})`)
this.mode = s
function segment(start:Vector,end:Vector):(number)=>Vector {
const [sx,sy,sz] = start
Expand Down

0 comments on commit 1105882

Please sign in to comment.