How do i draw an angular space with a quad?

I am trying to draw an angular space with using the quad command and trigonometry but cant figure it out. please need some urgent help

You’re going to have to give us more to go on than that. What is an “angular space”? Can you show us the code you have tried? Do you have a mock-up image of what sort of a result you want?

@TfGuy44 can you please help me with this? I am fairly new to this programming and struggling a lot

  1. http://Studio.ProcessingTogether.com/sp/pad/export/ro.9Nl$898UQxW3Q
  2. http://Studio.ProcessingTogether.com/sp/pad/export/ro.9D4K1FIWJ7Kxc
1 Like

I’m never going to see the death of that silly Car thing, am I? Can we at least make it’s rendering not awful?

void display() {
  for( int xx = -1; xx < 2; xx++){
  for( int yy = -1; yy < 2; yy++){
  pushMatrix();  
  translate(x, y);
  translate(xx*width,yy*height);
  rotate(z);
 
  noStroke();
  fill(#008000); 
  rect(-10, -10, 20, 20);
 
  stroke(0);
  noFill();
  triangle(-8, -8, 7, 0, -8, 8);
  popMatrix();
  }}
}

Anyway, you should start by having three variables that control the position (x,y) and angle of the spaceship. Give them good names.

Each time your program runs, so in setup(), pick random values for these variables. Or maybe try it with specific values. What would a good range for the X position be? Between 0 and… what? How about the angle? Between 0 and… what?

Then add three constants. These will control the size and shape of the spaceship. Look at the drawing to see what they do. You’ll have to give them better names, obviously, and also find values that look good by experimenting.

Then write a function, calcPoints(), which takes six inputs and produces six output variables. Where are you storing the outputs?

Then just draw four lines between those three points and the point (x,y) (or whatever you called the ship’s position). Heck, you could even fill in the ship with a color if you drew two triangle()s.

Anyway, here’s what I came up with:

void setup(){size(600,400);oooOO();stroke(255);ooo=oo();oooo=oo();O=O();OO=O()/2;OOO=
map(O(),100,200,PI/2,PI);}void draw(){background(o());line(o,oo,ooo,ooO);line(
ooo,ooO,Ooo,OoO);line(oOo,oOO,Ooo,OoO);line(oOo,oOO,o,oo);}int o(){OO();OOO();
return(0);}float o,oo,ooO,Ooo,OoO,oOo,oOO,O,OO,oooo,ooo,OOO;
float O(){return(random(100,200));}float oo(){return(random(
TWO_PI));}void oooOO(){o=random(width);oo=random(height);}
void OOO(){Ooo=o+O*cos(oooo+00);OoO=oo+O*sin(oooo-00);ooO=oo+OO*sin(oooo+OOO);}
void OO(){ooo=o+OO*cos(oooo+OOO);oOo=o+OO*cos(oooo-OOO);oOO=oo+OO*sin(oooo-OOO);}

// Code by TfGuy44. DO NOT STEAL.

Yes, okay, my constants aren’t constant. This shouldn’t be the biggest complaint you have about this code.

Thanks man, but I am just a very beginner level of programmer ,still most of the function looks unknown to me. can you please tell me how can i move an object by pressing the keys on the keyboard?

Sure. Here’s some example code that shows the best way to do it. It uses keyPressed() and keyReleased() to keep track in an array the states of the keys you care about.

float x, y;

int[] keys = { LEFT, RIGHT, UP, DOWN };
boolean[] key_states = new boolean[keys.length];


void setup(){
  size(600,400);
  x = 300;
  y = 200;
}

void draw(){
  background(0);
  movement();
  ellipse(x,y,10,10);
}

void movement(){
  if( key_states[0] ) x--;
  if( key_states[1] ) x++;
  if( key_states[2] ) y--;
  if( key_states[3] ) y++;
} 

void keyPressed(){
  key(true);
}

void keyReleased(){
 key(false);
}

void key(boolean b){
  for( int i = 0; i < keys.length; i++) if( keys[i] == keyCode ) key_states[i] = b;
}