Simple programming problem

edited December 2014 in Questions about Code

Hi,

I'm attempting to overlay an arrow on a point, and a having issues with the way the arrow aligns. If you run the code below you'll see that it's close, but not really precise. I've only achieved it through playing with the xy coordinates in the final placement of the character.

Does anyone know a better way of achieving this? Is there a unicode arrow that is already centrally aligned?

Many thanks.

import org.gicentre.utils.move.*;
char arrow = char(767);

ZoomPan zoomer; 

void setup(){
  size(400, 400);
  zoomer = new ZoomPan(this);
  textAlign(CENTER,CENTER);
}

void draw(){
  zoomer.transform();
  background(255);

  arrow(10.0,10.0, 0.0);
  arrow(11.0,10.0, 3.14/4);
  arrow(12.0,10.0, 3.14/2);
  arrow(13.0,10.0, 3*3.14/4);
  arrow(14.0,10.0, 3.14);
  arrow(15.0,10.0, -3.14/4);
  arrow(16.0,10.0, -3.14/2);
  arrow(17.0,10.0, -3*3.14/4);
  arrow(18.0,10.0, -3.14);
}

void arrow(Float x, Float y, Float heading){
  strokeWeight(4);
  stroke(255, 0, 0, 100);
  point(x*4, y);
  fill(0);
  pushMatrix();
    translate(x*4,y);
    rotate(heading);
    text(arrow, 2, -8);
  popMatrix();
}

Answers

  • What is the library you are importing?

  • The library is standard processing library from giCentreUtils: http://www.gicentre.net/. I just use it for zooming and panning.

  • The library is standard processing library...

    If we have to install it, it's not standard! And consequently this post is in the wrong section! [-(

  • edited December 2014 Answer ✓

    The problem is using the Unicode letter 767 for the arrow. When displaying a character (any character including the arrow) at a the position [x,y] the x position is the left hand side of the character and the y position is the baseline of the character. Lining up the arrow point with the position [x,y] is going to be a pain in the neck. See here for info about fonts.

    You might look at using PShape instead.

Sign In or Register to comment.