Online Music Hackathon

First Prize: $5000

Ends on Jul 22:
00
Days
00
Hours
00
Mins
00
Secs
Posts
Python (with Turtle)
Python (with Turtle)
Rules for Posting - Read me!
Some rules and guidelines to keep in mind as you share your great work on our boards: 1 - Be kind and courteous to others 2 - Make sure that any feedback you provide is constructive. 3 - Outside links are allowed, but you must provide the source. Ideally, things that you post will have been created on Repl.it. 4 - Avoid posting overly promotional material - the focus is, and always will be, a programming, learning, and collaborative community. :) 5 - Don't spam! Keep things SFW (Safe For Work). We may revoke your access to these boards if you are found to be in violation of any of these rules. Feel free to ask clarifying questions. Last updated 7/10/18 12:09 PST
63
posted to Share by timmy_i_chen (934) 1 year ago
🚨THE THEME IS MUSIC🚨: WIN $5,000! We're having another competition!
### Friends, foes, loyal Replers, Boy do I have some news for y'all! On July 1st, we're kicking off another competition and the stakes are higher than ever. ![richrichrich](https://storage.googleapis.com/replit/images/1561408399112_514da1dfbb25d3bc66b26fb7e7430790.gif) **Types of programs accepted:** *Any.* **Theme:** MUSIC! **Rules:** As always, *must* be original content & MUST be created *and* hosted on Repl.it **Prizes:** $5,000, $2,500, and $1,000 **Dates:** July 1 @ 00:00 PST to July 21 @ 00:00 PST **Judge:** Tom Lehman, the CEO of Genius ## To submit, all you have to do is share your repl on [Challenge](https://repl.it/talk/challenge)! Check out [our FAQ](https://repl.it/talk/announcements/MUSIC-HACKATHON-FAQ/16359) if anything is unclear or you have any questions. And feel free to ask anything you need there, too!
150
posted to Challenge by katyadee (833) 25 days ago
🐶Introduce yourself! 🐶
Hi everyone! ![waving](https://storage.googleapis.com/replit/images/1561489787610_61c528ae0267ed2696f0c625ff66db6c.gif) Use this space to share anything you want to share with our community - your name, where you're from, what you program in, what brought you here... whatever you're comfortable with! Can't wait to get to know y'all. 💖 Katya
60
posted to Announcements by katyadee (833) 24 days ago
13
Visually Pleasing Music Writer (With Turtle Graphics)
Hello! This project was done independently. The programming language used was Python, with Turtle graphics utilized. My project draws a very simple measure of music for you. I will be sanding down some fine points of this project until the deadline if that's okay. If not, then I'm perfectly content with submitting this is my final submission! Please give me feedback for this project! This is my first time posting on repl.it :D
24
posted to Challenge by AbirHaque (13) 9 days ago
52
How To Create A Black Hole Spiral in Python W/ Turtle
Hello Programmers, This is a innovative and creative way of showing of your programming skills in Python with Turtle by creating this Spiral which later centres into a Black Hole. Step 1 - Import and Name your turtle Step 2 - Create a for - in range and mark anything more than 100 Step 3 - Go forward by 180 or more Step 4 - Go left by 70 or more Step 5 - Go forward by 60 or more Step 6 - Go right by 40 or more Step 7 - Pen up Step 8 - Set position 0,0 Step 9 - Pen down Step 10 - Go right by 2 or more Challenge: Add Colour to make it a Rainbow Spiral There you have it Ten Easy Steps to make a pretty fascinating Black Hole Spiral and impress other programmers.
48
posted to Share by nothplus (60) 9 months ago
43
How to draw Pixel Art on Python with Turtle!
# How to Draw Pixel Art on Python with Turtle! In this Tutorial you shall learn how to create your own pixel art on Python with Turtle, I hope you enjoy. The first step to creating our art is to import turtle and set a background. My personal tip is to use black as it works best with pixel art. Here is model code: ``` import turtle t=turtle.Turtle() wn=turtle.Screen() wn.bgcolor("Black") #Remember Speech Marks. ``` Then, for step 2, we will set the speed of your turtle to be a high value, using this command: ` t.speed(0) ` Then, now the technical aspects are over with, let us get into the real juicy code! First, we must define square. My optimum size after a lot of testing was a 20 by 20 square. You define a function using this piece of code: ``` def square(): for x in range(4): t.forward(20) t.right(90) #Remember Indentation. ``` Then, After that step, we can start making pixel art! To add colours to our squares, we use the begin_fill command. Let me show an example about how this works. ``` def Tetris_Piece_1(): for x in range(4): t.begin_fill() square() t.color("Blue") t.end_fill() t.color("Black") t.forward(20) ``` We created this function. Now we may uses it whenever we like with this command: ` Tetris_Piece_1(). ` This code will make a Horizontal line of 4 pixels, like the Tetris piece! Look at the example below to see Pac-Man also. You've come to the end of the Tutorial. However, if you would like to extend this, here are some ideas. Find a way to define Red_Square or Blue_Square. Make a video-game character. Create a model of a Tetris screen. It has lots of uses, so try it today. Remember to click on Python with Turtle and not python 2.7, Python or Django. I recommend you watch the example in larger screen by pressing Open in Repl.it. Special Credit to JSer for teaching me how to use markdown on this post! Up the pensize to 4 if you want it really blocky using this command! ` t.pensize(4) `
22
posted to Learn by John_WardWard (143) 9 months ago
8
Advanced Harmonograph
A harmonograph is an apparatus that uses pendulums to create a geometric image. A simple, so-called "lateral" harmonograph uses two pendulums to control the movement of a pen relative to a drawing surface. In this program, I made a harmonograph that creates a random balanced, geometrical, shape each time. Change some values and the colors for fun!
4
posted to Share by EchoCoding (243) 2 months ago
23
Colorful Circle Spiral Generator Using Python Turtle
Welcome to the python turtle circle pattern tutorial! In this tutorial you will learn how to make a colorful circle pattern creator with python using turtle! This patterns will look somewhat like this and the best part is that you can customize them! ![Screen Shot 2018-10-12 at 3.48.46 PM](https://storage.googleapis.com/replit/images/1539373814562_2b0b2e8bfd93e89ec57a4c6d39e0cc42.pn) First log on to your repl.it account and make a new python turtle code ![Screen Shot 2018-10-11 at 9.44.49 PM](https://storage.googleapis.com/replit/images/1539308815295_06a93f67ba00ca4869f5981583a9a8b3.pn) On your new repl.it first you are going to put in your imports. For this code you will need to import math, and obviously turtle. It should look like this now! ```python import turtle import math ``` We now want to set the background color! To do this you are going to type ```python turtle.Screen().bgcolor('black') #This sets the color to black but you can choose any background color! ``` Now you need to create 5 turtles for this code. I named mine Johny, Steve, Terry, Barry, ,Will, and Nich yours can be named anything you would like. Just make sure to use the same name every time. I also defined its speed and color! ```python Johny = turtle.Turtle() Johny.speed(0) Johny.color('white') #When the speed of the turtle is set to 0 then it will turn off the animation and it will go as fast as possible. I used the color white for my turtle but you can use any color you want it does not matter :). Do this 5 times for 5 different names and 5 different colors but keep the speed the same! ``` So far our code looks like this: ```python import turtle import math turtle.Screen().bgcolor('black') Johny = turtle.Turtle() Johny.speed(0) Johny.color('white') Steve = turtle.Turtle() Steve.speed(0) Steve.color('yellow') Barry = turtle.Turtle() Barry.speed(0) Barry.color('blue') Terry = turtle.Turtle() Terry.speed(0) Terry.color('orange') Will = turtle.Turtle() Will.speed(0) Will.color('pink') Nich = turtle.Turtle() Nich.speed(0) Nich.color('red') #When the speed of the turtle is set to 0 then it will turn off the animation and it will go as fast as possible ``` To make this colorful circle generator you would want a user input so that you can get a new pattern each time!. To do this use a input statement and then a statement to make sure your number is a integer. It will look like this ```python random = input("Enter a random number") random = int(random) ``` Now we will need to make a while true loop so that the pattern will keep drawing forever and this will look like this: ```python while True: ``` _Anything which is in this while true loop needs to be tabbed in!_ We are very close to finishing our code! Inside this while true loop you will need to put this code in ```python def drawCircles(t,size): for i in range(10): t.circle(size) size=size- minus+62 def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Johny ,100,10) ``` There are comments in the code to tell you what this code means. In this code the turtle Johny is drawing which means it will be the color white. Now you will want to put this code in for each turtle and you will be done! I recommend that for every size = size - minus + 62 line that you change the +62 to something else like -12 or *32 to get a very interesting pattern each time. Here is the final code. ```python import turtle import math turtle.Screen().bgcolor('black') Johny = turtle.Turtle() Johny.speed(0) Johny.color('white') Steve = turtle.Turtle() Steve.speed(0) Steve.color('yellow') Barry = turtle.Turtle() Barry.speed(0) Barry.color('blue') Terry = turtle.Turtle() Terry.speed(0) Terry.color('orange') Will = turtle.Turtle() Will.speed(0) Will.color('pink') Nich = turtle.Turtle() Nich.speed(0) Nich.color('red') minus = input("Give me a random number") minus = int(minus) print "Click on results now" while True: def drawCircles(t,size): for i in range(10): t.circle(size) size=size- minus+62 def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Johny,100,10) def drawCircles(t,size): for i in range(4): t.circle(size) size=size - minus -3 def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Steve,100,10) def drawCircles(t,size): for i in range(4): t.circle(size) size=size- minus def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Barry,100,10) def drawCircles(t,size): for i in range(4): t.circle(size) size=size- minus + 2 def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Terry,100,10) def drawCircles(t,size): for i in range(4): t.circle(size) size=size-minus*3 def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Will,100,10) def drawCircles(t,size): for i in range(4): t.circle(size) size=size-minus-45 def drawSpecial(t,size,repeat): for i in range (repeat): drawCircles(t,size) t.right(360/repeat) drawSpecial(Nich,100,10) ``` To run the code you first must press run button and then you have to go to console and type your random number. Your random number can be a negative number and if you make the number too big the code does not work. After you do that then you should be good to go into result and view your pattern. If you discovered a cool looking pattern put it down below in the comments! Here is are some cool patterns the generator made! ![Screen Shot 2018-10-12 at 3.49.37 PM](https://storage.googleapis.com/replit/images/1539373802126_aa9e1ced7f74cb7c611b9d79fc39c527.pn) ![Screen Shot 2018-10-12 at 3.49.15 PM](https://storage.googleapis.com/replit/images/1539373805966_2798667f8c3d949293c2851387f98b53.pn) ![Screen Shot 2018-10-12 at 3.48.46 PM](https://storage.googleapis.com/replit/images/1539373814562_2b0b2e8bfd93e89ec57a4c6d39e0cc42.pn) _Thanks to nothplus for the idea of making a tutorial for python turtle! Be sure to check his tutorial right here>>>https://repl.it/talk/challenge/How-To-Create-A-Black-Hole-Spiral-in-Python-W-Turtle/7423_ # **Stay Tuned For More! And make sure to smash that upvote button**
11
posted to Learn by IEATPYTHON (311) 9 months ago
3
Day 3 Birdhouse
A turtle drawing a birdhouse I'm extending this post with this sentence since the requirement is at least 50 words
1
posted to Share by nedf538 (2) 16 days ago
18
DRAW with python turtle!
I managed to program a basic drawing app using only the python turtle module! It was pretty fun to code. I attached some drawings I made ^-^ EDIT: WOW I'M IN THE NEWSLETTER!? I'm honoured! (https://replit-newsletter-16--timmy-i-chen.repl.co/?ref=newsletter) I'm working on a couple games, so watch out! (Although they probably won't be done soon, because it's GCSE year, ugh...) ![drawing program - flower](https://storage.googleapis.com/replit/images/1536865435321_bd598138637586247b2433a96371534d.pn) ![BETTER drawing program](https://storage.googleapis.com/replit/images/1536865448102_a542f76811f1df3d35a97ffd613c3e39.pn)
23
posted to Share by WiNDfaLLx (19) 10 months ago
12
How Thick would you like your shape?- AIs' Drawings
# My program This program makes use of python with turtle, and does certain things in response to the user. Shapes have a lot of customisation within this project. I originally was messing around with shapes on python with turtle, when I realised this would be a great project to make: If the computer received the instruction to draw a certain amount of sides: it would. This is a very interesting concept applied to a basic thing in life which is actually quite useful. You can also switch off the AI and manually choose the shapes properties, which is obviously slower. This is one of the key applications of AI in the most basic of circumstances. I hope you enjoy the project! Commands are all in the console! ## John_WardWard
5
posted to Share by John_WardWard (143) 6 months ago
18
How to create a fairly basic game using Python w/ Turtle Graphics
# How to make a simple game with Python + Turtle ___ Hello! If you're reading this, I can only assume you want to learn about **how to make a fairly basic game using Python with Turtle Graphics**. If that's not the case, why are you here? Go do something else. If you're still here, I'm going to assume you have some basic knowledge of Python (syntax, how to use variables, etc.) and some more in-depth of Turtle Graphics. If you don't, please at least read the first 4 chapters or so of [this](http://interactivepython.org/runestone/static/thinkcspy/index.html) resource. If you need to find more about turtle functions (which you likely will), see [these](https://docs.python.org/3.3/library/turtle.html?highlight=turtle) docs. I know this is long, but if you want to do this right, it's **VERY IMPORTANT** to read through each section!!! If you miss even one thing, your code may not work! ## I - Creating your repl & basic setup ___ OK, so the first thing you need to do is create a Python with Turtle Graphics Repl. If you already have an account, you can do this by clicking the big red plus button, click Search All Languages, searching for Python, and selecting Python (with Turtle). Alternatively, (and anyone can do it this way), you can just click on [this link](https://repl.it/languages/python_turtle)! Now, the next thing you should do is import the turtle graphics module. To import the turtle graphics module, include the following lines at the top of your code: ```python #Import statements import turtle ``` It's as simple as that! The first line a comment - it is very useful in keeping your code organized and readable. The second line is called an import statement, and it does just what it sounds like it does. ## II - Creating the window ___ Now that we have imported the turtle module, we can get started. To make a Python w/ Turtle repl work, we need to have something for the turtle to draw **on**. Now, technically this isn't necessary at this stage, it will be if you want to set a background color, and it will be for later things. To create a window, add a blank line, then the following code: ``` #Creating the window window = turtle.Screen() ``` If you would like to have a background color for the window, also include this line after the following lines: `window.bgcolor("#UVWXYZ")`, where UVWXYZ is the hexadecimal color code of the color you want for the background color. (To get a hex color code, just Google 'color code picker'.) The hex color code has to be surrounded in quotes because it is a string and must be read as such. So, just to recap, your code should now look like this (I have included my own hex color code, feel free to use it or choose your own): ```python #Import statements import turtle #Creating the window window = turtle.Screen() window.bgcolor("#444444") ``` Now comes the fun part - you can press the green 'Run' button and see something visibly happen! Up in the top left corner of the right side of your screen (under the section labeled 'result'), you should see the word "center". If you choose a background color, you should also see that area turn that color. If this worked, great! Continue to step 3. If not - double-check you have entered the code correctly. ## III - Creating the game box ___ ### Part 1 - Creating the turtle Now, we're going to draw the area that the game will be played in. This will also define the grid we're going to use for the game. For this example, I'm going to be using a box size of 500x500 (-250 to 250 on each axis), with a grid size of 50. To do this, we need to do a few things. First, in a new section (separated from the previous sections by an empty line), we need to create a turtle to use to create the box. So, we're going to create a comment detailing what this section of code does, then we're going to create our first turtle. Let's add the following lines of code: ```python #Initializing turtles outer = turtle.Turtle() ``` The second line, `outer = turtle.Turtle()`, creates a new turtle object and calls it `outer`. We will be doing a lot more of this later, so remember this. ___ ### Part 2 - Setting up the turtle Now, we're going to create our play area. First of all, let's make a new section. The first line we're going to do is set `outer`'s speed. To set the speed of a turtle, you use the function `turtle.speed(x)`, where turtle is the name of the turtle object you're using and x is a number from 0 to 10. Speed increases from 1 to 10, and 0 is the maximum speed - going as fast as python can handle. This is what we want to use, because it will keep the user from having to wait as long to start. So, to set the speed of `outer` to the fastest possible, we're going to use `outer.speed(0)`. Next, let's set a border color and fill color for the area. This uses the `turtle.color()` function, which takes up to 2 arguments (the things in the parenthesis). The first is the pen color, or the color that it will draw with. The second is the fill color, which is exactly what it sounds like - the color that is filled in when using fill. For this example, let's use #000000 (black) for the pen color and #FFFFFF (white) for the fill color. So, underneath the outer.speed, we're going to have the following line: `outer.color("#000000","#FFFFFF")`. ___ ### Part 3 - Drawing the area **DISCLAIMER:** From this point on, I won't be explaining in as much detail how each command works, though I will continue giving examples. Please see the docs if you want more info. The first thing to do when drawing the area of the game is to decide how big you want the area to be. In this example, I will be using **500x500**, but you can easily change that. Since your turtle's pen defaults to down, if you want to move it without drawing, you have to send `outer.up()`. Next, you need to go to the coordinates of whatever point you want to be one of the corners of your area - the easiest way to get this is to have your turtle go to (x,y), where x is half of the width of your area and y is half of the height. Since our area is 500x500, use `outer.goto(250,250)`. Next, do start being able to draw, we need to use `outer.down()`. To begin filling the play area, we need to add `outer.begin_fill()`, which will continue tracking the inner area of what you have drawn until you tell it to end the fill. Now, we're finally ready to start drawing. While you can do this with individual turns and forwards, it's much better to use a loop. To make a loop that loops 4 times that will draw us a square of side length 500, we need to use this code: ```python for i in range(4): outer.rt(90) outer.fd(500) ``` This will tell the turtle to make a 90-degree right turn, then go forward 500 pixels 4 times, creating a square. Finally, we need to end the fill by sending `outer.end_fill()`. If you press run now, you should get a full square drawn and filled in. If it doesn't work, check your code against this: ```python #Making the outer border of the game outer.speed(0) outer.color("#000000","#FFFFFF") outer.up() outer.goto(250,250) outer.down() outer.begin_fill() for z in range(4): outer.rt(90) outer.fd(500) outer.end_fill() ``` ## IV - Hiding turtles ___ When you press run, you'll see it the play area, but you'll also see the turtles - the little arrows pointing towards the right. Well, if we're making a game, we can't have that! Let's hide those turtles so that they aren't visible to the user. To do this, we need to make a new section - preferably as close to the top as possible, while still below the section where you initialized the turtles. To hide a turtle, you use `turtle.ht()`, where turtle is the name of the turtle. So, let's quickly make a section and hide the `outer` turtle. Now, if you run it, you won't see the little arrow after the drawing is finished! ## IV.V - Drawing a grid (Optional!) ___ Now, this whole section is **OPTIONAL**! You do **NOT** need to include this section, but I find it helpful especially when creating the game. Now that that's out of the way... ___ ### Part 1 - Creating an array To create a grid for the game, we need to do a few things. First, we need to keep track of each gridline's position. We can do that fairly easily with an **array**. This array should go in its own section, since we're going to be using more arrays later. The increments and decrements from 0 for each value in the array depend on how big you want each grid box to be - for this example, I'm going to use **50x50**. So, we're going to create an array - let's call it `gridpos` - by doing the following: `gridpos = []`. We now have an empty array. Now, to get the values for each grid position, we're going to go from the x position of the bottom left corner of your box - if you're using my numbers, it will be -250 - and add the side length of a grid square - in my case, 50 - to it. This is our first value. Continue until you reach the positive version of the first number. Mine looks like this: `gridpos = [-200, -150, -100, -50, 0, 50, 100, 150, 200]`. Now, we can start to draw it. ___ ### Part 2 - Drawing the grid We're going to need another turtle for the grid, so let's call it... wait for it... `grid`. We're going to want to hide this turtle, so in the hiding turtles section, let's add a line to hide it. Then, set its speed to 0 and its color to whatever you like - for this example, I used #888888. Then, we're going to need to make a loop, and have it loop for 1 fewer times than the number of grid squares you want for the height or the length. So, if you want a 10x10 grid, then it needs to loop 9 times. Inside that loop, we want it to do the following: Go to the leftmost edge of the box and draw a horizontal line for each value in `gridpos`, and go to the bottommost edge of the box and draw a vertical line for each value in `gridpos`. The easiest way to do this is with a large loop. You'll want to loop as many times as items you have in `gridpos` - in my case, 9 times. Let's break this down into 2 parts - **Horizontal Lines** and **Vertical Lines**. ___ #### Part 2A - Horizontal lines Since your turtle will be starting at (0,0), and we want it to draw a horizontal line at each y position in `gridpos`, we need to get it to go to each without drawing off the lines. We can do this by telling it to pick up the pen, then goto the far-left x value and the y value corresponding to the iterator's value in `gridpos`. This is a little hard to explain, so let me show it: ```python for p in range(9): grid.up() grid.goto(-250,gridpos[p]) ``` What this will do is go to (-250, the value of the p'th item in `gridpos`), whatever that may be. From there, it's as simple as putting the pen down and going forward the side length of the area, then turning left 90 degrees. So, your current code for the grid should look like this (Initializing of the grid turtle and gridpos array not shown): ```python #Making the grid grid.speed(0) grid.color("#888888") for p in range(9): grid.up() grid.goto(-250,gridpos[p]) grid.down() grid.fd(500) grid.lt(90) ``` ___ #### Part 2B - Vertical lines Now, it's time to make the vertical lines. Luckily, this part is much easier since we have the first part. All you need to do is copy/paste the code from `grid.up()` to `grid.fd(500)` to immediately below itself, switch -250 and gridpos[p] in the `grid.goto()` statement, and switch the left turn to a right turn. Now, you should have this inside the loop: ```python grid.up() grid.goto(-250,gridpos[p]) grid.down() grid.fd(500) grid.lt(90) grid.up() grid.goto(gridpos[p],-250) grid.down() grid.fd(500) grid.rt(90) ``` If you run it now, you should see it create a complete grid in your play area. ## V - Initializing the boxes ___ Now, the whole point of this game is to collect boxes - you can decide how many. In the example I used 7, but I only am going to detail 3 because it's a very simple, repetitive process to make more. First, we're going to need to create a turtle for each box. Let's go back up to the turtle initialization section, and create 3 turtles - `box1`, `box2`, and `box3` using `x = turtle.Turtle()` and hide them. Now, we probably want some margin between each box and the gridlines - for this example, I'm using a margin of 5 on each side. To make this easier, let's make 2 arrays - an `xlist` and a `ylist`. Each **x value** is going to be 5 **above** the 50 - so -45, 5, 55, 105, etc. Each **y value** is going to be 5 **below** the 50 - so -55, -5, 45, 95, etc. These arrays should go in the same section as the `gridpos` array, for organization's sake. We also need to declare a whole ton of variables - 4 for each box - which will be used later. For each box, we need `boxZx`, `boxZy`, `boxZgridx`, and `boxZgridy`, where Z is the number of each box. We can do that just below the array initialization section. So, to make it simple, for `box1` we can just use `box1x = box1y = box1gridx = box1gridy = 0`, so that each of those variables has been initialized but is equal to 0. This saves line space and some time. ## VI - Placing the boxes ___ This is the part where things start getting repetitive. Each section to place a box is almost exactly the same as the last. First, make a new section for `box1`. First, we want to set its speed to 0 so that it draws as fast as possible. Then, we're going to set its color - in this example, I'm using #8B4513, because it's a nice brownish color. Then, we're going to go up to pick up the pen and go to a set coordinate. For now, let's just go to the top right grid square. To do this, we need to tell `box1` to goto `xlist[9],ylist[9]`. Next, we're going to put down the pen and begin the fill. After that, we need to draw a square of side length 40, because our grid squares are side 50 and we have a margin of 5 on each side. This can be done with the same loop we used to draw the area, but instead of going forward 500 we go forward 40. Finally, we need to end the fill. If you run it now, you should see a brown box appear in the top right corner. That means it's worked! If it hasn't, see this code: ```python #Making the first box box1.speed(0) box1.color("#8B4513") box1.up() box1.goto(xlist[9],ylist[9]) box1.down() box1.begin_fill() for z in range(4): box1.fd(40) box1.rt(90) box1.end_fill() ``` Now, you just need to do the same thing for boxes 2 and 3, but with a different value in the xlist[] and ylist[]. See what experimenting with it does to the position! ## VII - Randomly placing the boxes ___ #### Part 1 - Basic randomization Now, I know what you're thinking. *"We already placed the boxes!"*, you'll say. *"Why do we need to do another section on placing boxes?!"* Well, you don't want to have it be the same position every single game, do you? That takes away some of the fun! Let's make a randomization aspect. First, up in the import section, we need to `import random`. This will let us use a very important function - `random.randint()`. Now, we need to create a new section above the drawing of box1 - let's do it directly below the grid section. This is where we're going to start using those variables we created. First, we need to assign `box1gridx`. So, we're going to use `box1gridx = random.randint(0,9)`. This will tell `box1gridx` to become a random integer between 0 and 9, so that it encompasses the whole of the array. Then, do the same for `box1gridy`. Now, we need to assign `box1x` to a number in `xlist[]` based on `box1gridx`, and the same for `box1y`. This is simple, based on what we know about arrays. Just use `box1x = xlist[box1gridx]`, and do the same for `box1y`. Now, just for debug purposes, let's print the x and y positions to the console using `print(box1x,box1y)`. Finally, we need to change the goto positions when drawing box1 from `xlist[9],ylist[9]` to `box1x,box1y`. If you did the randomization right, it should look like this: ```python #Getting coordinates for box1 box1gridx = random.randint(0,9) box1gridy = random.randint(0,9) box1x = xlist[box1gridx] box1y = ylist[box1gridy] print(box1x,box1y) ``` If you run it now, it should go to a completely different spot each time. ___ #### Part 2 - Specialized randomization Something you may see come up - very rarely, but it could happen - is multiple boxes in the same spot. Now, while this is technically OK, we don't want it because it limits the game's potential. So, for `box2`, we're going to use the same code as for `box1` (slightly modified to apply to `box2`), but we're going to add something to it. We need to check to see if `box2x` is the same as `box1x` and if `box2y` is the same as `box1y`. If they are the same, then we need to give `box2` a new position. We can do this by putting the whole of the randomization code for `box2` in a `while True:` loop (There are better ways to do this, but this is a simple way - you **do NOT** want to run this until you have put a `break` into it), then putting in an if statement. Since we need to check if `box2x` is `box1x` and `box2y` is `box1y`, `if (box2x == box1x and box2y == box1y):` should do the trick. Note that we need to check for both, because just one being the same is OK. Then, under that if it doesn't really matter what we put, so I just put a print statement saying that the placement of this box failed. What is very important is the else. We need to make sure we have an else after the if that contains the line `break`. Otherwise, we will be stuck in this loop forever. So, before running, double check that you have this code for `box2`'s randomization: ```python #Getting coordinates for box2 while True: box2gridx = random.randint(0,9) box2gridy = random.randint(0,9) box2x = xlist[box2gridx] box2y = ylist[box2gridy] print(box2x,box2y) if (box2x == box1x and box2y == box1y): print("Box 2 placement failed, retrying...") else: break ``` Finally, let's fix `box2`'s goto so that it goes to `box2x`, `box2y`. Now, to do this for more boxes it's very similar, but you need to check the position against every single previous box's position. So, for box3, you would need the conditional `(box3x == box1x and box3y == box1y) or (box3x == box2x and box3y == box2y)`. Fill in that randomization and its corresponding goto, and then press run. You should see all 3 boxes go to completely random spots each time! # VIII - Drawing the player ___ Now, it's time to draw our player. This will eventually be moving around on the grid and collecting the boxes, but for now let's just try and draw it. To make it simple and easily distinguishable from the boxes, we're going to choose a different color and shape. In this tutorial, I'm using a circle of diameter 40 and color #ABCDEF (a nice light blue.) To draw the circle, you *could* use `turtle.circle()`, but I'm going to use the more obscure `turtle.dot()`, which draws a dot based on the turtle's position as the center of the circle. Because of this, we need a new array called `playerposlist`. The values in this will be 25 away from each value in `gridpos`, because our grid boxes are 50x50. So, we'll start at -225, then -175, -125, etc. Next, we need to actually create our `player` turtle and hide it, both in their respective sections. Now, we need to create 2 variables to track `player`'s x position and y position in relation to the grid - `playerx` and `playery`. Let's set both of them to 4 for now. Since we're going to need to draw the character a LOT, let's put the drawing code into a function - `drawplayer()`. Since this will be called multiple times, we want our first line to clear any previous drawings using `player.clear()`. Then, set the speed to 0 and have the turtle pick up the pen. Now, we're going to `player.goto(playerposlist[playerx],playerposlist[playery])`. Finally, we need a dot of radius 20 and color #ABCDEF. We can do this with `player.dot(20,"#ABCDEF")`. It should now look like this: ```python player.clear() player.speed(0) player.up() player.goto(playerposlist[playerx],playerposlist[playery]) player.dot(20,"#ABCDEF") ``` Now, just put a call to drawplayer() below the drawplayer() function. If you press play, the boxes should draw and the player should go to the spot that is 4 up and 4 left from the bottom left corner. # IX - Boxcheck ___ Now, if our player has spawned on or moves onto a box, we want it to be collected and disappear. To do that, we're going to need to create a variable tracking the number of `boxes`. Since we have 3 boxes in this example, `boxes` should equal 3. Now, it's time to create a function for checking the boxes called `boxcheck`. The very first line needs to declare that we are using the global versions of `boxes` and of each box's grid coordinate variables (`boxZgridx`, `boxZgridy`). Then, we just need to repeat 5 lines of code for each box (replacing Z with the proper box number): ```python if playerx == boxZgridx and playery == boxZgridy: boxZ.clear() boxes -= 1 boxZgridx = boxZgridy = -1 ``` What this will do is check the player's position against the box's position, and if it's the same it will remove the box and decrement the number of boxes remaining, and then 'put' the box somewhere it can't be counted again. We need to put a call for `boxcheck()` in the beginning of the `drawplayer()` function. After you have this code block for each box, we just need to check `if boxes == 0`, and if it does, then we need to call a new function: # X - `win()` ___ Now, to make our win function, we need one more global variable - `haswon`. Declare it to be 0. Then, create a new turtle called `winner` and hide it. When the player wins, we're going to tell them they won and move their player out of bounds so they stop moving. So, now create the `win()` function. Inside this function, we need to access the global variables `haswon`, `playerx`, and `playery`. Then, we should print something to the console telling the player they have won - something like `"You won!!"`. Then, we need an if to check if the win() function has already run. We do this by checking `if haswon == 0`. Inside this if, we need to first set `haswon` to 1. This prevents it from running this section of the code again if `win()` is called again. Next, we need to set `winner`'s speed to 0 and have it pick up the pen. Then, we're going to draw our 'YOU WIN!' message. To do that, we're going to need an array called `winlist[]`. In it, we need to have one string for each character (we can ignore the leading or ending spaces). Since we want to say 'YOU WIN!', we need 8 strings, each with a character from that in it (so "Y", "O", "U", etc.). Then, we will need a loop that loops 8 times, and each iteration will draw one character. For my loop, I used o as the iterator. Now, let's create the code to draw each letter. We're going to have `winner` goto `xlist[o+1]` (because it's 8 characters on a 10 square grid) for the x position, and `xlist[5]` for the y position. Then, we need to draw each character using `winner.write()`. This function recieves 4 arguments - what to write (`winlist[o]`), whether or not to move (leave this on `False`), the alignment of the text (`align="left"`), and the font information (`font=("Arial",40,"Normal")`). So, the final write command should look like this: ``` winner.write(winlist[o], False, align="left", font=("Arial",40," ``` Finally, out of the loop, we need to set `playerx` and `playery` to 10 and redraw the player. Now, if you run this, if you won, you'd see that Y and W are not centered. The simple fix to this is to put the `winner.goto()` statement inside an else, and have 2 if statements before: one `if o == 0:`, and one `if o == 4:`. Inside the first, we're going to use `winner.goto(xlist[o+1]+2,xlist[5])`, and inside the second, we're going to use `winner.goto(xlist[o+1]-5,xlist[5])`. Now, if you run it and won, you'd see that the Y and W ARE centered. However, we should probably make it so that you can actually... play the game. # XI - User input ___ To get user input, we're going to need to create 4 basic functions. Each one will be very similar, except for a few number changes. The first is `up()`. This will need to declare the `global playery`. Then, you just have a simple if: `if playery < 9:`, which will check to make sure the player isn't at the top of the map. Inside the if, we just need to add one to `playery` and call `drawplayer()` again. The same will be done for all three other methods, with slight changes. `down()` will still `global playery`, but will instead check `if playery > 0 and playery < 10:`. This is because the player gets put at playerx and playery position (10,10) at the end of the game, and we want them to no longer be able to move. Inside the if, we're going to decrement instead of increment the `playery` value, and we're still going to `drawplayer()`. For `left()`, we need to `global playerx` instead of `playery`, and the if will reflect this change. In fact, `left()` is the same as `down()` except you have to replace each occurance of `playery` with `playerx` and the name is changed. The same can be done for `right()`, where you can just copy `up()` and replace every occurance with `playery` with `playerx` and change the name. After you have done this, you still need a way to intercept the user input. We need to add keylisteners for 8 keys: Up, Down, Left, Right, W, A, S, and D. This will be done using the `window.onkey()` function, which takes 2 parameters: the function to call, and the key to listen for. The latter has to be passed to the function as a string. So, we're going to have 8 different onkey statements. To save time explaining, I will just paste them here: ``` window.onkey(up, "Up") window.onkey(up, "W") window.onkey(down, "Down") window.onkey(down, "S") window.onkey(left, "Left") window.onkey(left, "A") window.onkey(right, "Right") window.onkey(right, "D") ``` This will call the appropriate function for each keypress. Finally, to make this work, we just need to add 2 lines to the bottom of the code: `window.listen()` and `windown.mainloop()`. # XII - Conclusion And with that, you should be done! If you press play, you should now have a functioning game. Now, if you want to, you can apply the principle learned in **X - `win()`** to add in an introduction to the game, like in my example, but that is not necesary. If you enjoyed this tutorial, be sure to upvote it. If you want to make a fairly simple random spiral generator with python, go [here](https://repl.it/talk/challenge/Python-Turtle-Graphics-Random-Spirals/7651). If you want to check out my crash course on LOLCODE, go and click on this cat head [(or here)](https://repl.it/talk/challenge/A-Crash-Course-in-LOLCODE/7714) [🐱](https://repl.it/talk/challenge/A-Crash-Course-in-LOLCODE/7714)
2
posted to Learn by minermaniac447 (170) 9 months ago
2
Hangman using turtle
I made another version of this but name it turtle racer on accident so I am reposting it.
1
posted to Share by Nich0las192 (2) 9 days ago
2
3D shape tester
Test 3D shapes and mess around... I have to type random stuff so this is fifty character long so I can submit this. s
1
posted to Share by Nich0las192 (2) 9 days ago
9
Python Turtle Game
### Information I've been working on this in my free time and it worked out surprisingly well for a game made with Turtle. I started on this when I saw [this post](https://repl.it/talk/learn/How-to-create-a-fairly-basic-game-using-Python-with-Turtle-Graphics/8182). I took the basic idea and added more stuff and a different system for moving. ### Rules The game is fairly simple, use the arrow keys to move your turtle icon around the screen and try to collect as many green boxes as you can without running into a red box. You are confined within the borders, so make sure not to trap yourself in between red boxes! ### Bugs Occasionally if you collect two green boxes at the same time it glitches out both one green box and one red box. I'm not sure how to fix this if anyone has any ideas let me know. Also, the green boxes will spawn inside the red ones just for an extra challenge. My current high score is 53. *Upvote if you like it*
3
posted to Share by evanzimmerman (20) 5 months ago
2
Arty shapes
This program allows you draw accurate shapes and cool intricate patterns.
1
posted to Share by Fahdkhan123 (1) 11 days ago
3
Efe's Avatar
This is my avatar
2
posted to Share by EfeVurkac (2) 1 month ago
11
Space Game
collect flying asteroids, 2 player game
10
posted to Share by mculaton (18) 1 year ago
2
super draw! dudududun
it is a drawing program. type l in the console lo make it move left. type r to make it go right. type f to make it go forward.
0
posted to Share by 2009k (2) 8 days ago
11
Forza Turtle
Just a simple game written in Python used to teach kids programming. I don't expect to win based on game play but it's a great game to teach with. It's a 2 player game. Left side player spams the "w" key, right side player spams the "up arrow" key to move their respective turtles. First one across the finish line wins. Forward distance and heading are randomized too.
6
posted to Share by TrevorBarron (23) 12 months ago
12
FlappyTurtleMovingMaze
In this 2 player game each player has to navigate their turtle thru the gap in each column by using the up/down or w/s keys as the column scrolls across. I didn't implement gravity (yet) but that's something that could be added. I could also add more columns and more gaps. This game is done using P3 and turtle. I had to do some clever tricks to get around the shortcomings of turtle. The columns are just fat pen lines. the gaps are just short fat pen lines rotated 90 deg. It was fun to figure out how to make the gap reverse itself to move up and down. Also doing the collision checking was fun to learn. You can adjust the x and y speed values to make the game more difficult. right now it's not super easy. Anyway please vote for this game because my wife has been yelling at me all day to get off the computer and mow the lawn. I could use the beer money! Tonite I added gravity effect and clipped the vertical limits of turtle travel. I'm impressed with what can be done using turtle here on repl.it
3
posted to Share by TrevorBarron (23) 12 months ago
answered
1
wow123
i want to create a code that will look cool can u help me out
10
posted to Ask by ThomasShankland (1) 3 months ago
5
Homework05(Title)
Homework05(Title)
2
posted to Share by Red_Bean_Ice (4) 4 months ago
12
Ping Pong game
a simple game made last year
2
posted to Share by DARKLORD6474 (11) 12 months ago
1
Pokemon Thing
Just do this. i guess it's decent. Lets give it a go. ![serveimage (1)](https://storage.googleapis.com/replit/images/1557438787037_c65d39bef508c106d6167f160ba36cee.jpe) ![serveimage](https://storage.googleapis.com/replit/images/1557438795918_f775da49f24debec125e15a932bd091c.jpe) ![serveimage](https://storage.googleapis.com/replit/images/1557438807410_31dfea172ad836c7e5c2e9fb87652043.pn)
9
posted to Share by ChristianDupont (3) 2 months ago
1
imdabest
This is for people who are not very good at life ![i_m_a_potato_by_h_swilliams_drff03-250t](https://storage.googleapis.com/replit/images/1562579165300_c81c6999c4bf36d067893e0028dc43c3.jpeg)
3
posted to Share by FaislJav (0) 12 days ago
7
Turtle Snake!
## Snake game in Python Turtle!! Press space to start. WASD or arrow keys to move. Touch the black dots to get points. Don't touch yourself or the walls. That's it. Please upvote and comment your best score! Mine is 17 :D
2
posted to Share by mat1 (2255) 10 months ago
7
Eating machine 2 Players
so basically player one is the orange guy and player two is the blue guy. both players autimatiaclly move on it's own. for player one use the arrow keys to move. for player two, use a and d. try to eat the balls of your own color. if you do, u get one point. if you don't, you lose a point. please comment. have fun!
2
posted to Share by DJWang (17) 10 months ago
5
Turtle
This thing uses turtle in interesting ways. Personally, my favorite is the circle, as without the instant feature it slowly grows to a mesmerizing, massive, rainbow circle. c = circle ![Screen Shot 2019-02-11 at 11.34.48 AM](https://storage.googleapis.com/replit/images/1549913699567_1757d604abff23f71db3cba333dec68a.pn) s = random shapes ![Screen Shot 2019-02-11 at 11.35.25 AM](https://storage.googleapis.com/replit/images/1549913736037_4e5a257f92956d2dfb6537ad03aa12fa.pn) sp = spiral (It's actually one spiral) settings: 3 for tightness ![Screen Shot 2019-02-11 at 11.33.11 AM](https://storage.googleapis.com/replit/images/1549913642960_4ff98bd6f23e7e9ab061a0aa936eaedd.pn) Hopefully you'll like it! - ebest
0
posted to Share by ebest (412) 5 months ago
6
Python With Turtle Loop Tutorial.
#Advanced Loops on Python with Turtle! In this tutorial, you shall learn about the wonders of loops on Python with Turtle. Let's delve into how you can use them! Just don't forget to start of with this code: ``` import turtle wn=turtle.Screen() wn.bgcolor("Red") #Change this to any color you would like. t=turtle.Turtle() t.speed(0) ``` ##Shapes! As shown in the example below, a square would be drawn like this. ``` for x in range(4): t.forward(70) #Forward may be any number. t.right(90) # Angle has to stay the same but you may use left or right. ``` If you would like to use a more advanced take on this , define it so you don't have to write it out again! You do this with this code: ``` def square(): for x in range(4): t.forward(70) t.right(90) ``` Defining a function makes it easier for us to create a "Stamp" for a shape. There is always an easy way to find out how to print a regular polygon. This means that regular shapes with** 3 sides or more ** will follow this pattern. Equilateral Triangle: 3 Sides, 120 degree turns on python w/Turtle. Square:4 sides,90 degree turn on python w/ Turtle. Regular Pentagon:5 sides . 72 degree turn on python w/Turtle. There is a pattern to this though. Let me show you. ######The Verdict: The interior angles of the triangle equal 180 degrees. The turtle however relies on exterior angles. Therefore, 180 divided by 3 =60 Then, the exterior angles of a shape equal 180-interior angle, which equals 120. The interior angles of a square= 360 360 divided by 4=90. 180-90=90. The same pattern occurs with pentagons. The rule is, as one more side is added, 180 degrees are added to the total of the interior angles. Therefore, a hexagon would be 60 degrees right, due to the fact that 720 (540+180) divided by 6=120. Then,180 minus 120=60 To challenge yourself, find the code for a decagon. ####Loops which don't repeat the same shape! In Python and Python with Turtle, there is a function in which we can vary the output of the loop by using: `for x in range():` You may be asking how, and I shall show you! Start by running the code in this link: https://repl.it/@John_WardWard/KindRigidCondition Did you see that? It was all a loop. Down below is code which perfectly demonstrates a cool loop in action. ``` for x in range(360): t.forward(5) t.right(x+180) ``` This works, because x represents the term. It is like the nth term in maths! The code works by going forward 5, and then going (Term)+180 degrees. It creates a cool spiral effect twice! My other code that I linked earlier went like this: ``` for x in range(360): t.forward(x+1) t.right(x+1) This means that is starts of as a reasonably small number, starting with 1 and going up to 361 (1 degrees, technically speaking)on both fronts. It makes a slowly inward spiralling pattern which expands. Please check the example below for some examples of loops. I hope you have enjoyed this tutorial! If you find any other cool loops, be sure to comment them down below and I'll take a look!
2
posted to Share by John_WardWard (143) 9 months ago