“SPO Final Project - BONUS 2” by Data Flaw
https://openprocessing.org/sketch/1007065
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
SPO Final Project - BONUS 2
Flaw
var amt = 0;
function setup() {
createCanvas(500, 500);
background(0);
}
function draw() {
//background(0);
fill(0,10);
rect(0,0,width,height);
link(100,100,400,400);
link(100,100,300,200);
}
function link(posX1, posY1, posX2, posY2)
{
var amtInc = 0.005; // Works best between 0.0001 (very slow) to 0.01 (fast)
stroke(255);
//line(posX1, posY1, posX2, posY2); // Uncomment this if you want to see the line
// Math part, if you're interested :)
// I'm creating two vectors ("v1" and "v2") corresponding to the positions of my two points
// Then I'm using what's called an "interpolation" with the function "lerp"
// to calculate several steps between those two points, and creating the vector "v3" to store them
// The variable "amt" let us control the interpolation :
// at amt = 0, v3 = v1 (origin position)
// at amt = 1, v3 = v2 (final position)
let v1 = createVector(posX1, posY1);
let v2 = createVector(posX2, posY2);
let v3 = p5.Vector.lerp(v1, v2, amt);
fill(255);
ellipse(v3.x, v3.y, 10,10);
amt+= amtInc; // I'm incrementing amt with a tiny step each frame
amt = amt%1; // When amt = 1 (and my ellipse is at the final position), amt will be pulled back to 0.
}
See More Shortcuts