Lesson 06 - Rainbow Chain 🌈 彩虹链 🦄🦄¶
While-loop vs for-loop 循环语句 🎡¶
什么是 while 循环? 什么是 for 循环? 上面的结果分别是什么?
Initial Code¶
以下是你本节课的练习代码,请复制粘贴到你的编辑器上,应用刚才学到的循环语句,绘制出目标图案。
import pygame
# Initialize pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
SAND = (255, 255, 255)
# Game setup
# window size
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# window caption
pygame.display.set_caption("Chrome Dino Game")
# Create a Frame Rate object
clock = pygame.time.Clock()
# Game loop
running = True
while running:
screen.fill(SAND)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Ground
pygame.draw.rect(screen,(0,0,0),(0,500,800,5))
# Create a cube
pygame.draw.rect(screen, (0, 0, 255), (80, 400, 50, 100), 0)
pygame.display.flip()
clock.tick(30)
pygame.quit()
Rainbow Chain - color list 列表 / 数组¶
Target:¶
How to define a list in Python?¶
What is RGB colormode?¶
The RGB color model is an additive color model in which the red, green and blue primary colors of light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.
RGB 颜色模型是一种加色模型,其中光的红、绿、蓝三原色以各种方式相加,以再现各种颜色。该模型的名称来自三种加色原色(红、绿、蓝)的首字母。
Define a color using RGB values 🎨🫧¶
The red, green and blue use 8 bits each, which have integer values from 0 to 255. This makes 256256256=16777216 possible colors. 红色、绿色和蓝色各使用 8 位,其值为 0 到 255 之间的整数。这样就形成了 256256256=16777216 种可能的颜色。🌈🌈
Challenge: Rhythm Blocks 🎹🎶😎¶
Try to move the cubes!
尝试让方块动起来!