bezier.py

Created by pikube

Created on October 26, 2019

870 Bytes

Trace une courbe de Bézier quadratique avec des valeurs aléatoires. Essayez render().


from math import *
from cmath import *
import kandinsky as k
import random as ran
dark=k.color(0,0,0)
red=k.color(255,0,0)
def setpoint(x,y):
  for cx in range(7):
    k.set_pixel((x-3+cx),y,dark)
  for cy in range(7):
    k.set_pixel(x,y-3+cy,dark)
def color(x,y):
  k.set_pixel(x,y,red)
def render():
  p1_x=ran.randrange(0,320)
  p1_y=ran.randrange(0,222)
  p2_x=ran.randrange(0,320)
  p2_y=ran.randrange(0,222)
  p3_x=ran.randrange(0,320)
  p3_y=ran.randrange(0,222)
  setpoint(p1_x,p1_y)
  setpoint(p2_x,p2_y)
  setpoint(p3_x,p3_y)
  step=0
  while 1:
    t=(1/(2**step))
    for loop in range(1+2**step):
      k.set_pixel(int((1-loop*t)*((1-loop*t)*p1_x+(loop*t)*p2_x)+(loop*t)*((1-(loop*t))*p2_x+(loop*t)*p3_x)),int((1-(loop*t))*((1-(loop*t))*p1_y+(t*loop)*p2_y)+(t*loop)*((1-(t*loop))*p2_y+(loop*t)*p3_y)),k.color(0,int(loop*t*255),0))
    step+=1

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.