From 3d4dd6b4285ae8083acdad77657a6982cfce1286 Mon Sep 17 00:00:00 2001 From: blkgoose Date: Thu, 17 Jan 2019 09:53:35 +0100 Subject: [PATCH 1/2] Added interaction functions --- sketch.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sketch.js b/sketch.js index e9925c7..7803a2a 100644 --- a/sketch.js +++ b/sketch.js @@ -28,7 +28,6 @@ function draw () { //update calculate() - interact() step() //draw @@ -47,14 +46,20 @@ function draw () { } -function interact () { - if (mouseIsPressed) { - let x = Math.floor(mouseX / POINT_MARGIN) - let y = Math.floor(mouseY / POINT_MARGIN) - if (x >= 0 && y >= 0 && x < GRID_WIDTH && y < GRID_HEIGHT) { - points[x][y].nextVal = INTERACTION_STRENGTH - points[x][y].force = 0 - } +function mouseDragged() { + interact(INTERACTION_STRENGTH/4) +} + +function mousePressed() { + interact(INTERACTION_STRENGTH) +} + +function interact(str) { + let x = Math.floor(mouseX / POINT_MARGIN) + let y = Math.floor(mouseY / POINT_MARGIN) + if (x >= 0 && y >= 0 && x < GRID_WIDTH && y < GRID_HEIGHT) { + points[x][y].nextVal += str + points[x][y].force = 0 } } From 6991868666ccdbe004477c51021868986e464d41 Mon Sep 17 00:00:00 2001 From: blkgoose Date: Thu, 17 Jan 2019 09:55:51 +0100 Subject: [PATCH 2/2] Lowered interaction strength --- sketch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sketch.js b/sketch.js index 7803a2a..edabc23 100644 --- a/sketch.js +++ b/sketch.js @@ -2,7 +2,7 @@ const MODE = 1 // 1: Wireframe; 2: Cubes const FLUIDITY = 0.99 // 0 < x < 1 TIP: 1 means no loss in time const SPEED = 0.1 // 0 < x < 1 WARNING! High values make the simulation unstable -const INTERACTION_STRENGTH = -50 // How muck force is given to a clicked point +const INTERACTION_STRENGTH = -30 // How muck force is given to a clicked point const MIN_AMMOUNT = 50 // Ammount of points on the shorter side of the grid const ASPECT_RATIO = window.innerWidth / window.innerHeight