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 9150895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:40:22+00:00 2026-06-17T11:40:22+00:00

I’m writing a code in Jython, that will copy part of one picture into

  • 0

I’m writing a code in Jython, that will copy part of one picture into an empty picture, but I want it to copy (let’s say) 10 pixels less with each next row. I don’t think I make sense, let me explain with an example. A picture 100 pixels by 100 pixels, the program will copy the first row (100pixels) of pixels into the new picture, but for second row of pixels I want it to copy only 90 pixels, then for the third row 80 pixels, and so on.

Here I have a code that will copy part of a picture, but it copies a square. So what should I add to make it do what I want. I’m guessing I’m supposed to do something with the for x in range but I don’t know what.

def copyPic():
  file=pickAFile()
  oldPic=makePicture(file)
  newPic=makeEmptyPicture(getWidth(oldPic),getHeight(oldPic))
  xstart=getWidth(oldPic)/2
  ystart=getHeight(oldPic)/2
    for y in range(ystart,getHeight(oldPic)):
       for x in range(xstart, (getWidth(oldPic))):
         oldPixel=getPixel(oldPic,x,y)
         colour=getColor(oldPixel)
         newPixel=getPixel(newPic,x,y)
         setColor(newPixel,colour)
  explore(newPic)
  • 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-17T11:40:23+00:00Added an answer on June 17, 2026 at 11:40 am

    Your code definitely looks like it will copy the bottom right 1/4 of the image… to make a triangle-shaped piece (or just a piece that has an angle if I understand your question properly) of that section you need to reduce the X maximum value each time through… something like:

    def copyPic():
      file=pickAFile()
      oldPic=makePicture(file)
      newPic=makeEmptyPicture(getWidth(oldPic),getHeight(oldPic))
      xstart=getWidth(oldPic)/2
      ystart=getHeight(oldPic)/2
    
      # The next line gets the max value x can be (width of pic)
      xmax = getWidth(oldPic)
    
        for y in range(ystart,getHeight(oldPic)):
    
           # Now loop from the middle (xstart) to the end (xmax)
           for x in range(xstart, xmax):
    
             oldPixel=getPixel(oldPic,x,y)
             colour=getColor(oldPixel)
             newPixel=getPixel(newPic,x,y)
             setColor(newPixel,colour)
    
           # Now the x-loop has finished for this line (this value of y)
           # so reduce xmax by 10 (or whatever value) ready for the next line
           xmax = xmax - 10
    
           # Then you should do some checking in your code to ensure
           # xmax is not < xstart... here is something crude that should work
           if xmax < xstart:
               xmax = xstart
    
      explore(newPic)
    

    Your code I think will take an image like this:

    +------------+
    |   1     2  |
    |            |
    |   3     4  |
    |            |
    +------------+
    

    and give this:

    +-----+
    |  4  |
    |     |
    +-----+
    

    because your X loop is always the same length

    By reducing x each time as shown, you should get something like this:

    +-----+
    |  4 /
    |  /
    +-
    

    This is not very well coded, and I could rewrite the whole thing… but if you are just learning python then at least the modifications I made to your code should work well with what you already have, and should be easy to follow. I hope that it helps, and feel free to ask for clarification if you need it.

    Cheers

    PS: I see you asked this twice – you shouldn’t ask the same question twice since it splits the answers, and makes it harder for people trying to find answers like this later on…

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.