Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jython problem?

 
Garrett turner
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone, I have been working on this problem for school and I am stuck on how to finish a part of it. I was wondering if anyone could look at it and see what my problem is. I am using the addLine() function to draw several lines to form a tree and from there I want to generate 5 trees total using a for loop statement. I am getting stuck on how to make the for loop to solve this problem. Thank you for reading this post, and I appreciate any help that I receive.



def myHome():
canvas = getMediaPath("640X480.jpg")
canvasf = makePicture(canvas)
str = "This is my home."
addText(canvasf, 20,20,str, black)
addText(canvasf, 21,20,str, black)
addRect(canvasf, 299, 19, 301, 71)
addRectFilled(canvasf, 300, 20, 300, 70, cyan)
addRect(canvasf, 350, 90, 200, 150)
addRect(canvasf, 390, 120, 50, 50)
addRect(canvasf, 460, 120, 50, 50)
for x in range(40,240,50):
for y in range(90, 240):
addLine(canvasf, 40,70,40,230,makeColor(0,175,0))
addLine(canvasf, 20,90,40,120,makeColor(0,175,0))
addLine(canvasf, 20,130,40,160,makeColor(0,175,0))
addLine(canvasf, 40,120,60,90,makeColor(0,175,0))
addLine(canvasf, 40,160,60,130,makeColor(0,175,0))
writePictureTo(canvasf, r"E:\house.jpg")
explore(canvasf)


house.jpg
[Thumbnail for house.jpg]
 
Garrett turner
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I figured it out, sorry to make a thread for nothing. This is what I came up with.




def myHome():
canvas = getMediaPath("640X480.jpg")
canvasf = makePicture(canvas)
str = "This is my home."
addText(canvasf, 20,20,str, black)
addText(canvasf, 21,20,str, black)
addRect(canvasf, 299, 19, 301, 71)
addRectFilled(canvasf, 300, 20, 300, 70, cyan)
addRect(canvasf, 350, 90, 200, 150)
addRect(canvasf, 390, 120, 50, 50)
addRect(canvasf, 460, 120, 50, 50)
addLine(canvasf, 40,70,40,230,makeColor(0,175,0))
addLine(canvasf, 20,90,40,120,makeColor(0,175,0))
addLine(canvasf, 20,130,40,160,makeColor(0,175,0))
addLine(canvasf, 40,120,60,90,makeColor(0,175,0))
addLine(canvasf, 40,160,60,130,makeColor(0,175,0))
x = 60
for i in range(4):
addLine(canvasf, 30+x, 70, 30+x,230, makeColor(0,175,0))
addLine(canvasf, 10+x, 90, 30+x,120,makeColor(0,175,0))
addLine(canvasf, 10+x,130,30+x,160,makeColor(0,175,0))
addLine(canvasf, 30+x,120,50+x,90,makeColor(0,175,0))
addLine(canvasf, 30+x,160,50+x,130,makeColor(0,175,0))
x = x + 60
explore(canvasf)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic