fork download
  1. # -*- coding: cp949 -*-
  2. ##Modify this chapter’s case study program (the c-curve) so that it draws
  3. ##the line segments using random colors.
  4. """
  5. Program file: ccurve.py
  6. Author: Ken
  7. This program prompts the user for the level of
  8. a c-curve and draws a c-curve of that level.
  9. """
  10. from turtlegraphics import Turtle
  11. import random
  12.  
  13. def cCurve(turtle, x1, y1, x2, y2, level):
  14.  
  15. """Draws a c-curve of the given level."""
  16. def drawLine(x1, y1, x2, y2):
  17. """Draws a line segment between the endpoints."""
  18. turtle.setColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
  19. turtle.up()
  20. turtle.move(x1, y1)
  21. turtle.down()
  22. turtle.move(x2, y2)
  23. if level == 0:
  24. drawLine(x1, y1, x2, y2)
  25. else:
  26. xm = (x1 + x2 + y1 - y2) / 2
  27. ym = (x2 + y1 + y2 - x1) / 2
  28.  
  29. cCurve(turtle, x1, y1, xm, ym, level - 1)
  30.  
  31. cCurve(turtle, xm, ym, x2, y2, level - 1)
  32. def main():
  33. level = input("Enter the level (0 or greater): ")
  34. turtle = Turtle(400, 500)
  35. turtle.setWidth(1)
  36. cCurve(turtle, 50, -100, 50, 100, level)
  37.  
  38. main()
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
# -*- coding: cp949 -*-
^
Main.java:1: error: class, interface, or enum expected
# -*- coding: cp949 -*-
   ^
Main.java:2: error: illegal character: '#'
##Modify this chapter?s case study program (the c-curve) so that it draws
^
Main.java:2: error: illegal character: '#'
##Modify this chapter?s case study program (the c-curve) so that it draws
 ^
Main.java:2: error: illegal character: '\u2019'
##Modify this chapter?s case study program (the c-curve) so that it draws
                     ^
Main.java:3: error: illegal character: '#'
##the line segments using random colors.
^
Main.java:3: error: illegal character: '#'
##the line segments using random colors.
 ^
Main.java:4: error: unclosed string literal
"""
  ^
Main.java:9: error: unclosed string literal
"""
  ^
Main.java:10: error: '.' expected
from turtlegraphics import Turtle
                                 ^
Main.java:11: error: ';' expected
import random
      ^
Main.java:13: error: class, interface, or enum expected
def cCurve(turtle, x1, y1, x2, y2, level):
^
12 errors
stdout
Standard output is empty