from machine import Pin, SPI
from random import random, seed
from ili9341 import Display, color565
from utime import sleep_us, ticks_cpu, ticks_us, ticks_diff
import mySetup
import math
import ili9341
oc_freq = 270000000
machine.freq(oc_freq)

display = mySetup.createMyDisplay()

### Downsample
pixelSize = 8;
         
class Vector2:
    """A two-dimensional vector with Cartesian coordinates."""

    def __init__(self, x, y):
        self.x, self.y = x, y

    def __str__(self):
        """Human-readable string representation of the vector."""
        return '{:g}i + {:g}j'.format(self.x, self.y)

    def __repr__(self):
        """Unambiguous string representation of the vector."""
        return repr((self.x, self.y))

    def dot(self, other):
        """The scalar (dot) product of self and other. Both must be vectors."""

        if not isinstance(other, Vector2D):
            raise TypeError('Can only take dot product of two Vector2D objects')
        return self.x * other.x + self.y * other.y
    # Alias the __matmul__ method to dot so we can use a @ b as well as a.dot(b).
    __matmul__ = dot

    def __sub__(self, other):
        """Vector subtraction."""
        return Vector2(self.x - other.x, self.y - other.y)

    def __add__(self, other):
        """Vector addition."""
        return Vector2(self.x + other.x, self.y + other.y)

    def __mul__(self, scalar):
        """Multiplication of a vector by a scalar."""

        if isinstance(scalar, int) or isinstance(scalar, float):
            return Vector2(self.x*scalar, self.y*scalar)
        raise NotImplementedError('Can only multiply Vector2D by a scalar')

    def __rmul__(self, scalar):
        """Reflected multiplication so vector * scalar also works."""
        return self.__mul__(scalar)

    def __neg__(self):
        """Negation of the vector (invert through origin.)"""
        return Vector2(-self.x, -self.y)

    def __truediv__(self, scalar):
        """True division of the vector by a scalar."""
        return Vector2(self.x / scalar, self.y / scalar)

    def __mod__(self, scalar):
        """One way to implement modulus operation: for each component."""
        return Vector2(self.x % scalar, self.y % scalar)

    def __abs__(self):
        """Absolute value (magnitude) of the vector."""
        return math.sqrt(self.x**2 + self.y**2)

    def distance_to(self, other):
        """The distance between vectors self and other."""
        return abs(self - other)

    def to_polar(self):
        """Return the vector's components in polar coordinates."""
        return self.__abs__(), math.atan2(self.y, self.x)

sW = 320 * (1/pixelSize);
sH = 240 * (1/pixelSize);

for x in range(0,sW):
    for y in range(sH):
        uv=Vector2(x/sW,1.-y/sH)
        speed = .1;
        scale = 0.1 *(pixelSize/8);
        p = Vector2(x*scale,y*scale)
                
        for i in range(1,4):
            p.x+=0.3/i*math.sin(i*3.*p.y);
            p.y+=0.3/i*math.cos(i*3.*p.x);
        r=math.cos(p.x+p.y+1.)*.5+.5;
        g=math.sin(p.x+p.y+1.)*.5+.5;
        b=(math.sin(p.x+p.y)+math.cos(p.x+p.y))*.3+.5;
        w = h = pixelSize;
        c = ili9341.color565(int(r*255),int(g*255),int(b*255))
        display.fill_rectangle(x*w,y*h,w,h, c)


while True:
    pass

print("- bye -")
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT