villares / material-aulas

Material para ensino introdutório de programação com Python em um contexto visual
https://abav.lugaralgum.com/material-aulas/
97 stars 70 forks source link

Página sobre `lerp()` e `lerpColor() faltando! #47

Closed villares closed 4 years ago

villares commented 4 years ago

Precisa explicar... image

from __future__ import division # usando divisão do Python 3

def setup():
    size(500, 500)

def draw():
    background(200)
    noStroke()
    dots(width / 2, height / 2,
         mouseX , mouseY,
         color(255, 255, 0),
         color(0, 255, 255), 
         steps=20,
         dot_size=10)

def dots(x1, y1, x2, y2, ca, cb, steps=10, dot_size=10):
    L = dist(x1, y1, x2, y2)
    A = atan2(x1 - x2, y2 - y1)
    pushMatrix()
    translate(x1, y1)
    rotate(A)
    if L < steps * dot_size:
        steps = int(L / dot_size)
    for i in range(steps + 1):
        y = 0
        if steps > 0:
            p = i / steps
            y = lerp(0, L, p)
            cor = lerpColor(ca, cb, p) 
            fill(cor)
        rectMode(CENTER)
        rect(0, y, dot_size, dot_size)
    popMatrix()
villares commented 4 years ago

https://github.com/villares/material-aulas/blob/master/Processing-Python/map_lerp.md