Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bundles/curve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ export {
y_of,
z_of
} from './functions';

export {} from './type_interface';

export {
type_map
} from '../../typings/type_map';
123 changes: 123 additions & 0 deletions src/bundles/curve/type_interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { classDeclaration, typeDeclaration, functionDeclaration } from '../../typings/type_map';

@classDeclaration('Point')
export class Point {}

@classDeclaration('AnimatedCurve')
export class AnimatedCurve{}

@typeDeclaration('(u: number) => Point')
export class Curve {}

@typeDeclaration('(t: number) => Curve')
export class CurveAnimation {}

export class TypeInterface {
@functionDeclaration('duration: number, fps: number, drawer: (func: Curve) => Curve, func: (func: Curve) => Curve', 'AnimatedCurve')
animate_3D_curve() {}

@functionDeclaration('duration: number, fps: number, drawer: (func: Curve) => Curve, func: (func: Curve) => Curve', 'AnimatedCurve')
animate_curve() {}

@functionDeclaration('t: number', 'number')
arc() {}

@functionDeclaration('p: Point', 'number')
b_of() {}

@functionDeclaration('curve1: Curve, curve2: Curve', 'Curve')
connect_ends() {}

@functionDeclaration('curve1: Curve, curve2: Curve', 'Curve')
connect_rigidly() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_3D_connected() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_3D_connected_full_view() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_3D_connected_full_view_proportional() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_3D_points() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_3D_points_full_view() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_3D_points_full_view_proportional() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_connected() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_connected_full_view() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_connected_full_view_proportional() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_points() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_points_full_view() {}

@functionDeclaration('numPoints: number', '(func: Curve) => Curve')
draw_points_full_view_proportional() {}

@functionDeclaration('p: Point', 'number')
g_of() {}

@functionDeclaration('curve: Curve', 'Curve')
invert() {}

@functionDeclaration('x: number, y: number, z: number, r: number, g: number, b: number', 'Point')
make_3D_color_point() {}

@functionDeclaration('x: number, y: number, z: number', 'Point')
make_3D_point() {}

@functionDeclaration('x: number, y: number, r: number, g: number, b: number', 'Point')
make_color_point() {}

@functionDeclaration('x: number, y: number', 'Point')
make_point() {}

@functionDeclaration('curve: Curve', 'Curve')
put_in_standard_position() {}

@functionDeclaration('p: Point', 'number')
r_of() {}

@functionDeclaration('theta1: number, theta2: number, theta3: number', '(c: Curve) => Curve')
rotate_around_origin() {}

@functionDeclaration('x: number, y: number', '(c: Curve) => Curve')
scale() {}

@functionDeclaration('s: number', '(c: Curve) => Curve')
scale_proportional() {}

@functionDeclaration('x0: number, y0: number, z0: number', '(c: Curve) => Curve')
translate() {}

@functionDeclaration('t: number', 'Point')
unit_circle() {}

@functionDeclaration('t: number', 'Point')
unit_line() {}

@functionDeclaration('t: number', 'Curve')
unit_line_at() {}

@functionDeclaration('p: Point', 'number')
x_of() {}

@functionDeclaration('p: Point', 'number')
y_of() {}

@functionDeclaration('p: Point', 'number')
z_of() {}
}
199 changes: 104 additions & 95 deletions src/bundles/rune/display.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import context from 'js-slang/context';
import { functionDeclaration } from '../../typings/type_map';
import { AnaglyphRune, HollusionRune } from './functions';
import { type DrawnRune, AnimatedRune, type Rune, NormalRune, type RuneAnimation } from './rune';
import { AnimatedRune, NormalRune, type DrawnRune, type Rune, type RuneAnimation } from './rune';
import { throwIfNotRune } from './runes_ops';

// =============================================================================
Expand All @@ -12,103 +13,111 @@ context.moduleContexts.rune.state = {
drawnRunes
};

