From 1daa098fe8257dc4b90fe97a0ef5cedf97b9715f Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 13 Jul 2004 17:29:47 +0000 Subject: [PATCH] cleaning up math api --- core/PApplet.java | 36 +++++++++++++++++++++++++++++++++++- core/PGraphics.java | 2 ++ core/todo.txt | 11 ++++++++--- todo.txt | 4 +++- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/core/PApplet.java b/core/PApplet.java index 34a46f7dc..d0857fb4b 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -1065,6 +1065,14 @@ public class PApplet extends Applet return (float)Math.sqrt(a); } + static public final float log(float a) { + return (float)Math.log(a); + } + + static public final float exp(float a) { + return (float)Math.exp(a); + } + static public final float pow(float a, float b) { return (float)Math.pow(a, b); } @@ -1086,6 +1094,11 @@ public class PApplet extends Applet return Math.min(a, Math.min(b, c)); } + + static public final float lerp(float a, float b, float amt) { + return a + (b-a) * amt; + } + static public final float constrain(float amt, float low, float high) { return (amt < low) ? low : ((amt > high) ? high : amt); } @@ -1124,6 +1137,18 @@ public class PApplet extends Applet return (float)Math.tan(angle); } + static public final float asin(float angle) { + return (float)Math.asin(angle); + } + + static public final float acos(float angle) { + return (float)Math.acos(angle); + } + + static public final float atan(float angle) { + return (float)Math.atan(angle); + } + static public final float atan2(float a, float b) { return (float)Math.atan2(a, b); } @@ -1151,12 +1176,21 @@ public class PApplet extends Applet } + static public final float mag(float a, float b) { + return (float)Math.sqrt(a*a + b*b); + } + + static public final float mag(float a, float b, float c) { + return (float)Math.sqrt(a*a + b*b + c*c); + } + + static public final float dist(float x1, float y1, float x2, float y2) { return sqrt(sq(x2-x1) + sq(y2-y1)); } static public final float dist(float x1, float y1, float z1, - float x2, float y2, float z2) { + float x2, float y2, float z2) { return sqrt(sq(x2-x1) + sq(y2-y1) + sq(z2-z1)); } diff --git a/core/PGraphics.java b/core/PGraphics.java index 11e1c43a6..33852e4d9 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -4142,6 +4142,8 @@ public class PGraphics extends PImage implements PConstants { } } else { + //System.out.println(getClass().getName()); + //System.out.println(getClass().getResource(filename)); awtimage = gimmeImage(getClass().getResource(filename), force); if (awtimage == null) { awtimage = diff --git a/core/todo.txt b/core/todo.txt index a83359005..a5ced955a 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -60,8 +60,13 @@ X do applets know when they're stopped? stop? dispose? X would be good to set a param in p5 so that the thread dies X if people have other threads they've spawned, impossible to stop +X include a lerp()? is there one in flash? +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Programs;action=display;num=1083289030 +_ should it be called lerp or mix? +X acos, asin, log, exp, ceil/floor, pow, mag(x,y,z) MEGABUCKET (api) + _ color issues _ add color(gray) and color(gray, alpha) _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1074180764 @@ -78,9 +83,6 @@ _ include in the docs: don't override stop() _ or handle this some more intelligent way, super.stop() is needed. _ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1083574943 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1067383998 -_ include a lerp()? is there one in flash? -_ http://processing.org/discourse/yabb/YaBB.cgi?board=Programs;action=display;num=1083289030 -_ acos/asin/etc? _ angleMode(DEGREES) and angleMode(RADIANS) _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1075507381;start=0 _ figure out how to handle cached images, multiple images @@ -100,7 +102,9 @@ _ append/unappend (no push/pop), shift/unshift, _ slice, splice, reverse, concat, split _ more blend() modes? (the five listed on the thread below?) _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1082056702 +_ seems like semi-standard modes _ update() mode needs to be hacked in (?) +_ make 'online' a boolean _ illustrator export / rendering mode @@ -215,6 +219,7 @@ CORE / PGraphics 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1083221401;start=0 1 _ scaled ellipse showing up as a hexagon 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1083674213 + 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1084652597;start=0 1 _ problem with the fill 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1077834735 1 _ z values not set properly on ellipses? diff --git a/todo.txt b/todo.txt index ab0ac9ee3..d85027dfb 100644 --- a/todo.txt +++ b/todo.txt @@ -4,8 +4,10 @@ X http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs X fixed one bug in PdeRuntime error message stuff X was this the big one? a big one? +040713 +X fixes to line and curve code -_ line fade out gradient bug.. is this an easy fix? +_ terrible loadImage bug.. does it affect loadStrings? _ "save as" needs to update the editorheader