• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with code

 
Taiwo Sokunbi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Task : Write a GraphicsProgram subclass that draws a pyramid consisting of bricks arranged in horizontal rows, so that the number of bricks in each row decreases by one as you move up the pyramid.

But all I have been able to generate is right angled pyramid.
Below is the code I wrote.
Any help will be greatly appreciated.




 
Tony Docherty
Bartender
Posts: 2971
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to understand your code as I have no idea what the GCompound class is. Also please don't use all upper case letters for variables, they are only for constants ie those declared as final static.

If you are successfully generating a right angle triangle then your problem is when you draw the next row your offset is wrong. You need to offset each new rows start position by half the width of a single brick. This is because each row has one less brick than the row below it, so to centre a row relative to the previous one you need to take off half a brick width at each end .
 
Taiwo Sokunbi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion will try to do that.

The GCompound is part of acm package that belongs to GObject .
 
Taiwo Sokunbi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot it worked
@Tony
 
Tony Docherty
Bartender
Posts: 2971
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic