Предмет: Информатика, автор: kirilloleinik2011

Складіть проєкт, у якому виконавець намалює відрізок завдовжки 70 кроків зеленим кольором, якщо натиснуто клавішу стрілка вправо, або намалює відрізок завдовжки 120 кроків синім кольором, якщо натиснуто клавішу стрілка вліво.

Ответы

Автор ответа: cevase
0

Ответ:

Ось приклад проєкту на мові Python, який малює відрізок залежно від клавіші, натиснутої користувачем:

import turtle

# Створюємо об'єкт вікна turtle і задаємо його властивості

win = turtle.Screen()

win.title("Малювання відрізків")

win.bgcolor("white")

# Створюємо об'єкт черепашки turtle і задаємо його властивості

t = turtle.Turtle()

t.color("green") # Початковий колір - зелений

t.pensize(5)

# Функція, яка малює відрізок

def draw_line(length, color):

t.color(color)

t.forward(length)

# Функція, яка зчитує вхідні дані та малює відрізок

def move_forward():

draw_line(70, "green")

def move_backward():

draw_line(120, "blue")

# Прив'язуємо функції до клавіш клавіатури

turtle.listen()

turtle.onkey(move_forward, "Right")

turtle.onkey(move_backward, "Left")

# Запускаємо головний цикл програми

turtle.mainloop()

Опис роботи програми:

Ми імпортуємо модуль turtle, який надає можливість малювати різні графічні об'єкти.

Ми створюємо вікно turtle за допомогою класу Screen і задаємо його властивості (назву та колір фону).

Ми створюємо об'єкт черепашки turtle за допомогою класу Turtle і задаємо його властивості (колір та товщину олівця).

Ми створюємо функцію draw_line, яка приймає два параметри: довжину відрізка та колір олівця. Функція малює відрізок заданої довжини та з заданим коліром.

Ми створюємо дві функції move_forward та move_backward, які будуть викликатись при натисканні відповідних клавіш клавіатури (стрілка вправо та стрілка вліво відповідно). Кожна з цих функцій викликає функцію draw_line зі своїми параметрами (70 та "green" для move_forward, 120 та "blue" для move_backward).

Ми прив'язуємо функції move_forward та move_backward до відповідних клавіш клавіатури за допомогою методу onkey.

Ми запускаємо головний цикл програми за допомогою методу mainloop, який очікує на взаємодію з користувачем (натискання клавіш клавіатури) та відображає малюнок на екрані.

Похожие вопросы
Предмет: Английский язык, автор: zlatakolisnyk


Discuss.
What kind of music do you like?
hip hop, jazz, classical dance, rock pop
heavy metal Latin traditional R&B
• Do you play a musical instrument?
• Who's your favourite singer? What's your favourite band?
2 Read
Track #7
A. Look at the pictures below. What kind of music do you think these teenagers like? Listen, read and check your answers
APRESICHERIGENS
Hi, I'm Carla and I'm from NYC, the
home of hip hop. I'm a rapper and
my stage name is C-block.
I started rapping at the age of six.
I'm a big fan of hip hop and I rap
everywhere, at school, on the bus
even in the shower. I don't want to
do anything else all day. The best time is
when I go to hip hop parties and perform with
DJs. It's out of this world!
Carla, New York City
MUSICAL
youth
I'm Darren and I play bass guitar in a band. We're into everything
from heavy metal to pop. Our band is called The Crash Monkeys
and we practise every day in Russell's garage. He's one of the
band members. I learnt the acoustic guitar at school and I'm
fond of classical guitar music, too. I compose most of the music
but I don't write the lyrics for our songs. Doing gigs with the
band is the biggest thrill, and next month we're going to a studio
to record some of our songs. We're very enthusiastic about it!
Darren, Manchester
KENINOVETADALAFERATA
My name's Sheila and my dream is to become a professional DJ when I grow
up. My dad's got a huge music collection and when I was young, I listened to his
records all the time. Today, I find most of them old school. I still enjoy listening to a
wide variety of music, but dance music with a strong beat is my favourite. Nobody
has a party at my school without me as the DJ because I know how to create the
right atmosphere, and get people dancing!
Sheila, Melbourne
B. Read again and write C for Carla, D for Darren or S for Sheila.
1. I practise in a lot of places.
2. I learnt a lot from one of my parents.
3. I am popular at parties.
4. I practise at a friend's house.
5. I changed my opinion about some kinds of music.
6. I love working with DJs.
7. I've studied music.
8. I'm doing some professional work next month.


помогите!! 50 очков отдаю!!
Предмет: Другие предметы, автор: alimzanovzamalbek
Предмет: Математика, автор: vanechka0408