plot the coordinates of the processing (python) list and specify the number of times in draw ()

This time as well, I made it with a lot of questions from my juniors, so I will write it with explanations.

things to do!

  1. Stack the specified amount of dishes!
  2. Draw a circle at the location of the coordinates in the list
  3. Place the car in a random position!

Completed program of 1.!

sketch.py


y = 600
count = 0

def setup():
    size(800,600)

def stack_plates(n):
    global y,count
    if count <= n:                #Ends when count exceeds the specified n
        ellipse(width/2,y,100,10) #Draw a plate
    y -= 5                        #Shift the coordinates to draw the plate
    count += 1                    #Increase the value after each process!

def draw():
    stack_plates(10)

Be conscious!

  1. It is necessary to shift the coordinates of the plate each time the plate is placed.
  2. Make a wall because it will last forever in draw ()

2. Completed program!

sketch.py


def setup():
    size(800,600)
    x = [200,300,550]
    y = [100,400,300]
    d = [50,180,100]
    for i in range( len(x) ):        #len()Move with the length in x
        ellipse(x[i],y[i],d[i],d[i])

Be conscious!

  1. Make sure that the values to be entered in x, y, d are the same!
  2. Move for with len ()!

3. Completed program!

sketch.py


def setup():
    size(800,600)
    pic = int(random(10)) #The number of cars to put!
    for i in range(pic):
        x = random(800)   #Car x coordinate
        y = random(600)   #Car y coordinate
        sketch_car(x,y)   #X in function,Give the coordinates of y!
    
def sketch_car(x,y):      #A function to draw a car!
    fill(128,249,251)
    rect(x,y,50,25)
    fill(244,201,70)
    rect(x-25,y+25,100,25)
    fill(60,63,55)
    ellipse(x,y+50,25,25)
    ellipse(x+50,y+50,25,25)

Be conscious!

  1. Have a function to draw a car!
  2. Prepare x and y arguments for each function of the car!
  3. Determine the coordinates to write the car with the random function!
  4. If you want to make the number of cars random, change the number of times to turn for at random!

There are less explanations than last time, but I intended to write it so that it can be read by looking at the program while looking at the contents of consciousness! If you can't do it without knowing it, I think it's worth seeing!

Recommended Posts

plot the coordinates of the processing (python) list and specify the number of times in draw ()
Get the number of specific elements in a python list
Check the processing time and the number of calls for each process in python (cProfile)
Count the number of Thai and Arabic characters well in Python
Receive a list of the results of parallel processing in Python with starmap
Output the number of CPU cores in Python
[Python] Sort the list of pathlib.Path in natural sort
View the result of geometry processing in Python
Make a copy of the list in Python
Divides the character string by the specified number of characters. In Ruby and Python.
Full-width and half-width processing of CSV data in Python
How to get the number of digits in Python
[python] Get the list of classes defined in the module
Carefully understand the exponential distribution and draw in Python
Plot and understand the multivariate normal distribution in Python
Carefully understand the Poisson distribution and draw in Python
Get the size (number of elements) of UnionFind in Python
[Python] Outputs all combinations of elements in the list
Summary of date processing in Python (datetime and dateutil)
How to identify the element with the smallest number of characters in a Python list?
[Machine learning] "Abnormality detection and change detection" Let's draw the figure of Chapter 1 in Python.
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
How to count the number of occurrences of each element in the list in Python with weight
Sort and output the elements in the list as elements and multiples in Python.
Python --Find out number of groups in the regex expression
[python] plot the values ​​before and after the conversion of yeojohnson conversion
[Homology] Count the number of holes in data with Python
Get the number of occurrences for each element in the list
[Tips] Problems and solutions in the development of python + kivy
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
The story of Python and the story of NaN
Difference between list () and [] in Python
About the basics list of Python basics
Specify the encoding of the unicode string in the Python 2.x print statement
[Python] Let's reduce the number of elements in the result in set operations
A function that measures the processing time of a method in python
[python] Get the rank of the values in List in ascending / descending order
List of Linear Programming (LP) solvers and modelers available in Python
Get the title and delivery date of Yahoo! News in Python
Get the number of readers of a treatise on Mendeley in Python
[Python] How to specify the window display position and size of matplotlib
Check the behavior of destructor in Python
Graph of the history of the number of layers of deep learning and the change in accuracy
Count the number of times two values appear in a Python 3 iterator type element at the same time
Display a list of alphabets in Python 3
Generate a list packed with the number of days in the current month.
OR the List in Python (zip function)
Comparing the basic grammar of Python and Go in an easy-to-understand manner
python> array> Determine the number and initialize> mylist = [idx for idx in range (10)] / mylist = [0 for idx in range (10)] >> mylist = [0] * 10
Change the saturation and brightness of color specifications like # ff000 in python 2.5
[Python] How to put any number of standard inputs in a list
Check the in-memory bytes of a floating point number float in Python
[Python] Calculate the number of digits required when filling in 0s [Note]
Difference between append and + = in Python list
The result of installing python in Anaconda
The basics of running NoxPlayer in Python
Open an Excel file in Python and color the map of Japan
Get the number of articles accessed and likes with Qiita API + Python
Summary of built-in methods in Python list
[Completed version] Try to find out the number of residents in the town from the address list with Python
In search of the fastest FizzBuzz in Python