Cover
 This is the archive Discourse for the Processing (ALPHA) software. Please visit the new Processing forum for current information.
 Processing 1.0 _ALPHA_    Programming Questions & Help    Programs (Moderators: fry, REAS)    moveTo for shape « Previous topic | Next topic »

 Pages: 1
 Author Topic: moveTo for shape  (Read 340 times)
kevinP

 moveTo for shape « on: Jun 7th, 2004, 2:21pm »

Hi all,

I am trying to draw some simple polygons using side lengths and angles (somewhat like turtle graphics do).

I thought that this is not much more than converting polar coords to Cartesian, but in my simplified example below I get a diamond (or rotated square) rather than a square parallel to my X/Y axes. The vertices are being calculated relative to the central starting point.

Code:
 void setup() {   size(300,300); }   // square int[] side = { 100, 100, 100, 100 }; // length of sides int[] dir  = { 0, -90, -180, -270 }; // direction in deg.   void draw() {   display(); }   void display() {   translate(width/2, height/2);   beginShape(POLYGON);   {     for(int i=0; i

Follow-up - using this and no beginShape() works fine:
line(0,0, cos(angle), sin(angle));
translate(cos(angle), sin(angle));

But I want to be able to draw a filled polygon (using side length and angle).
 « Last Edit: Jun 7th, 2004, 2:47pm by kevinP »

Kevin Pfeiffer
TomC

 Re: moveTo for shape « Reply #1 on: Jun 7th, 2004, 2:49pm »

You're only drawing one vertex per line.

line(x1,y1,x2,y2) is the equivalent of vertex(x1,y1) and vertex(x2,y2).

 « Last Edit: Jun 7th, 2004, 2:50pm by TomC »
kevinP

 Re: moveTo for shape « Reply #2 on: Jun 7th, 2004, 2:58pm »

I realized that I need to save my "current position" and then add that to each new X/Y calculation in order to get vertices relative to each other.

This works...
Code:
 void display() {   int xPos = 0;   int yPos = 0;       translate(width/2, height/2);   beginShape(LINE_LOOP);   {     vertex(xPos, yPos);     for(int i=0; i
 « Last Edit: Jun 7th, 2004, 3:13pm by kevinP »

Kevin Pfeiffer
TomC

 Re: moveTo for shape « Reply #3 on: Jun 7th, 2004, 3:01pm »

True.  On second thought I think that the problem is with calling translate inside beginShape/endShape.

Quote:
 Transformations such as translate(), rotate(), and scale() do not work within beginShape().

-- http://processing.org/reference/beginShape_.html
kevinP

 Re: moveTo for shape « Reply #4 on: Jun 7th, 2004, 3:14pm »

Yes, I see. Also sorry for stepping on your reply -- I updated my previous posting which threw your answer here out of context.

-K

Kevin Pfeiffer
 Pages: 1

 Forum Jump: ----------------------------- Discussion -----------------------------  - Community, Collaboration, Status   - Events, Publications, Propaganda   - General Processing Discussion ----------------------------- Programming Questions & Help -----------------------------  - Syntax => Programs   - Integration ----------------------------- Topics & Contributions -----------------------------  - Tools   - Responsive Form, Games   - Information Visualization   - Simulation, Artificial Life   - Tangible Computing   - Automated Systems   - Sound   - Video, Camera   - Beyond Categories ----------------------------- Suggestions -----------------------------  - Software Suggestions   - Website, Reference, Example Suggestions ----------------------------- Bugs -----------------------------  - Software Bugs   - Website, Reference, Example Bugs   - Bug Fixes, Implemented Suggestions ----------------------------- Teaching -----------------------------  - Course Blueprints   - Theory and Practice « Previous topic | Next topic »