3 Replies - 767 Views - Last Post: 09 February 2013 - 09:19 PM Rate Topic: -----

#1 splshmtn21  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 09-February 13

How do I draw dice with dots in Python?

Posted 09 February 2013 - 06:05 PM

Here is the website for my assignment and the guidelines I am supposed to follow.

http://lhs-sfusd-ca....l=1360456228666

Here is the code I have so far and I need to include the random function and draw dots on my dice. I'm not sure where to put in the random function and how to draw dots. I want to keep all my code except for the last section with the random integers because I'm not sure where to put in that part into my code. Help is much appreciated!

from nodebox.graphics import *
import random

class FlatDie:
    def __init__(self):
        self.roll()
    def roll(self):
        self.dots = 3
    def show(self,x,y):
        stroke(0)
        fill(0)
        rect(x,y,30,30)
        fill(1)
        text(str(self.dots),x+10,y+10)
     
def draw (canvas):
    if canvas.mouse.pressed or canvas.frame == 1:
        total = 0
        i = 0
        while i < 6:
            Zac = FlatDie()
            Zac.roll()
            Zac.show(i * 35,85)
            total = total + Zac.dots
            i+=1
        fill(0)
        text("Total roll: " + str(total),10,10)
 
canvas.size = 200,200
canvas.run(draw)

die1=random.randint(1,6)
die2=random.randint(1,6)
die3=random.randint(1,6)
die4=random.randint(1,6)
die5=random.randint(1,6)
die6=random.randint(1,6)
total=int(die1+die2+die3+die4+die5+die6)


This post has been edited by macosxnerd101: 09 February 2013 - 06:21 PM
Reason for edit:: The code goes between the code tags: [code] Code goes here [/code]


Is This A Good Question/Topic? 0
  • +

Replies To: How do I draw dice with dots in Python?

#2 splshmtn21  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 09-February 13

Re: How do I draw dice with dots in Python?

Posted 09 February 2013 - 06:33 PM

Thanks for editing my code! I couldn't figure out how to get the indents in the right place cause I'm new here.

So does anyone know how to fix this program? :helpsmilie: :taz: :/
Was This Post Helpful? 0
  • +
  • -

#3 splshmtn21  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 09-February 13

Re: How do I draw dice with dots in Python?

Posted 09 February 2013 - 06:48 PM

I really need help and am behind on my assignments. My grade depends on it. :shuriken: :donatello: :no: :wacko:
Was This Post Helpful? -1
  • +
  • -

#4 witeboy724  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 29
  • Joined: 21-June 12

Re: How do I draw dice with dots in Python?

Posted 09 February 2013 - 09:19 PM

Well, I don't know anything about nodebox graphics. You need to put the random part in the def roll() section on line 8. Sense you're calling roll() 6 times, you just need one random line.
     def roll(self):
	        self.dots = random.randint(1,6)



Then get rid of the lines at the end. You were already keeping track of the total as you go, so you don't need that last line either. To draw the dots, you're going to have to tell python where the dots go and how big they are. Tell it that the 1 die has a dot centered, the 2 and 3 are diagonal, etc. Hope this helps a little.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1