Exemple #1
0
def make_yinyang(size=200, r=80, filename="yin_yang.png"):
    surface = gz.Surface(size, size, bg_color=(0, .3, .6))
    yin_yang = gz.Group([
        gz.arc(r, pi / 2, 3 * pi / 2, fill=(1, 1, 1)),
        gz.arc(r, -pi / 2, pi / 2, fill=(0, 0, 0)),
        gz.arc(r / 2, -pi / 2, pi / 2, fill=(1, 1, 1), xy=[0, -r / 2]),
        gz.arc(r / 2, pi / 2, 3 * pi / 2, fill=(0, 0, 0), xy=[0, r / 2]),
        gz.circle(r / 8, xy=[0, +r / 2], fill=(1, 1, 1)),
        gz.circle(r / 8, xy=[0, -r / 2], fill=(0, 0, 0))
    ])
    yin_yang.translate([size / 2, size / 2]).draw(surface)
    surface.write_to_png(filename)
    return 0
Exemple #2
0
def draw_server_arc(server_no, start, stop, c):
    # Start in the center and draw the circle
    # print("server_no", server_no)
    # print("ring_rad", ring_rad)
    # print("stop", stop)
    # print("start", start)
    # print("c", c)
    if c == "Pink":
        return False

    if type(c) == type(" "):
        #print("Name!!", c)

        red, green, blue = webcolors.name_to_rgb(c)
        red = red / 255.0
        green = green / 255.0
        blue = blue / 255.0
        c = (red, green, blue)
        #print(c)

    circle = g.arc(r=server_no * ring_rad + (0.5 + start_ring) * ring_rad,
                   xy=[w / 2, h / 2],
                   a1=stop - Pi / 2,
                   a2=start - Pi / 2,
                   stroke=c,
                   stroke_width=15)
    circle.draw(surface)
Exemple #3
0
def test_yin_yang():
    L = 200  # <- dimensions of the final picture
    surface = gz.Surface(L, L, bg_color=(0, .3, .6))  # blue background
    r = 70  # radius of the whole yin yang

    yin_yang = gz.Group([
        gz.arc(r, np.pi / 2, 3 * np.pi / 2, fill=(1, 1, 1)),  # white half
        gz.arc(r, -np.pi / 2, np.pi / 2, fill=(0, 0, 0)),  # black half
        gz.arc(r / 2, -np.pi / 2, np.pi / 2, fill=(1, 1, 1), xy=[0, -r / 2]),
        gz.arc(r / 2, np.pi / 2, 3 * np.pi / 2, fill=(0, 0, 0), xy=[0, r / 2]),
        gz.circle(r / 8, xy=[0, +r / 2], fill=(1, 1, 1)),  # white dot
        gz.circle(r / 8, xy=[0, -r / 2], fill=(0, 0, 0))
    ])  # black dot

    yin_yang.translate([L / 2, L / 2]).draw(surface)

    assert is_like_sample(surface, 'yin_yang')
Exemple #4
0
def test_yin_yang():
    L = 200  # <- dimensions of the final picture
    surface = gz.Surface(L, L, bg_color=(0, .3, .6))  # blue background
    r = 70  # radius of the whole yin yang

    yin_yang = gz.Group([
        gz.arc(r, np.pi / 2, 3 * np.pi / 2, fill=(1, 1, 1)),  # white half
        gz.arc(r, -np.pi / 2, np.pi / 2, fill=(0, 0, 0)),  # black half

        gz.arc(r / 2, -np.pi / 2, np.pi / 2, fill=(1, 1, 1), xy=[0, -r / 2]),
        gz.arc(r / 2, np.pi / 2, 3 * np.pi / 2, fill=(0, 0, 0), xy=[0, r / 2]),

        gz.circle(r / 8, xy=[0,  +r / 2], fill=(1, 1, 1)),  # white dot
        gz.circle(r / 8, xy=[0,  -r / 2], fill=(0, 0, 0))])  # black dot

    yin_yang.translate([L / 2, L / 2]).draw(surface)

    assert is_like_sample(surface, 'yin_yang')
Exemple #5
0
def draw_sun(server_no, hour, alpha):
    a = -Pi / 2 + (hour * ah)
    sw = ring_rad
    arc = g.arc(r=server_no * ring_rad - (ring_rad / 2) +
                (ring_rad * start_ring),
                xy=[w / 2, h / 2],
                a1=a,
                a2=a + ah,
                stroke=(1, 0.84, 0, alpha),
                stroke_width=sw)
    arc.draw(surface)
Exemple #6
0
def createHeart(stroke, stroke_width, fill=None):

    line = gz.polyline(points=points,
                       stroke_width=stroke_width,
                       stroke=stroke,
                       fill=red)
    arc1 = gz.arc(r=radius,
                  a1=ofstRadian,
                  a2=-ofstRadian,
                  stroke=stroke,
                  stroke_width=stroke_width,
                  xy=[A[0] - arcX, A[1] - arcY],
                  fill=red)
    arc2 = gz.arc(r=radius,
                  a1=ofstRadian,
                  a2=-ofstRadian,
                  stroke=stroke,
                  stroke_width=stroke_width,
                  xy=[C[0] - arcX, C[1] + arcY],
                  fill=red)

    return gz.Group([line, arc1, arc2])
Exemple #7
0
def make_frame(t, speed_list):

    surface = gizeh.Surface(W, H)
    max_speed = max(speed_list)
    c = 2 * np.pi / max_speed  # 係数

    arc = gizeh.arc(r=R, a1=np.pi, a2=2 * np.pi, xy=(W / 2, H), fill=(1, 1, 1))
    arc.draw(surface)

    for speed in speed_list:
        line = gizeh.polyline(points=[
            (W / 2, H), (W / 2, H) + (gizeh.polar2cart(R, np.pi + c * speed))
        ],
                              stroke_width=4,
                              stroke=(1, 0, 0),
                              fill=(0, 1, 0))
        line.draw(surface)
    return surface.get_npimage()
Exemple #8
0
import gizeh
import numpy as np
import pygame as pg

k = np.array((640, 360))
surf = gizeh.Surface(k[0], k[1])

ar = gizeh.arc(100, np.pi / 2, 0, xy=k / 2, fill=(1, 0, 0))
ar.draw(surf)

pg.init()
disp = pg.display.set_mode(k)
clk = pg.time.Clock()

surf2 = pg.surfarray.make_surface(
    np.transpose(surf.get_npimage(), axes=(1, 0, 2)))
r = True

while r:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            r = False
    disp.fill((255, 255, 255))
    disp.blit(surf2, (0, 0))
    pg.display.flip()
    clk.tick(60)
Exemple #9
0
"""
This generates a Yin Yang.
"""

import gizeh as gz
from math import pi

L = 200  # <- dimensions of the final picture
surface = gz.Surface(L, L, bg_color=(0, .3, .6))  # blue background
r = 70  # radius of the whole yin yang

yin_yang = gz.Group([
    gz.arc(r, pi / 2, 3 * pi / 2, fill=(1, 1, 1)),  # white half
    gz.arc(r, -pi / 2, pi / 2, fill=(0, 0, 0)),  # black half
    gz.arc(r / 2, -pi / 2, pi / 2, fill=(1, 1, 1),
           xy=[0, -r / 2]),  # white semihalf
    gz.arc(r / 2, pi / 2, 3 * pi / 2, fill=(0, 0, 0),
           xy=[0, r / 2]),  # black semihalf
    gz.circle(r / 8, xy=[0, +r / 2], fill=(1, 1, 1)),  # white dot
    gz.circle(r / 8, xy=[0, -r / 2], fill=(0, 0, 0))
])  # black dot

yin_yang.translate([L / 2, L / 2]).draw(surface)

surface.write_to_png("yin_yang.png")
Exemple #10
0
"""
This generates a Yin Yang.
"""

import gizeh as gz
from math import pi

L = 200 # <- dimensions of the final picture
surface = gz.Surface(L, L, bg_color=(0 ,.3, .6)) # blue background
r = 70 # radius of the whole yin yang

yin_yang = gz.Group([
     gz.arc(r, pi/2, 3*pi/2, fill = (1,1,1)), # white half
     gz.arc(r, -pi/2, pi/2, fill = (0,0,0)), # black half

     gz.arc(r/2, -pi/2, pi/2, fill = (1,1,1), xy = [0,-r/2]), # white semihalf
     gz.arc(r/2, pi/2, 3*pi/2, fill = (0,0,0), xy = [0, r/2]),  # black semihalf

     gz.circle(r/8, xy = [0,  +r/2], fill = (1,1,1)), # white dot
     gz.circle(r/8, xy = [0,  -r/2], fill = (0,0,0)) ]) # black dot

yin_yang.translate([L/2,L/2]).draw(surface)

surface.write_to_png("yin_yang.png")
Exemple #11
0
import numpy as np
import gizeh as gz
import moviepy.editor as mpy

W, H = 256, 256
R = 1.0 * W / 3
D = 4
yingyang = gz.Group([
    gz.arc(R, 0, np.pi, fill=(0, 0, 0)),
    gz.arc(R, -np.pi, 0, fill=(1, 1, 1)),
    gz.circle(R / 2, xy=(-R / 2, 0), fill=(0, 0, 0)),
    gz.circle(R / 2, xy=(R / 2, 0), fill=(1, 1, 1))
])

fractal = yingyang
for i in range(5):
    fractal = gz.Group([
        yingyang,
        fractal.rotate(np.pi).scale(0.25).translate([R / 2, 0]),
        fractal.scale(0.25).translate([-R / 2, 0]),
        gz.circle(0.26 * R, xy=(-R / 2, 0), stroke=(1, 1, 1), stroke_width=1),
        gz.circle(0.26 * R, xy=(R / 2, 0), stroke=(0, 0, 0), stroke_width=1)
    ])

# Go one level deep into the fractal
fractal = fractal.translate([(R / 2), 0]).scale(4)


def make_frame(t):
    surface = gz.Surface(W, H)
    G = 2**(2 * (t / D))  # zoom coefficient
Exemple #12
0
import gizeh
import numpy as np
surface = gizeh.Surface(width=400, height=400)
Pi = 3.14
circ = gizeh.circle(r=30, xy=(50, 50), fill=(0, 0, 0))
rect = gizeh.rectangle(lx=60, ly=45, xy=(100, 100), fill=(0, 1, 0))
sqr = gizeh.square(l=20, stroke=(1, 1, 1), stroke_width=1.5)
arc = gizeh.arc(r=20, a1=Pi / 4, a2=3 * Pi / 4, fill=(1, 1, 1))
text = gizeh.text("Hello world",
                  fontfamily="Impact",
                  fontsize=40,
                  fill=(1, 1, 1),
                  xy=(100, 100),
                  angle=Pi / 12)
polygon = gizeh.regular_polygon(r=40,
                                n=5,
                                angle=np.pi / 4,
                                xy=[40, 50],
                                fill=(1, 0, 1))
line = gizeh.polyline(points=[(0, 0), (20, 30), (40, 40), (0, 10)],
                      stroke_width=3,
                      stroke=(1, 0, 0),
                      fill=(0, 1, 0))
circ.draw(surface)
rect.draw(surface)
sqr.draw(surface)
arc.draw(surface)
text.draw(surface)
polygon.draw(surface)
line.draw(surface)
Exemple #13
0
import gizeh as gz
from math import pi

L = 200 
surface = gz.Surface(L, L, bg_color=(0 ,.3, .6)) 
r = 80 

yin_yang = gz.Group([
     gz.arc(r, pi/2, 3*pi/2, fill = (1,1,1)), 
     gz.arc(r, -pi/2, pi/2, fill = (0,0,0)), 
     gz.arc(r/2, -pi/2, pi/2, fill = (1,1,1), xy = [0,-r/2]), 
     gz.arc(r/2, pi/2, 3*pi/2, fill = (0,0,0), xy = [0, r/2]),  
     gz.circle(r/8, xy = [0,  +r/2], fill = (1,1,1)), 
     gz.circle(r/8, xy = [0,  -r/2], fill = (0,0,0)) ]) 
    
yin_yang.translate([L/2,L/2]).draw(surface)
surface.write_to_png("yin_yang.png")
Exemple #14
0
        # Finish the previous linegroup
        prevline = gizeh.polyline(line, stroke_width=5)
        line = []

        vx, vy = x-old_x, y-old_y
        distance = hypot(vx, vy)
        radius = distance*(random.random()/2 + 0.5)
        mid_x, mid_y = old_x+vx/2, old_y+vy/2
        sgn = random.choice([1, -1])
        # 90 degrees rotated, direction random
        hvx, hvy = -vy*sgn, vx*sgn
        hlength = sqrt(radius**2 - (distance/2)**2)
        f = hlength/distance
        center_x, center_y = mid_x+f*hvx, mid_y+f*hvy

        arc = gizeh.arc(radius, atan2(old_y-center_y, old_x-center_x), atan2(y-center_y, x-center_x), xy=[center_x+IMAGE_BORDER, center_y+IMAGE_BORDER], stroke_width=5)
        g = gizeh.Group([g, prevline, arc])
        
    line.append([x+IMAGE_BORDER, y+IMAGE_BORDER])
    old_x, old_y = x, y

p = gizeh.polyline(line, stroke_width=5)
g = gizeh.Group([g, p])

g.draw(surface)

surface.write_to_png("sigil.png")

upload = imgurclient.upload_from_path(os.getcwd()+"/sigil.png")
os.remove(os.getcwd()+"/sigil.png")