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

  • SEARCH
  • Home
  • 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 3441062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:30:24+00:00 2026-05-18T08:30:24+00:00

I am creating objects on a line in a window created by this piece

  • 0

I am creating objects on a line in a window created by this piece of code:

void createTurtles() {
     int nrTurtles = Keyboard.nextInt("Set amount of turtles: ");
     w = new GraphicsWindow(500, 300);
     drawLinez();
     for (int k = 1; k <= nrTurtles; k++) {
        Turtle t = new Turtle(w, 50, 50 + k*10);
        t.right(90);
        t.setSpeed(100);
        t.penDown();
        turtles.add(t);
     }
}

This codeline:

        Turtle t = new Turtle(w, 50, 50 + k*10);

Creates one turtle at the time. Right now i have set that the turtles will have the Y coordinat of 50, and the X coordinat of 50+k*10. This is because the line starts at the X coordinat of 50 and stops at the X coordinat of 250.

Now what i want is, based on the nr of turtles created (user inputs this), i want the turtles to be spread on this line evenly. How to do it? It has do to with the line that i wrote and maybe the k value or the 10.

The line is illustrated in the picture (see link below), its the red line, that the number of turtles are created at.

  • 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-05-18T08:30:24+00:00Added an answer on May 18, 2026 at 8:30 am

    Devide the height - 100 of the window by the number of turtles and you will have your distanceBetweenTurles:

    int nrTurtles = Keyboard.nextInt("Set amount of turtles: ");
    
    int height = 300;
    w = new GraphicsWindow(500, height);
    
    drawLinez();
    
    double distanceBetweenTurles = (height - 100.0) / nrTurtles;
    
    for (int k = 1; k <= nrTurtles; k++) {
        Turtle t = new Turtle(w, 50, 50 + (int) (k * distanceBetweenTurtles));
        t.right(90);
        t.setSpeed(100);
        t.penDown();
        turtles.add(t);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can this be done more elegant and without creating new objects? List<Move> playerMoves
nobody loved my first question about this: Creating Entity Framework objects with Unity for
Prior to C# generics, everyone would code collections for their business objects by creating
I'm just creating a ContextMenu.. At this line, I don't know what I shall
Possible Duplicate: What is the 'new' keyword in JavaScript? creating objects from JS closure:
What's the best framework for creating mock objects in Java? Why? What are the
I'm trying to send a post request to Parse: https://parse.com/docs/rest#objects-creating . Can't get it
I'm creating several visual objects in loop: ... Package packet; // a visual packet
I'm writing a program and I seem to be creating alot of objects where
Criteria, don't want creating copies of objects all over the place. Should be fast,

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.