Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:23:14+00:00 2026-06-14T17:23:14+00:00

As a small homework to get into Processing, I had to write some code

  • 0

As a small homework to get into Processing, I had to write some code to get the following:
task

Using

public void setup() {
   size(300,200);
   noFill();
   rect(100, 20, 40, 80);
   ellipseMode(CENTER);
   fill(#000000);
   ellipse(width/2, height/2, 5,5);
   
   noFill();
   translate(width/2, height/2);
   rotate(radians(65));
   rect(-20, -40, 40, 80);
}
public void draw() {
}

this worked very good, so far. But I don’t like that I had to change the coordinates inside of the bottom rect instruction in order to get the rotation right. I know that by rotating you don’t rotate single elements but in fact the whole coordinate system.
What I don’t know is which values to put into the translate instruction to have the output be like in the picture above while also still using the same coordinates within the rect command.

The task is already done with the code I used, I just don’t like it too much. So this isn’t mere asking for somebody else doing my homework but pure interest.

EDIT: More generalised attempt of a question: How do I know which values to pit into translate before rotate to get whatever result I want? Is there a way to calculate them? For sure, it’s not just trying out, is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:23:15+00:00Added an answer on June 14, 2026 at 5:23 pm

    in my particular example, know how to translate and rotate to get the
    result in the picture without changing the rectangle coordinates?

    Well, you need to draw at origin to use rotate properly, so you are just dealing with the origin of the rect… As it is in your code, the default, the origin is the upper left corner, so you made an off set (from (0,0)) to draw it’s centre, not the corner, at coordinate(0,0), then rotate by the middle. Well done. It is not coincidence that the values you found was minus half rect width(-20) and minus half rect height(-40). If you change to rectMode(CENTER) than you can just draw at (0,0). The same applies to translate, you can just translate to the desired point, the center of the screen, where there is the ellipse. What is done using half width and half height…

    look:

    public void setup() {
      size(300, 200);
      smooth();
      ellipseMode(CENTER);
      rectMode(CENTER);
      noFill();
      // here converting the coordinates to work with CENTER mode
      //could have changed the rect mode just after this
      // but i kept as an illustration
      int rwidth = 40;
      int rheight = 80;
      int xpos = 100 + rwidth/2;
      int ypos = height/2 - rheight/2 ;
    
      rect(xpos, ypos, rwidth, rheight);
    
      fill(#000000);
      ellipse(width/2, height/2, 5, 5);
    
      noFill();
      pushMatrix();
    
      translate(width/2, height/2);
    
      //draw at origin gray
      stroke(150);
      rect(0, 0, 40, 80);
      // then rotate
      rotate(radians(65));
      // draw again black
      stroke(0);
      rect(0, 0, 40, 80);
    
      popMatrix();
    
    
      // here using the cordinates calculated before as a translate value 
      // we draw at origin, but it appears at same place
      stroke(230,230,100);
      // a bit to the left...
      translate(xpos-2, ypos-2);
    
      rect(0, 0, 40, 80);
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some issues with one small function I'm working on for a homework assignment.
Given the following algorithm on a dataset of size N: Separate the data into
I have a small homework application that writes random numbers from 5 to 77
I'm working on a small homework assignment and I'm supposed to make a food
For homework, I need to build a small java application.The main goal is to
2 small parts to this question which hopefully will clear up some ambiguity for
A small - little question. I have seen many application having buttons like following.
As the title says, I need to write a small program to read data
I am aware of SO question Failing to get element values using Element.getAttribute() but
I have in my homework some question about data structure: I have elements which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.