๐Ÿ–Œ๏ธ์—ฐ์† ๊ทธ๋ฆฌ๊ธฐ

์ฝ”๋“œ๋ฅผ ์‹คํ–‰์‹œ์ผœ์„œ ์‹ค์ œ ๋™์ž‘์„ ํ™•์ธํ•˜์„ธ์š”.

1. ์„  ๊ทธ๋ฆฌ๊ธฐ

from helloai import *

win = Window('fun-programming')

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    # ์‹œ์ž‘์ 
    x = random(300)
    y = random(300)
    color = (random(256), 0, 0)
    
    win.line((0, 0), (x, y), color, 1)
    win.show()


if __name__ == '__main__':
    run()

from helloai import *

win = Window('fun-programming')

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    # ์‹œ์ž‘์ 
    x1 = random(win.width)
    y1 = random(win.height)
    
    # ๋์  
    x2 = random(win.width)
    y2 = random(win.height)
    
    win.line((x1, y1), (x2, y2), Color.RED, 2)
    win.show()


if __name__ == '__main__':
    run()

from helloai import *

win = Window('fun-programming')

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    # ์‹œ์ž‘์ 
    x1 = random(win.width)
    y1 = random(win.height)
    
    # ๋์  
    x2 = random(win.width)
    y2 = random(win.height)
    
    color = (random(246), random(246), random(246))
    win.line((x1, y1), (x2, y2), color, 1)
    win.show()


if __name__ == '__main__':
    run()

๋ ˆ์ด์ € ํšจ๊ณผ

from helloai import *

win = Window('fun-programming')

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    # ์‹œ์ž‘์ 
    x = random(300)
    y = random(300)
    color = (random(256), 0, 0)
    
    win.line((0, 0), (x, y), color, 1)
    win.show()


if __name__ == '__main__':
    run()

2. ์›๊ณผ ์‚ฌ๊ฐํ˜•

from helloai import *

win = Window('helloAI')


# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    x = random(win.width)
    y = random(win.height)
    color = (random(256), random(256), random(256))
    win.ellipse((x, y), 100, 100, fill=color)
    win.show()


if __name__ == '__main__':
    run()

from helloai import *

win = Window('helloAI')


# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    win.background((0,0,0))

    x = random(win.width)
    y = random(win.height)
    color = (random(256), random(256), random(256))
    win.ellipse((x, y), 100, 100, fill=color)
    win.show()


if __name__ == '__main__':
    run()

from helloai import *

win = Window('helloAI')

def setup():
    win.background((0,0,0))

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    size = 100
    x0 = random(win.width)
    y0 = random(win.height)
    x1 = x0 + size
    y1 = y0 + size
    color = (random(256), random(256), random(256))
    win.rectangle((x0, y0), (x1, y1), fill=color)
    win.show()


if __name__ == '__main__':
    run()

๋žœ๋ค์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ

from helloai import *

win = Window('helloAI')
x_val = 0


# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    global x_val
   
    win.ellipse((x_val, win.height/2), 100, 100, (255, 215, 0))
    x_val = x_val + 5    #    5ํ”ฝ์…€์”ฉ ์ฆ๊ฐ€์‹œํ‚ด
    win.show()


if __name__ == '__main__':
    run()

from helloai import *

win = Window('helloAI')
x_val = 0


# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    global x_val
   
    win.background((0, 0, 0))
    win.ellipse((x_val, win.height/2), 100, 100, (255, 215, 0))
    x_val = x_val + 5
    win.show()


if __name__ == '__main__':
    run()

3. ๋ฒฝ์— ๋‹ฟ์œผ๋ฉด ํŠ•๊ธฐ๊ธฐ

from helloai import *

win = Window('helloAI')
x_val = 0
y_val = 0
x_delta = 5
y_delta = 5

