Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlotGrapher- V205 #226

Merged
merged 27 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a221582
Create Index.js
V205Arduino Dec 24, 2023
4a569a4
Rename Index.js to index.js
V205Arduino Dec 24, 2023
467215f
Update index.js
V205Arduino Dec 24, 2023
d90bc95
Create snapshots
V205Arduino Dec 24, 2023
90ae680
Delete art/BlotGrapher - V205/snapshots
V205Arduino Dec 24, 2023
7715715
Update index.js
V205Arduino Dec 24, 2023
57a69e1
Add files via upload
V205Arduino Dec 25, 2023
d3d48f3
Create test
V205Arduino Dec 25, 2023
82b2443
Add files via upload
V205Arduino Dec 25, 2023
bb4805b
Delete art/BlotGrapher - V205/IMG_1109.jpeg
V205Arduino Dec 25, 2023
eef73e0
Delete art/BlotGrapher - V205/IMG_1116.jpeg
V205Arduino Dec 25, 2023
a0cd13a
Update index.js
V205Arduino Dec 25, 2023
c2cd510
Update index.js
V205Arduino Dec 25, 2023
3e11669
Delete art/BlotGrapher - V205/IMG_1117.png
V205Arduino Dec 25, 2023
15ad1f5
Delete art/BlotGrapher - V205/snapshots/test
V205Arduino Dec 25, 2023
81b274b
Rename IMG_1109.jpeg to Snapshot1.jpeg
V205Arduino Dec 25, 2023
ce7f274
Rename IMG_1117.png to Snapshot2.png
V205Arduino Dec 25, 2023
660ce7f
Rename IMG_1111.jpeg to Snapshot3.jpeg
V205Arduino Dec 25, 2023
c1fb168
Merge branch 'hackclub:main' into patch-3
V205Arduino Jan 3, 2024
d85a73b
Merge branch 'hackclub:main' into patch-3
V205Arduino Jan 3, 2024
a935d2a
Merge branch 'hackclub:main' into patch-3
V205Arduino Jan 6, 2024
95eb3d6
Update index.js
V205Arduino Jan 6, 2024
e3ad724
Update index.js
V205Arduino Jan 6, 2024
95c3474
Update index.js
V205Arduino Jan 6, 2024
cf4d0c5
Merge branch 'hackclub:main' into patch-3
V205Arduino Jan 7, 2024
6adc168
Update index.js
V205Arduino Jan 7, 2024
6026d06
Update index.js
V205Arduino Jan 9, 2024
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
291 changes: 291 additions & 0 deletions art/BlotGrapher - V205/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
/*
Blot Grapher
Credits:
V205 and Bright Li
Q: What is this? A: This is a WIP graphing tool.
Q: What can this do? A: This program can currently graph lines.


Commands:

// this is the format to use this program:
/*
//NOTE: The floating point decimal things will give you some drift.
//NOTE: If it is a formula that can have two y values for one x, it will probably not work properly.I'll try to fix it later

// this is the format to use this program:
/*
//NOTE: The floating point decimal things will give you some drift.
//NOTE: If it is a formula that can have two y values for one x, it will probably not work properly.I'll try to fix it later

var formulaName = function(n) {
return (n) // now, modify the returned value to something!
}


//You can use Math(.sin and other things) tools to help.



// Draw it! I made it return a turtle

drawTurtles([
drawEquation(formulaName)
])
//seperate more equations with comas on new lines
// if you don't see anything, your equation is probably in the negatives or is very large

// these names should explain them self.
drawEquation(formula,resolution,maxX,minX,maxY,minY)
*/


/*
V 0.5
Changelog:
1/5/24 made a drawing of pi. update readme.
12/23/23 Added comments V 0.6
12/23/23 Added maxY and minY V 0.5
12/22/23 Added maxX and minX V 0.4
12/21/23 Added resolution V 0.3
12/18/23 Basic versions V 0.1 and V 0.2


*/




const width = 125;
const height = 125;

setDocDimensions(width, height);










