turtle-graphics

randomly positioned circle clicking game

馋奶兔 提交于 2019-12-11 17:56:03
问题 So I'm still very new to python and trying to learn through making small projects. The game I'm making is meant to test your mouse accuracy by creating a bunch of random circles which the player is meant to click in a given amount of time. At the end of the game, it should tell the player their score, and how many misclicks they had. I've been using turtle to try and do this, but I'm stuck: import turtle import random t = turtle.Pen() win = turtle.Screen() win.bgcolor("lightgreen") win.title(

Need help in printing fractal tree

家住魔仙堡 提交于 2019-12-11 16:59:19
问题 I need some help in printing fractal tree using JavaScript. I have written code which prints tree sequence according to the rules defined for the tree, but having some trouble to print the tree. Thanks for all the help. Here is the code: var sentence = "F"; var rules = []; rules[0] = { a: "F", b: "F[+F]F[-F]F" } setup(); function setup() { turtle(); for (i = 0; i < 2; i++){ generate(); } } function turtle(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext('2d

how to set a turtle to a turtle screen

老子叫甜甜 提交于 2019-12-11 15:27:27
问题 I have a game I am trying to make, but when I create my screen and my turtle, my turtle shows up on a different screen than the screen I made. If I were to run the code it would pop up with 2 different turtle screens A: the one I called screen, and B: the one that automatically pops up when you create a turtle without a screen. import turtle from turtle import * from turtle import Screen import tkinter from tkinter import * import time from time import sleep from random import randint import

TypeError running tic tac toe game

偶尔善良 提交于 2019-12-11 14:58:02
问题 I have a complete tic/tac/toe game. But there is literally one stupid issue. I have no idea what this error IS or how I am getting it. It says my "clicked" function is missing one parameter when called. Here is my code: import turtle import time import random pieces = ["_", "_", "_", "_", "_", "_", "_", "_", "_"] turn = "X" def drawgame(brd): # draw board turtle.setup(600, 600) turtle.bgcolor("silver") turtle.color("white") turtle.width(10) turtle.up() # Horizontal bars turtle.goto(-300, 100)

Need help making a Hilbert Curve using numbers in Python

こ雲淡風輕ζ 提交于 2019-12-11 14:46:20
问题 I want to make a function that will create a Hilbert Curve in python using numbers. The parameters for the function would be a number and that will tell the function how many times it should repeat. To make a Hilbert Curve you start with 'L', then that turns into '+RF-LFL-FR+', and then 'R' turns into '-LF+RFR+FL-' How should I do this? #Here is what I've made so far def hilbert(num): s = 'L' for i in range(num-1): s = s.replace('L','+RF-LFL-FR+') b = 'R' for i in range(num-1): b = b.replace(

How to bind a button in turtle?

守給你的承諾、 提交于 2019-12-11 13:11:26
问题 Note: I've already tried to find solutions from https://docs.python.org/3/ and other stack overflow questions, but I haven't been able to find it. What I'm looking for is quite simple. While using a code like this: import turtle s = turtle.Screen() def u(): t.forward(50) s.onkey(u(), "Up") s.listen() It simply runs the code u So first of all: Why does it not wait until I press "Up"? And second, how can I make it so that it does? 回答1: You need to do the onkey and listen calls outside the u

Set dot color based on where they are in Python turtle?

喜你入骨 提交于 2019-12-11 12:29:08
问题 from turtle import * from random import randint speed("fastest") pendown() goto(200, 0) goto(200, 200) goto(0, 200) goto(0,0) goto(200,200) area_size = 800 max_coord = area_size / 2 num_dots = 300 setup(area_size, area_size) for _ in range(num_dots): dots_pos_x = randint(-max_coord, max_coord) dots_pos_y = randint(-max_coord, max_coord) penup() goto(dots_pos_x, dots_pos_y) dot(4) pendown() hideturtle() done() This code draws a square with a line splitting it into two equal triangles. How can

Bouncing ball in a circle (Python Turtle)

落爺英雄遲暮 提交于 2019-12-11 11:55:14
问题 I am currently working on a circular billiards program using Turtle. My problem is that I can't figure out what angle or position I need to give Python once the ball has reached the sides of the circle in order to make it bounce. Here is the part of my program that needs to be fixed: while nbrebonds>=0: forward(1) if (distance(0,y)>rayon): #rayon means radius print(distance(0,y)) left(2*angleinitial) #I put this angle as a test but it doesn't work forward(1) nbrebonds+=(-1) 回答1: From what I

Why does my Python turtle shape size decrease when pressing 'shift'

…衆ロ難τιáo~ 提交于 2019-12-11 11:52:30
问题 I am trying to create a turtle in Python so I could increase/ decrease it's size by pressing +/- on keyboard import turtle turtle.setup(700,500) wn = turtle.Screen() testing_turtle = turtle.Turtle() size = 1 def dropsize(): global size if size>1: size-=1 print(size) # To show the value of size testing_turtle.shapesize(size) def addsize(): global size if size<20: # To ensure the size of turtle is between 1 to 20 size+=1 print(size) testing_turtle.shapesize(size) wn.onkey(addsize,'+') wn.onkey

Simpler way to make a square and rotated square in Python Turtle graphics

喜欢而已 提交于 2019-12-11 08:24:13
问题 I'm working in turtle graphics to recreate this pattern: This is probably a very basic question, but is there a simpler way for me to create that rotated square within a square shape? As it is, I just use one turtle to make a normal square, then slowly move a second turtle into position to draw the rotated part. Ex: import turtle alex = turtle.Turtle() tess = turtle.Turtle() for i in range(4): alex.fd(50) alex.lt(90) tess.pu() tess.fd(25) tess.rt(90) tess.fd(10) tess.rt(225) tess.pd() for i