Adding Radar sweep line to code.

edited January 2016 in Library Questions

I am building a weather radar based on Grook.nets code for an ultrasonic sensor, however, I am not using a ultrasonic sensor. I have modified the code in many ways... The radar currently can detect heavy rain/hail at about 40 mi. I would like to add a sweep line for effects on the screen. Could anyone help me out? I am attaching my code. Thank you.

int cx; 
int cy; 
int r = 200;
int x = new int[100];
int y = new int[100];

import processing.serial.*;
Serial port;
Serial port2;
String data = "";
String Radius = "";
String Theta = "";
int index = 0;
float distance = 9000;
float angle = 10;
float pi = 22.0/7;

PImage img;



void setup() {
  size(600, 600);
  cx = width/2;
  cy = height/2;
  size(1000, 800);
  background(100);
  ellipse(500, 500, 1000, 1000);
  line(500, 0, 500, 1000);
  line(0, 500, 1000, 500);
  line(500, 500, 1000, 0);
  line(500, 500, 1, 1);
  img = loadImage("MAP3.png");
  tint(255, 1);
}
{



  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('.');
}

void draw() {
  background (0);
  stroke(0, 200, 0); 
  float t = millis()/1500; 
  for (int i = 0; i < 100; i++) {
    x[i] =(int) (cx+r*cos(t - i*0.01)); 
    y[i] =(int) (cy+r*sin(t - i*0.01));
    stroke(0, 200 - i * 2, 0); 
    line(cx, cy, x[i], y[i]);
  }


  image(img, 0, 0);
}

void serialEvent(Serial port)
{

  data = port.readStringUntil('.');
  data = data.substring(0, data.length() - 1);  
  index = data.indexOf(",");
  Radius = data.substring(0, index);
  Theta = data.substring (index+1, data.length());

  translate(500, 500);
  point (1, 1);

  distance = float(Radius); 
  angle = float(Theta) /180 * pi; 
  fill(10, 600, 20);
  ellipse(distance * cos(angle), -1 * distance * sin(angle), 40, 20);

  fill(98, 245, 31);


  noStroke();
  fill(8, 3); 
  rect(1000, 1, width, 1010);

  fill(98, 800, 31);
}
`
Thanks for any help. Initial code written by Grook.net. Modified by Tim Herrman.

Here is a link to an image showing what I want to do.

http://www.bing.com/images/search?q=Radar+Sweep&view=detailv2&&id=22EB8F2D6B4A7022F64E3C9B07F1499647F2F8D1&selectedIndex=23&ccid=3s8XPcDD&simid=608046625551091599&thid=OIP.Mdecf173dc0c37904ea95e802d6180293o0&ajaxhist=0

Answers

  • edited January 2016 Answer ✓

    Please, format your code correctly, select entire code and hit "C" button above text area.

    Here's code of just simple radar sweep line:

    int cx; 
    int cy; 
    int r = 200;
    int x = new int[100];
    int y = new int[100];
    
    void setup() {
      size(600, 600);
      cx = width/2;
      cy = height/2;
    }
    void draw() {
      background (0);
      stroke(0,200,0); 
      float t = millis()/1500; 
      for(int i = 0; i < 100; i++){
         x[i] =(int) (cx+r*cos(t - i*0.01)); 
         y[i] =(int) (cy+r*sin(t - i*0.01));
         stroke(0, 200 - i * 2, 0); 
         line(cx, cy, x[i], y[i]);
      }
    }
    
  • Thank you for your prompt response. I am getting an error when running the new code. The error says cannot convert int to int(). Any help would be greatly appreciated and thank you again.

  • edited January 2016 Answer ✓

    The error says cannot convert int to int().

    @herrmant, that error message was mistyped. Correct message:
    "cannot convert from int[] to int"

    In order to fix it, declare fields x & y as arrays of int:

    final int[] x = new int[100];
    final int[] y = new int[100];
    
  • Ok, thank you for your help. The program now runs. However, would there be a a way to remove the previous sweeps as it makes the radar image unreadable where the sweep is. Again thank you and any additional help is appreciated.Screenshot (46)

  • edited January 2016

    Oh.. Sorry, I didn't think you gonna really use it. Change this linestroke(0, 200 - i * 2, 0); to stroke(0, 200, 0, 200 - i * 2); something like that, you can play with numbers to adjust everything. For example r means radius..

  • I think I got it, I used a different code form this link,

    https://forum.processing.org/two/discussion/11360/need-help-creating-a-sweep-line-for-radar-simulation

    And I changed the color and length and got this result-- Screenshot (48)

Sign In or Register to comment.