-2

i am supposed to draw a clock in python without using any modules that need downloading like turtle module, rather id have to use the stddraw module. The clock would also have to give the current time in hours, minutes, and seconds represented on the clock. I am struggling to understand how i'm supposed to go about doing this since i havent done any drawing or anything before so this is really new territory in terms of programming. Any ideas on how to go about doing this or advice is greatly appreciated!

ChaosPredictor
  • 3,777
  • 1
  • 36
  • 46
ssal
  • 95
  • 1
  • 1
  • 8
  • Advice: dont ask here, read the manuals to stddraw - look for tutorials. SO does not provide either. – Patrick Artner Oct 23 '18 at 19:38
  • 3
    Turtle module doesn't need downloading though, it's in STD. Oh also goodluck getting system time without libraries, I mean, you can just make win32 api call yourself, oh wait, you'll need ctypes for that... Are you sure you know what you're asking? If you mention stddraw then they probably told you to use that instead of say, turtle, because "don't use libraries that need downloading" means that you either shouldn't be allowed to use python at all, or that python STD is fine and turtle is part of it... – Purple Ice Oct 23 '18 at 21:24

1 Answers1

1

without using any modules that need downloading like turtle module, rather id have to use the stddraw module

As @PurpleIce starts to get at, you've got this backward. The turtle module comes with Python, the stddraw module needs to be downloaded (from Princeton.)

Your question has inspired me to see if it is possible to make a minimalist working clock using Python turtle:

from time import localtime
from turtle import *  # avoid wildcard imports like this

ATTRIBUTES = ['tm_hour', 'tm_min', 'tm_sec']

def tick():
    record = localtime()

    hands['tm_hour'].seth(record.tm_hour % 12 * 30 + record.tm_min / 2 + record.tm_sec / 120)
    hands['tm_min'].seth(record.tm_min * 6 + record.tm_sec / 10)
    hands['tm_sec'].seth(record.tm_sec * 6)

    ontimer(tick, 1000)

mode("logo")  # make 0 degrees be straight up the page

hands = {}
for size, attr in enumerate(ATTRIBUTES, start=1):
    hands[attr] = Turtle('triangle')
    hands[attr].shapesize(1 / size, size * 10)

tick()

mainloop()

Hopefully, this will give you insight on how to begin building your own clock using the stddraw module:

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81
  • 1
    Thanks, this is very nicely done, but im kind of a beginner, would you mind explaining why you had to use the commands such as getattr or putting the time parts into an array named attributes. Is this necessary? – ssal Oct 25 '18 at 15:21
  • @shehab, you're quite right, the `getattr()` stuff isn't necessary so I've removed it. This was an artifact of a more general solution I had in mind before I realized that hands were affected by multiple time units. The `ATTRIBUTES` array of time fields is still useful as it gives me a way to work with the hands both as a group of generic hands and individually as hands with unique requirements. – cdlane Oct 26 '18 at 22:38