Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
jcponce committed Jul 19, 2023
1 parent 484ee8f commit 9007f4d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
Binary file modified .DS_Store
Binary file not shown.
15 changes: 9 additions & 6 deletions math1052/sketches/chapter-01/damped-oscillator/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ function setup() {
function draw() {

background(150);

updateSpring();

push();
translate(0,0)
springCurve(ps-50, 0, left);
line(left, ps-50, left, ps-32);
translate(0, 0);
springCurve(ps - 45, 0, left);
line(left, ps - 45, left, ps - 20);
pop();
//cursor('default');
updateSpring();

drawSpring();

updateGraph();
drawGraph();

Expand Down Expand Up @@ -110,7 +113,7 @@ function drawGraph() {
noFill();
beginShape();
for (let i=0; i<maxPoints; i++) {
vertex(i*5.2, points[i]);
vertex(i*5.25, points[i]);
}
endShape();
pop();
Expand Down
92 changes: 47 additions & 45 deletions math1052/sketches/chapter-01/simple-oscillator/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ let diam = 64;
let t = 0;

let wave = [];
let start = false;
let over = false;
let move = false;
let start = false; // Start animation

let dragging = false; // Is the object being dragged?
let dragging = false; // Is the object being dragged?
let rollover = false; // Is the mouse over the ellipse?

function setup() {
Expand All @@ -25,15 +23,14 @@ function draw() {
background(112, 50, 126);

y = generalSolution(t) + height / 2;
if(start){

if (start) {
t = t + 0.27;
}



push();
stroke(190, 90);
line(0, height/2, width, height/2)
line(0, height / 2, width, height / 2);
pop();

// Draw spring curve
Expand All @@ -47,31 +44,29 @@ function draw() {
strokeWeight(4);
line(100, y - 40, 100, y - 32);
pop();




// Test if mouse if over the circle (mass)
let d = dist(x, y, mouseX, mouseY);
if (d < diam / 2) {
over = true;
//over = true;
rollover = true;
cursor("grab");
} else {
over = false;
//over = false;
rollover = false;
cursor("default");
}
//console.log(rollover);

// Set and constrain the position of top bar
// Adjust location if being dragged
if (dragging) {
A = mouseY - height/2;
}
// Adjust location if being dragged
if (dragging) {
A = mouseY - height / 2;
}

push();
noStroke();
if (over) {
if (rollover) {
fill(200, 200, 220);
} else {
fill(45, 197, 244);
Expand All @@ -80,30 +75,26 @@ function draw() {
pop();

//if (start) {




wave.unshift(y);
translate(100, 0);
push();
beginShape();
noFill();
stroke(255);
for (let i = 0; i < wave.length; i++) {
vertex(i, wave[i]);
}
endShape();
pop();

if (wave.length > 1000) {
wave.pop();
}

wave.unshift(y);
translate(100, 0);
push();
beginShape();
noFill();
stroke(255);
for (let i = 0; i < wave.length; i++) {
vertex(i, wave[i]);
}
endShape();
pop();

if (wave.length > 1000) {
wave.pop();
}
//}

changeParameters();



//console.log(y )
}

Expand Down Expand Up @@ -151,9 +142,12 @@ function springCurve(y0, y1, Ap) {
}

function mousePressed() {
dragging = true;
start = false;
t = 0;
if (rollover) {
dragging = true;
start = false;
t = 0;
}

//console.log(dragging);
}

Expand All @@ -163,3 +157,11 @@ function mouseReleased() {
start = true;
//console.log(dragging);
}

function keyPressed() {
if (keyCode == 82) {
t = 0;
start = false;
A = 0;
}
}

0 comments on commit 9007f4d

Please sign in to comment.