/**
* Renders the specified Rune in a tab as a basic drawing.
* @param rune - The Rune to render
* @return {Rune} The specified Rune
*
* @category Main
*/
export function show(rune: Rune): Rune {
throwIfNotRune(show.name, rune);
drawnRunes.push(new NormalRune(rune));
return rune;
}
class RuneDisplay {
/**
* Renders the specified Rune in a tab as a basic drawing.
* @param rune - The Rune to render
* @return {Rune} The specified Rune
*
* @category Main
*/
@functionDeclaration('rune: Rune', 'Rune')
static show(rune: Rune): Rune {
throwIfNotRune(RuneDisplay.show.name, rune);
drawnRunes.push(new NormalRune(rune));
return rune;
}

/**
* Renders the specified Rune in a tab as an anaglyph. Use 3D glasses to view the
* anaglyph.
* @param rune - The Rune to render
* @return {Rune} The specified Rune
*
* @category Main
*/
export function anaglyph(rune: Rune): Rune {
throwIfNotRune(anaglyph.name, rune);
drawnRunes.push(new AnaglyphRune(rune));
return rune;
}
/**
* Renders the specified Rune in a tab as an anaglyph. Use 3D glasses to view the
* anaglyph.
* @param rune - The Rune to render
* @return {Rune} The specified Rune
*
* @category Main
*/
@functionDeclaration('rune: Rune', 'Rune')
static anaglyph(rune: Rune): Rune {
throwIfNotRune(RuneDisplay.anaglyph.name, rune);
drawnRunes.push(new AnaglyphRune(rune));
return rune;
}

/**
* Renders the specified Rune in a tab as a hollusion, using the specified
* magnitude.
* @param rune - The Rune to render
* @param {number} magnitude - The hollusion's magnitude
* @return {Rune} The specified Rune
*
* @category Main
*/
export function hollusion_magnitude(rune: Rune, magnitude: number): Rune {
throwIfNotRune(hollusion_magnitude.name, rune);
drawnRunes.push(new HollusionRune(rune, magnitude));
return rune;
}
/**
* Renders the specified Rune in a tab as a hollusion, using the specified
* magnitude.
* @param rune - The Rune to render
* @param {number} magnitude - The hollusion's magnitude
* @return {Rune} The specified Rune
*
* @category Main
*/
@functionDeclaration('rune: Rune, magnitude: number', 'Rune')
static hollusion_magnitude(rune: Rune, magnitude: number): Rune {
throwIfNotRune(RuneDisplay.hollusion_magnitude.name, rune);
drawnRunes.push(new HollusionRune(rune, magnitude));
return rune;
}

/**
* Renders the specified Rune in a tab as a hollusion, with a default magnitude
* of 0.1.
* @param rune - The Rune to render
* @return {Rune} The specified Rune
*
* @category Main
*/
export function hollusion(rune: Rune): Rune {
throwIfNotRune(hollusion.name, rune);
return hollusion_magnitude(rune, 0.1);
}
/**
* Renders the specified Rune in a tab as a hollusion, with a default magnitude
* of 0.1.
* @param rune - The Rune to render
* @return {Rune} The specified Rune
*
* @category Main
*/
@functionDeclaration('rune: Rune', 'Rune')
static hollusion(rune: Rune): Rune {
throwIfNotRune(RuneDisplay.hollusion.name, rune);
return RuneDisplay.hollusion_magnitude(rune, 0.1);
}

/**
* Create an animation of runes
* @param duration Duration of the entire animation in seconds
* @param fps Duration of each frame in frames per seconds
* @param func Takes in the timestamp and returns a Rune to draw
* @returns A rune animation
*
* @category Main
*/
export function animate_rune(
duration: number,
fps: number,
func: RuneAnimation
) {
const anim = new AnimatedRune(duration, fps, (n) => {
const rune = func(n);
throwIfNotRune(animate_rune.name, rune);
return new NormalRune(rune);
});
drawnRunes.push(anim);
return anim;
}
/**
* Create an animation of runes
* @param duration Duration of the entire animation in seconds
* @param fps Duration of each frame in frames per seconds
* @param func Takes in the timestamp and returns a Rune to draw
* @returns A rune animation
*
* @category Main
*/
@functionDeclaration('duration: number, fps: number, func: RuneAnimation', 'AnimatedRune')
static animate_rune(duration: number, fps: number, func: RuneAnimation) {
const anim = new AnimatedRune(duration, fps, (n) => {
const rune = func(n);
throwIfNotRune(RuneDisplay.animate_rune.name, rune);
return new NormalRune(rune);
});
drawnRunes.push(anim);
return anim;
}

/**
* Create an animation of anaglyph runes
* @param duration Duration of the entire animation in seconds
* @param fps Duration of each frame in frames per seconds
* @param func Takes in the timestamp and returns a Rune to draw
* @returns A rune animation
*
* @category Main
*/
export function animate_anaglyph(
duration: number,
fps: number,
func: RuneAnimation
) {
const anim = new AnimatedRune(duration, fps, (n) => {
const rune = func(n);
throwIfNotRune(animate_anaglyph.name, rune);
return new AnaglyphRune(rune);
});
drawnRunes.push(anim);
return anim;
/**
* Create an animation of anaglyph runes
* @param duration Duration of the entire animation in seconds
* @param fps Duration of each frame in frames per seconds
* @param func Takes in the timestamp and returns a Rune to draw
* @returns A rune animation
*
* @category Main
*/
@functionDeclaration('duration: number, fps: number, func: RuneAnimation', 'AnimatedRune')
static animate_anaglyph(duration: number, fps: number, func: RuneAnimation) {
const anim = new AnimatedRune(duration, fps, (n) => {
const rune = func(n);
throwIfNotRune(RuneDisplay.animate_anaglyph.name, rune);
return new AnaglyphRune(rune);
});
drawnRunes.push(anim);
return anim;
}
}

export const {show,
anaglyph,
hollusion,
hollusion_magnitude,
animate_rune,
animate_anaglyph,
} = RuneDisplay;
Loading
Loading