Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

skript:arduinoradar

Dies ist eine alte Version des Dokuments!




Das Arduino Radar

Etwas zeichnen mit Processing

Einfache grafische Elemente mit Processing darstellen, ein Beispiel:

int tickRadius; //radius of the ticks
int handPos; //position of the hand in degree
//window origin in the upper left corner
int x_M; //window center in x-direction
int y_M; //window center in y-direction
 
 
void setup() {
  //window size in pixel
  size(700,500);
  tickRadius = 200;
  handPos = 0;
  x_M = width/2;
  y_M = height/2;
}
 
void draw() {
  drawBackground();
  drawCenter();
  drawTicks();
  handPos = drawHand(handPos);
}
 
void drawBackground() {
  // Using only one value with color()
  // generates a grayscale value.
  color c = color(65);  // Define 'c' with grayscale value
  background(c);  // 'c' as background color
}
 
void drawCenter() {
  color c = color(255, 204, 0);  // Define RGB color 'c'
  fill(c);  // Use color variable 'c' as fill color
  noStroke();  // Don't draw a stroke around shapes
  ellipse(x_M, y_M, 40, 40);  // Draw left circle
}
 
void drawTicks() {
  color c = color(255, 204, 0);  // Define RGB color 'c'
  stroke(c);
  for(int i = 0; i < 360; i+=4){
    // x = r * cos(phi), y = r * sin(phi)
    // use radian measure
    point(x_M + tickRadius * cos(PI/180*i), y_M + tickRadius * sin(PI/180*i));
  }
 
}
 
int drawHand(int handPos) {
  color c = color(255, 204, 0);  // Define RGB color 'c'
  stroke(c);
  // x = r * cos(phi), y = r * sin(phi)
  // use radian measure
  line(x_M, y_M, x_M + tickRadius * cos(PI/180*handPos), y_M + tickRadius * sin(PI/180*handPos));
  // update handPos by one degree
  handPos++;
  return handPos;
}
skript/arduinoradar.1470230727.txt.gz · Zuletzt geändert: 2016/08/03 15:25 von c.jaedicke