function drawEquation(formulaa, resolution, maxX, minX, maxY, minY) {
const graphTurtle = createTurtle();
// if you are exploring this code, I would advise you to start from here and go down, closing those little arrows for collapsing code as you go.
// Sorry for the mess.

// check if parameters is blank(or non real numbers), if so, use defaults
if (!maxY && maxY != 0) {
console.log("defaulting to maxY = 100")
maxY = 100;
}
if (!minY && minY != 0) {
console.log("defaulting to minY = 0")
minY = 0;
}
if (!maxX && maxX != 0) {
console.log("defaulting to maxX = 100")
maxX = 100;
}
if (!minX && minX != 0) {
console.log("defaulting to minX = 0")
minX = 0;
}
// is resolution a non zero positive number?

if (resolution <= 0 || !resolution) {
console.log("Please use positive numbers for resolution. Resolution = " + resolution);
console.log("resolution defaulting to 0.1")
resolution = 0.1;
}

var x = minX;
const originalX = x;




while (x <= maxX) {

let yActual = formulaa(x);
var previousY = formulaa(x - resolution);


//comment the following out if your console gets flooded
console.log("x = " + x + ", y = " + yActual)

if (x == originalX) { // is x the original value of x(or the minimum value?)?
// if so, use jump not goto to not make a extra line.


graphTurtle.jump([graphTurtle.lb[0], graphTurtle.lb[1]])
graphTurtle.jump([originalX, yActual])

} else {
// is yActual not a real number or is out of the bounds(maxY,minY)
if ((!yActual || (yActual >= maxY) || (yActual <= minY)) && yActual != 0) { //|| (yActual >=maxY) || (yActual <= minY)
//out of bounds.
//uncomment this if you want:
//console.log("yActual out of bounds. yActual is: " + yActual )


} else {
// everything else, draw a line.

// very messy code, figure out how to clean this up.
// lots of conditions, probably way too many.
if (previousY <= maxY && previousY >= minY && yActual <= maxY && yActual >= minY) {

graphTurtle.down()
graphTurtle.goTo([x, yActual]);
} else {

graphTurtle.jump([x, yActual]);
}
}
}
x += resolution // add resolution to x.


}
/*
drawTurtles([
graphTurtle
]);
*/
return graphTurtle
}


// this is the format to use this program:
/*
//NOTE: The floating point decimal things will give you some drift.
//NOTE: If it is a formula that can have two y values for one x, it will probably not work properly.I'll try to fix it later

var formulaName = function(n) {
return (n) // now, modify the returned value to something!
}


//You can use Math(.sin and other things) tools to help.



// Draw it! I made it return a turtle

drawTurtles([
drawEquation(formulaName)
])
//add more equations with comas on new lines
// if you don't see anything, your equation is probably in the negatives or is very large

// these names should explain them self.
drawEquation(formula,resolution,maxX,minX,maxY,minY)
*/

// This is the straight line near the top, it is cropped with the parameters.
var linearLine = function(n) {
return (90) //Math.sin(n) +

}


// this is the other straight line at the top, this is the one at the very top.
var linearLine2 = function(n) {
return (100) //Math.sin(n) +
}



// the left top corner
var leftTop = function(n) {
return (-1 / 11 * Math.pow(n - 20, 2) + 100)
}


// the other left top corner part
var leftTop2 = function(n) {
return (-1 / 20 * Math.pow(n - 20, 2) + 90)
}




// the right top corner
var rightTop = function(n) {
return (1 / 20 * Math.pow(n - 100, 2) + 100)
}



// the other right top corner
var rightTop2 = function(n) {
return (1 / 11 * Math.pow(n - 100, 2) + 90)
}



// the bottom left left leg
var bottomLeftLeft = function(n) {
return (1 / 8 * Math.pow(n - 5, 2) + 5)
}



// the bottom left right leg

var bottomLeftRight = function(n) {
return (1 / 8 * Math.pow(n - 15, 2))
}




// bottom right left corner

// y = ax^2 + bx + c
var bottomRightLeft = function(n) {
return (1 / 8 * Math.pow(n - 100, 2))
} //v+Math.sqrt(r-Math.pow(n-v,2)))



// bottom right right corner


// y = ax^2 + bx + c
var bottomRightRight = function(n) {
return (1 / 8 * Math.pow(n - 110, 2))
} //v+Math.sqrt(r-Math.pow(n-v,2)))












// the very bottom




drawTurtles([
drawEquation(linearLine, 1, 100, 20),
drawEquation(linearLine2, 1, 100, 20, 200),
drawEquation(leftTop, 0.1, 20, 5, 900.1),
drawEquation(leftTop2, 0.1, 20, 5, 900.1),
drawEquation(rightTop, 0.1, 115, 100, 900.1),
drawEquation(rightTop2, 0.1, 115, 100, 900.1),
drawEquation(bottomLeftLeft, 0.1, 100, 8.2, 90.1),
drawEquation(bottomLeftRight, 0.1, 100, 8.2, 90.1),
drawEquation(bottomRightLeft, 0.1, 100, 0, 90),
drawEquation(bottomRightRight, 0.1, 110, 0, 90)

]);

Binary file added art/BlotGrapher - V205/snapshots/Snapshot1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/BlotGrapher - V205/snapshots/Snapshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/BlotGrapher - V205/snapshots/Snapshot3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.