grafico.py

Created by numworks-italia

Created on April 10, 2020

655 Bytes

Questo script permette di tracciare dei grafici di funzione. La funzione plotf(function,Xmin,Xmax,Ymin,Ymax) traccia la funzione come primo argomento del parametro definito da** Xmin, Xmax, Ymin et Ymax**. Provare per esempio plotf(sin,-10,10,-2,2). La funzione plotlist(list) traccia gli elementi della lista, posta come argomento, nell’ordine di un elemento per pixel sull’asse orizzontale e sull’ asse verticale adeguato ai valori contenuti nella lista. Provare per esempio plotlist(range(320)).


from kandinsky import *
from math import *
def plotf(function,Xmin,Xmax,Ymin,Ymax):
  red=color(255,0,0)
  black=color(0,0,0)
  for pixel_x in range(320):
    X=Xmin+pixel_x*(Xmax-Xmin)/319
    Y=function(X)
    pixel_y=int((Y-Ymax)*221/(Ymin-Ymax))
    set_pixel(pixel_x,pixel_y,red)
  for x in range(320):
    y_0=int(Ymax*221/(Ymax-Ymin))
    set_pixel(x,y_0,black)
  for y in range(222):
    x_0=int(Xmin*319/(Xmin-Xmax))
    set_pixel(x_0,y,black)
def plotlist(list):
  red=color(255,0,0)
  Ymin=min(list)
  Ymax=max(list)
  length=len(list)
  for i in range(length):
    j=int((list[i]-Ymax)*182/(Ymin-Ymax)+19)
    set_pixel(i,j,red)

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.