Skip to content

Commit

Permalink
installed mathjs library locally and replaced eval
Browse files Browse the repository at this point in the history
  • Loading branch information
Osterie committed Jan 23, 2023
1 parent 3f5a5de commit bd51013
Show file tree
Hide file tree
Showing 2,726 changed files with 198,725 additions and 6 deletions.
6 changes: 4 additions & 2 deletions color_function/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<title>Grafisk fremstilling av temperaturer</title>
<link rel="stylesheet" type="text/css" href="style.css" />

<script src=https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.3.0/math.min.js></script>

</head>

<body>
Expand All @@ -32,6 +30,10 @@
<canvas id="canvas" width="600px" height="600px"> </canvas> <br>
</center>


<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.3.0/math.min.js"></script> -->

<script src="./library/node_modules/mathjs/lib/browser/math.js"></script>
<script src="./library/functions.js"></script> <!-- Can convert vectors to angles (degress or radians) -->
<script src="./library/classdefinitions.js"></script>
<!-- <script src="worker.js"></script> -->
Expand Down
9 changes: 5 additions & 4 deletions color_function/library/classdefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Square {
draw() {
switch (true) {
case isFinite(this.hue):
this.color = `hsl( ${this.hue} , ${this.saturation}% , ${this.lightness}%)`;
this.color = `hsl( ${this.hue}, ${this.saturation}%, ${this.lightness}%)`;
this.ctx.fillStyle = this.color;
this.ctx.fillRect(this.xpos, this.ypos, this.square_size, this.square_size);
break;
Expand All @@ -27,15 +27,16 @@ class Square {
}

hue_changed(expression, x, y) {
this.hue = Function( `return ${expression.replace(/X/g, x).replace(/Y/g, y)}` )();

this.hue = math.evaluate(expression.replace(/X/g, x).replace(/Y/g, y));
this.draw();
}
saturation_changed(expression, x, y) {
this.saturation = Math.abs( ((100 + Function(`return ${expression.replace(/X/g, x).replace(/Y/g, y)}`)()) % 200) - 100 );
this.saturation = Math.abs( ((100 + math.evaluate(expression.replace(/X/g, x).replace(/Y/g, y))) % 200) - 100 );
this.draw();
}
lightness_changed(expression, x, y) {
this.lightness = Math.abs( ((100 + Function(`return ${expression.replace(/X/g, x).replace(/Y/g, y)}`)()) % 200) - 100 );
this.lightness = Math.abs( ((100 + math.evaluate(expression.replace(/X/g, x).replace(/Y/g, y))) % 200) - 100 );
this.draw();
}
}
Expand Down
12 changes: 12 additions & 0 deletions color_function/library/node_modules/.bin/mathjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions color_function/library/node_modules/.bin/mathjs.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions color_function/library/node_modules/.bin/mathjs.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions color_function/library/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions color_function/library/node_modules/@babel/runtime/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions color_function/library/node_modules/@babel/runtime/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd51013

Please sign in to comment.