Skip to content

Commit

Permalink
Merge pull request #23 from OSTERITE/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Osterie authored Jan 23, 2023
2 parents 35f9b89 + f6c8df2 commit 2b8c43e
Show file tree
Hide file tree
Showing 2,728 changed files with 198,926 additions and 229 deletions.
21 changes: 8 additions & 13 deletions color_function/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
<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>

<center>
<p> Write an expression with X and Y(only capitalized letters) (Can use Math.sin(X)*100 and such)</p>
<p> Write an expression with X and Y(only capitalized letters) (Can use Math.sin(X)*100 and such)</p>
<p> Zoom using mouse and drag, hold ctrl and click to unzoom</p>

<!-- <button id='reset'> Reset Configs(NA)</button> -->

<textarea id='hue_expression' cols="40" rows="5">X*Y</textarea>
<!-- <button id='reset'> Reset Configs(NA)</button> -->
<textarea id='hue_expression' placeholder="Hue" cols="40" rows="5">X*Y</textarea>
<textarea id='saturation_expression' placeholder="Saturation" cols="40" rows="5">100</textarea>
<textarea id='lightness_expression' placeholder="Hue" cols="40" rows="5">50</textarea>
<textarea id='lightness_expression' placeholder="Lightness" cols="40" rows="5">50</textarea>

<input id='pixel_ratio' type="text" placeholder="Pixel Ratio" value="1">
<input id='size_lower' type='number' placeholder="Size Lower" value='-10'>
Expand All @@ -33,16 +30,14 @@
<canvas id="canvas" width="600px" height="600px"> </canvas> <br>
</center>

<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script> For saving of files -->
<!-- <script src="https://fulab.no/skolemappe/faa-vgs/bibliotek/IT-2/teamtools.js"> </script> -->
<!-- <script src="https://fulab.no/fulibs/fusionSDK.js"> </script> -->
<!-- Fulab functions and such-->


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

<script src="./library/mathjs/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> -->
<script src="script.js"> </script>
</body>


</html>
268 changes: 138 additions & 130 deletions color_function/library/classdefinitions.js

Large diffs are not rendered by default.

101 changes: 47 additions & 54 deletions color_function/library/functions.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,86 @@

//Returns angle between two vectors, unit can be "deg" or radians
function v2a(vector1, vector2, unit) {
vector1_length = Math.sqrt(vector1[0] ** 2 + vector1[1] ** 2);
vector2_length = Math.sqrt(vector2[0] ** 2 + vector2[1] ** 2);
vector_product = vector1[0] * vector2[0] + vector1[1] * vector2[1];

//angle as degrees
if (unit == "deg") {
var angle =
(Math.acos(vector_product / (vector1_length * vector2_length)) * 180) /
Math.PI;
return angle;
}

//angle as radians
else {
var angle = Math.acos(vector_product / (vector1_length * vector2_length));
return angle;
}
}
vector1_length = Math.sqrt(vector1[0] ** 2 + vector1[1] ** 2);
vector2_length = Math.sqrt(vector2[0] ** 2 + vector2[1] ** 2);
vector_product = vector1[0] * vector2[0] + vector1[1] * vector2[1];

//angle as degrees
if (unit == "deg") {
var angle = (Math.acos(vector_product / (vector1_length * vector2_length)) * 180) / Math.PI;
return angle;
}

//angle as radians
else {
var angle = Math.acos(vector_product / (vector1_length * vector2_length));
return angle;
}
}

function largest_drawable_square(cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y) {

function largest_drawable_square(cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y){
let height = 0; //Positive values down, negative values up.
let width = 0; //positive values to the right, negative to the left.
let width = 0; //positive values to the right, negative to the left.

//checks which quadrant mouse is in relation to the initially clicked point (think unit circle quadrants or whatever)
let quadrant = 'top_right'
let quadrant = "top_right";

if (cursor_end_y - cursor_start_y > 0) {
quadrant = "bottom_right"
quadrant = "bottom_right";
}

if (cursor_end_x - cursor_start_x < 0) {
quadrant = "bottom_left"
if (cursor_end_y - cursor_start_y < 0){
quadrant = "top_left"
quadrant = "bottom_left";
if (cursor_end_y - cursor_start_y < 0) {
quadrant = "top_left";
}
}


const square_width = cursor_end_x - cursor_start_x
const square_height = cursor_end_y - cursor_start_y
//finds the cursor x or y position which would give the greatest width or height (both?)
//current mouse position is in top right or bottom left quadrant (quadrant 'top_right' and "bottom_left")
if (quadrant == 'top_right' || quadrant == "bottom_left") {
if (Math.abs(cursor_end_x - cursor_start_x) > Math.abs(cursor_end_y - cursor_start_y)) {
width = cursor_end_x - cursor_start_x;
height = -width
//current mouse position is in top right or bottom left quadrant (quadrant top_right or bottom_left)
if (quadrant == "top_right" || quadrant == "bottom_left") {
if (Math.abs(square_width) > Math.abs(square_height)) {
width = square_width;
height = -width;
}

else {
height = (cursor_end_y - cursor_start_y)
width = -height
height = square_height;
width = -height;
}
}
//quadrant "top_left" and bottom_right
//quadrant top_left or bottom_right
else if (quadrant == "top_left" || quadrant == "bottom_right") {

if (Math.abs(cursor_end_x - cursor_start_x) > Math.abs(cursor_end_y - cursor_start_y)) {
width = cursor_end_x - cursor_start_x;
height = width
}
if (Math.abs(square_width) > Math.abs(square_height)) {
width = square_width;
height = width;
}
else {
width = cursor_end_y - cursor_start_y;
height = width
width = square_height;
height = width;
}
}
return {cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y, width, height}
return {cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y, width, height, };
}


function get_cursor_position(canvas, event) {
//finds the absolute coordinates clicked, given as distence from top left.
return [event.offsetX, event.offsetY];
}


function draw_square(canvas_info, background_img, cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y) {
function draw_square(canvas_info, background_img, cursor_start_x, cursor_end_x,cursor_start_y, cursor_end_y) {
let canvas = canvas_info;
const ctx = canvas.getContext("2d", { alpha: false });
let current_square = largest_drawable_square( cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y)
let current_square = largest_drawable_square(cursor_start_x, cursor_end_x, cursor_start_y, cursor_end_y);

let parameter_x = cursor_start_x + ~~current_square.width;
let parameter_y = cursor_start_y + ~~current_square.height;
//Draws the guiding box if it fits the canvas
if ( (parameter_x < canvas.width && parameter_x > 0) && (parameter_y < canvas.height && parameter_y > 0 ) ){
if ( (parameter_x < canvas.width && parameter_x > 0) && (parameter_y < canvas.height && parameter_y > 0) ) {
ctx.drawImage(background_img, 0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.rect(cursor_start_x, cursor_start_y, current_square.width, current_square.height);
ctx.stroke();
}
}

function get_cursor_position(canvas, event) {
//finds the absolute coordinates clicked, given as distence from top left.
return [event.offsetX, event.offsetY];
}
12 changes: 12 additions & 0 deletions color_function/library/mathjs/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/mathjs/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/mathjs/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/mathjs/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/mathjs/node_modules/@babel/runtime/LICENSE

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 2b8c43e

Please sign in to comment.