The image is a slug

at first

I wanted to make something different by slightly changing the existing one, so I made it based on the program I made in Lesson 7-7 of Chapter 7.

I wanted to use a lot of circles, so I summarized it with reference to P212 of "The easiest python introductory textbook".

com 最終.jpg


A little change or addition ...

Change part ①

qiita.py



balls = [
    Ball(900,200,-1,1,"lightcoral"),
    Ball(850,200,-1,1,"red"),
    Ball(800,200,-1,1,"darkred"),
    Ball(750,200,-1,1,"tomato"),
    Ball(700,200,-1,1,"yellow"),
    Ball(650,200,-1,1,"orange"),
    Ball(600,200,-1,1,"olive"),
    Ball(550,200,-1,1,"limegreen"),
    Ball(500,200,-1,1,"green"),
    Ball(450,200,-1,1,"aquamarine"),
    Ball(400,200,-1,1,"cyan"),
    Ball(350,200,-1,1,"steelblue"),
    Ball(300,200,-1,1,"midnightblue"),
    Ball(250,200,-1,1,"blue"),
    Ball(200,200,-1,1,"darkviolet"),
    Ball(150,200,-1,1,"violet"),
    Ball(100,200,-1,1,"magenta"),
    Ball(150,200,-1,1,"deeppink"),
    Ball(50,200,-1,1,"pink"),
    Ball(0,200,-1,1,"palevioletred")]

In this way, the dictionary is used to summarize the position of the circle and the direction of travel. For details, please refer to P206 to P212 of the easiest python introductory textbook, Fumiko Osawa [Author].


com 最終.gif


Change part ②

canvas.create_oval (self.x -20, self.y --20, self.x + 20, self.y + 20, fill = "white", width = 0) to canvas.create_oval (self.x, self.y) , self.x, self.y, fill = "white", width = 0).

qiita.py



canvas.create_oval(self.x  , self.y , self.x  , self.y  , fill="white" , width=0)

By doing this, we continue to make progress.


com 最終2.gif

Complete! !! !! Was it a slug feeling?


Source code

qiita.py



# coding:utf-8
import tkinter as tk

class Ball:
    def __init__(self, x, y, dx, dy, color):
        self.x = x
        self.y = y
        self.dx = dx
        self.dy = dy
        self.color = color



    def move(self,canvas):
         canvas.create_oval(self.x  , self.y , self.x , self.y , fill="white" , width=0)
         self.x = self.x + self.dx
         self.y = self.y + self.dy
         #Draw a circle at the next position
         canvas.create_oval(self.x - 20, self.y - 20, self.x + 20, self.y + 20, fill=self.color , width=0)
         if self.x >= canvas.winfo_width():
            self.dx = -1
         if self.x <= 0:
            self.dx = +1 
         if self.y >= canvas.winfo_height():
            self.dy = -1
         if self.y <= 0:
            self.dy = +1

balls = [
    Ball(900,200,-1,1,"lightcoral"),
    Ball(850,200,-1,1,"red"),
    Ball(800,200,-1,1,"darkred"),
    Ball(750,200,-1,1,"tomato"),
    Ball(700,200,-1,1,"yellow"),
    Ball(650,200,-1,1,"orange"),
    Ball(600,200,-1,1,"olive"),
    Ball(550,200,-1,1,"limegreen"),
    Ball(500,200,-1,1,"green"),
    Ball(450,200,-1,1,"aquamarine"),
    Ball(400,200,-1,1,"cyan"),
    Ball(350,200,-1,1,"steelblue"),
    Ball(300,200,-1,1,"midnightblue"),
    Ball(250,200,-1,1,"blue"),
    Ball(200,200,-1,1,"darkviolet"),
    Ball(150,200,-1,1,"violet"),
    Ball(100,200,-1,1,"magenta"),
    Ball(150,200,-1,1,"deeppink"),
    Ball(50,200,-1,1,"pink"),
    Ball(0,200,-1,1,"palevioletred")]

def loop():
  #move
  for b in balls:
      b.move(canvas)
      
  #again
  root.after(2,loop)
     
#Draw a window
root = tk.Tk()
root.geometry("800x600")

#Put Canvas
canvas = tk.Canvas(root, width =800, height =600, bg="white")
canvas.place(x=0 , y=0)

#Timer again
root.after(2, loop)

root.mainloop()


References

The easiest python introductory textbook, Fumiko Osawa [Author]

https://pythondatascience.plavox.info/matplotlib/色の名前


Impressions

This class was the first time I was involved in the program. It was fun to try this time, so I wanted to take this opportunity to make more.

com 最終3.gif

2020-07-05 (3).png

That's beautiful!

Recommended Posts

The image is a slug
Cut out A4 print in the image
[python] [meta] Is the type of python a type?
What is wheezy in the Docker Python image?
A program that searches for the same image
It's a Mac. What is the Linux command Linux?
What is a distribution?
What is a hacker?
Check if the string is a number in python
Created a fooling image for the caption generative model
Try loading the image in a separate thread (OpenCV-Python)
[Python] Mask the image into a circle using Pillow
Zip 4 Gbyte problem is a story of the past
Creating a list when the nomenclature is a fixed time
[Python] Make sure the received function is a user-defined function
What is the difference between a symbolic link and a hard link?
[python] Change the image file name to a serial number
Dot according to the image
What is the Linux kernel?
When reading an image with SimpleITK, there is a problem if there is Japanese in the path
Is this string a decimal?
Try a similar search for Image Search using the Python SDK [Search]
Remove the frame from the image
Image crawling summary performed at the speed of a second
Is this a system trade?
What is a decision tree?
Python list is not a list
Grayscale image is displayed as a color image in OpenCV / Python
I made a dot picture of the image of Irasutoya. (part1)
What is a Context Switch?
What is a super user?
Is there a bias in the numbers that appear in the Fibonacci numbers?
What is a system call
Convert the image data (png) at hand to a .pbm image
The image display function of iTerm is convenient for image processing.
[Definition] What is a framework?
What is the interface for ...
What is a callback function?
What is the Callback function?
What is a python map?
I wrote a script that splits the image in two
Is there a secret to the frequency of pi numbers?
A method of converting the style of an image while preserving the color
Python will fail if there is a space after the backslash
[Blender] Script to check if the selected one is a mesh
Play a sound in Python assuming that the keyboard is a piano keyboard
Do a search by image from the camera roll using Pythonista3
[Statistics] Grasp the image of the central limit theorem with a graph
How easy is it to synthesize a drug on the market?
On Linux, the time stamp of a file is a little past.
Anyway, the fastest serial communication log is left in a file
Delete a particular character in Python if it is the last
[Profile] Identify where the program is taking a long time (google-perftool)
Try to edit a new image using the trained StyleGAN2 model
[Go] Create a CLI command to change the extension of the image
Is the new corona really a threat? Validated with Stan (was)
Try playing with a baseball simulator # 1 Is the feed bunt effective?
I tried to cut out a still image from the video
The road to web application development is a long way off
[Golang] Check if a specific character string is included in the character string
i! i! ← This is a mathematical formula