color = (255, 215, 0)

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    global x_val, y_val, color 
    global x_delta, y_delta
    
    win.background((0, 0, 0))
        
    win.ellipse((x_val, y_val), 100, 100, color)
    x_val = x_val + x_delta
    y_val = y_val + y_delta

    # ์ฐฝ์„ ๋ฒ—์–ด๋‚˜๋ฉด
    if x_val > win.width or x_val < 0:
        x_delta = x_delta * -1

    if y_val > win.height or y_val < 0:
        y_delta = y_delta * -1

    win.show()


if __name__ == '__main__':
    run()

4. ๋ฌด์ง€๊ฐœ ๋งŒ๋“ค๊ธฐ

from helloai import *

win = Window('helloAI')

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():

    thickness = random(5, 20)
    color = (random(256), random(256), random(256) )
    el_width = randrange(win.width - 50, win.width)

    # ์ฐฝ์˜ ์•„๋ž˜์ชฝ ๋ฒฝ๋ฉด์˜ ์ค‘๊ฐ„์ง€์ ์„ ์›์˜ ์ค‘์ ์œผ๋กœ ์žก๋Š”๋‹ค.
    win.ellipse((win.width/2, win.height),
                el_width,
                el_width,
                outline=color,
                thickness=10)
    win.show()


if __name__ == '__main__':
    run()

5. ๋ฐ”์ฝ”๋“œ ๋ชจ์–‘ ๋งŒ๋“ค๊ธฐ

from helloai import *

win = Window('helloAI')
x_val = 0

def setup():
    win.background((255, 255, 255))

# ๋ฌดํ•œ ๋ฐ˜๋ณต ์ฝ”๋“œ 
def loop():
    global x_val
    
    barcode_line()
    
    x_val += 2
    if x_val > win.width:
        x_val = 0
        
    win.show()


def barcode_line():
    global x_val
    if (random(100) > 50):
        color = Color.BLACK
    else:
        color = Color.WHITE  

    win.line((x_val, 100), (x_val, 300), color=color, thickness=2)

if __name__ == '__main__':
    run()

6. ์Šคํƒ€ํ•„๋“œ (๋ณ„๋“ค์˜...)

from helloai import *

x = []
y = []
speed = []

win = Window('helloai', (500, 400))
win.background(Color.BLACK)

def setup():
    win.background((0, 0, 0))
    for i in range(100):
        x.append(random_range(0, win.width))
        y.append(random_range(0, win.height))
        speed.append(random_range(1, 5))
    


def loop():
    win.background(Color.BLACK)

    for i in range(100):
        co = int(map(speed[i], 1, 5, 100, 255))
        color = (co, co, co)

        win.ellipse((x[i], y[i]), int(speed[i]), int(speed[i]), fill=color, outline=color)

        x[i] = x[i] - speed[i] / 2
        if x[i] < 0:
           x[i] = win.width
    win.show()


run()

7. sin ๊ณก์„ 

from helloai import *
import math 

win = Window('helloAI')
deg = 0

def loop():
    global deg
    
    #x์ถ• ๊ทธ๋ฆผ
    win.line((0, win.height/2), (win.width, win.height/2), Color.BLACK)
    
    y = math.sin(math.radians(deg))
    print(y)
    win.point(deg, y*win.height/2 + win.height/2)
    
    deg += 1
    if deg > win.width:
        deg = 0
        win.background(Color.BACKGROUND)
        
    win.show()
    
if __name__ == '__main__':
    run()

from helloai import *
import math 

win = Window('helloAI')

a = 0
x = 0
px = 0
py = 0

def loop():
    global a, x, px, py 
    
    y = remap(math.sin(a) * math.sin(a * 2) * math.sin( a * 1.7), (-1, 1), (50, win.height))
    win.line((px, py), (x, y))

    px = x
    py = y

    x = x + 1
    a = a + 0.03
    
    
    if x > win.width:
        x = px = py = 0
        win.background(Color.BACKGROUND)
        
    win.show()
    
    
if __name__ == '__main__':
    run()

Last updated