-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorful Mouse-Controlled Spiral Art.py
More file actions
50 lines (40 loc) · 1.1 KB
/
Colorful Mouse-Controlled Spiral Art.py
File metadata and controls
50 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import turtle
import math
import colorsys
# Setup layar
screen = turtle.Screen()
screen.bgcolor("black")
screen.title("Colorful Mouse-Controlled Spiral Art")
screen.tracer(0) # Nonaktifkan animasi agar lebih halus
# Konfigurasi turtle
tt = turtle.Turtle()
tt.hideturtle()
tt.speed(0)
tt.pensize(2)
screen.colormode(1.0)
# Fungsi untuk membuat warna pelangi (HSV ke RGB)
def rainbow(i, total):
hue = i / total
r, g, b = colorsys.hsv_to_rgb(hue, 1, 1)
return (r, g, b)
# Fungsi menggambar spiral dari titik mouse
def draw_spiral(x, y):
tt.penup()
tt.goto(x, y)
tt.pendown()
angle = 0
radius = 0
total = 100 # Jumlah langkah spiral
for i in range(total):
angle += 12
radius += 2
color = rainbow(i, total)
tt.pencolor(color)
new_x = x + math.cos(math.radians(angle)) * radius
new_y = y + math.sin(math.radians(angle)) * radius
tt.goto(new_x, new_y)
screen.update()
# Event: klik mouse untuk menggambar spiral
screen.onclick(draw_spiral)
screen.listen()
turtle.done()