-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monkeypatching de toAngle et moveServos.
À présent, Processing peut utiliser les mêmes déclarations que celle utilisées par l'Arduino. Signed-off-by: Yoan Blanc <[email protected]>
- Loading branch information
Showing
16 changed files
with
171 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
bool isInside(float x, float y){ | ||
if( x < MIN_X+COR_X ){ | ||
LOG("OUT X", x, "<", MIN_X + COR_X); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
#include <math.h> | ||
|
||
#pragma once | ||
#ifndef LOG | ||
#ifndef DEBUG | ||
#define LOG | ||
#endif | ||
#endif | ||
|
||
bool _etoile(float& x, float& y, float cx, float cy, float r, float par); | ||
void etoile(float cx, float cy, float r, float par = -1); | ||
|
||
// Étoile à 5 branches | ||
// | ||
// https://en.wikipedia.org/wiki/Hypotrochoid | ||
void etoile(float cx, float cy, float r, float par) // étoile à 5 branches | ||
{ | ||
float x, y; | ||
float r1 = r, r2 = r * 3 / 5, d = r; | ||
if (par <= 0) { | ||
par = M_PI / 180; | ||
} | ||
for (float t = 0; t < 6 * M_PI; t += par) { | ||
x = cx + (r1 - r2) * cos(t) + d * cos((r1 - r2) / r2 * t); | ||
y = cy + (r1 - r2) * sin(t) - d * sin((r1 - r2) / r2 * t); | ||
toAngle(x, y); | ||
moveServos(); | ||
LOG("HYPO", t, x, y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
import processing.core.PApplet; | ||
import processing.core.PVector; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
|
||
public class Dessin { | ||
public static String VERSION="0.0.4"; | ||
|
||
public static void main(String[] argv) { | ||
// Ceci est un test. | ||
for(PVector p : etoile(0, 0, 100, 16)) { | ||
System.out.printf("(%.2f; %.2f)\n", p.x, p.y); | ||
} | ||
} | ||
System.out.println("Ceci est un test"); | ||
shared.getCaller().setCallback(new Callback(){ | ||
@Override | ||
public void moveServos() { | ||
System.out.printf("moveServos\n"); | ||
} | ||
|
||
@Override | ||
public void toAngle(float x, float y) { | ||
System.out.printf("toAngle %f, %f\n", x, y); | ||
} | ||
}); | ||
|
||
public static List<PVector> etoile(float cx, float cy, float r) { | ||
// Une puissance de deux c'est bien. | ||
return etoile(cy, cy, r, 256); | ||
shared.etoile(0, 0, 100); | ||
} | ||
|
||
public static List<PVector> etoile(float cx, float cy, float r, float steps) { | ||
List<PVector> points = new ArrayList<PVector>(); | ||
float[] x = new float[]{0}; | ||
float[] y = new float[]{0}; | ||
for(float i=0; i <= 1; i += 1/steps) { | ||
if (shared._etoile(x, y, cx, cy, r, i)) { | ||
points.add(new PVector(x[0], y[0])); | ||
} else { | ||
System.err.printf("Appel à etoile(%f, %f, %f, %d) a échoué.", cx, cy, r, i); | ||
return points; | ||
public static void setPApplet(final PApplet pApplet, final float zoom) { | ||
shared.getCaller().setCallback(new Callback(){ | ||
private PVector old; | ||
private PVector current = new PVector(0, 0); | ||
|
||
@Override | ||
public void moveServos() { | ||
pApplet.line(old.x, old.y, current.x, current.y); | ||
//pApplet.delay(100); | ||
} | ||
|
||
@Override | ||
public void toAngle(float x, float y) { | ||
//pApplet.println("to ", x, y); | ||
old = current; | ||
current = new PVector(x * zoom, y * zoom); | ||
} | ||
} | ||
return points; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
|
||
class Callback { | ||
public: | ||
virtual ~Callback() { std::cout << "Callback::Callback" << std::endl; } | ||
virtual void moveServos() { std::cout << "Callback::moveServos()" << std::endl; } | ||
virtual void toAngle(float x, float y) { std::cout << "Callback::toAngle(" << x << "," << y << ")" << std::endl; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "caller.h" | ||
|
||
// global variable... | ||
Caller* caller = new Caller(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
#include "callback.h" | ||
|
||
class Caller { | ||
private: | ||
Callback* _callback; | ||
public: | ||
Caller(): _callback(0) {} | ||
~Caller() { delCallback(); } | ||
void delCallback() { delete _callback; _callback = 0; } | ||
void setCallback(Callback* cb) { delCallback(); _callback = cb; } | ||
void moveServos() { if(_callback) { _callback->moveServos(); } } | ||
void toAngle(float x, float y) { if(_callback) { _callback->toAngle(x, y); } } | ||
}; |
Oops, something went wrong.