Example #1
0
File: ptline.py Project: uhwang/vgl
def main():

    data = Data(-3, 3, -1, 10)
    fmm = FrameManager()
    frm_x2 = fmm.create(0.0, 0.0, 2, 4, data)

    gbbox = fmm.get_gbbox()

    dev_wmf = DeviceWindowsMetafile("patlin.wmf", gbbox)
    dev_wmf.set_device(frm_x2)
    test(dev_wmf)
    dev_wmf.close()

    dev_img = DeviceCairo("patlin.png", gbbox, dpi)
    dev_img.fill_white()
    dev_img.set_plot(frm_x2)
    test(dev_img)
    dev_img.close()
Example #2
0
def main():
    from vgl import color, BBox, Frame, FrameManager, Data
    from vgl import DeviceWindowsMetafile, DeviceCairo
    #from vgl import drawfrm, symbol, drawtick, drawaxis, drawlabel

    data = Data(-3, 3, -1, 10)
    fmm = FrameManager()
    frm_x2 = fmm.create(0.0, 0.0, 4, 4, data)

    gbbox = fmm.get_gbbox()

    dev_img = DeviceCairo("patlin.png", gbbox, 100)
    dev_img.fill_white()
    dev_img.set_plot(frm_x2)
    test(dev_img)
    dev_img.close()

    dev_wmf = DeviceWindowsMetafile("patlin.wmf", gbbox)
    dev_wmf.set_device(frm_x2)
    test(dev_wmf)
    dev_wmf.close()
Example #3
0
def get_center(a, b):
    return (a + b) * 0.5


def get_half(min, max):
    return (max - min) * 0.5


xmin = np.min(geom[:, :, 0])
xmax = np.max(geom[:, :, 0])
ymin = np.min(geom[:, :, 1])
ymax = np.max(geom[:, :, 1])

data = Data(xmin, xmax, ymin, ymax, zmin, zmax)
fmm = FrameManager()
frm = fmm.create(0, 0, 5, 5, data)

mesh = mesh3d.SquareMesh3d(geom.shape[0], geom.shape[1])
mesh.create_node(geom)
mesh.create_mesh()
mesh.create_axis((0, 0, 0), get_half(xmin, xmax), get_half(ymin, ymax),
                 get_half(zmin, zmax))
mesh.set_show_axis(True)
v3d = view3d.View3d(frm)

running = True
old_pos = (0, 0)
new_pos = (0, 0)
m_xRotate = 0
m_yRotate = 0
Example #4
0
File: julia.py Project: uhwang/vgl
from vgl import color, BBox, Frame, FrameManager, Data, symbol
from vgl import DeviceCairo
import coltbl
from math import sin, cos

data = Data(0, 1, 0, 1)
fmm = FrameManager()
frm = fmm.create(0, 0, 4, 4, data)


def julia(dev):
    global wid, hgt

    zoom = 1
    moveX = 0
    moveY = 0
    maxIterations = 300

    # pick some values for the constant c,
    # this determines the shape of the Julia Set
    cRe = -0.7
    cIm = 0.27015

    #loop through every pixel
    for x in range(wid):
        for y in range(hgt):
            # calculate the initial real and imaginary part of z,
            # based on the pixel location and zoom
            # and position values
            newRe = 1.5 * (x - wid / 2) / (0.5 * zoom * wid) + moveX
            newIm = (y - hgt / 2) / (0.5 * zoom * hgt) + moveY
Example #5
0
# ex_polygon.py
#
#	Ref: Math Adventures with Python by Peter Farell
#
import pygame
from pygame.locals import *
import numpy as np

from vgl import Frame, FrameManager, Data
from vgl import DevicePygame, DeviceWindowsMetafile
from vgl import drawfrm, color, symbol, geom
from vgl.device import DeviceAggdraw

data = Data(-10, 10, -10, 10)
fmm = FrameManager()
frm = fmm.create(0.0, 0.0, 4, 4, data)
plist = []


def create_polygon_list():
    side = 1.7
    jump = 2.2 * side
    sx = -5.6
    sy = 5.6
    j = 0
    i = 1
    y = sy
    nstart = 3
    nend = 19
    step = 170 / (nend - nstart)
    for n in range(nstart, nend, 1):
Example #6
0
File: x2x3.py Project: uhwang/vgl
import pygame 
from pygame.locals import *
import numpy as np

from vgl import color, geom, BBox, Frame, FrameManager, Data
from vgl import DeviceWindowsMetafile, DevicePygame, DeviceAggdraw, DeviceCairo
from vgl import drawfrm, symbol, drawtick, drawaxis, drawlabel

x = np.arange(-3,3.2,0.2)
y2 = x**2
#y3 = x**2+3*np.sin(x)
y3 = x**3

data = Data(-6,6,-2,10)
fmm = FrameManager()
frm_x2 = fmm.create(0.0,0.0,3,3, data)
frm_x3 = fmm.create(3.2,3.4,3,3, data)
frm_x4 = fmm.create(0.0,3.2,3,2, Data(-4,4,-3,3))

def plot_x2(dev):
	drawaxis.draw_axis(dev)
	drawtick.draw_tick_2d(dev)	
	drawlabel.draw_label_2d(dev)
	dev.polyline(x, y2, color.BLUE, 0.003*dev.frm.hgt())
	sym = symbol.Circle(0.01, dev.frm.hgt())
	dev.begin_symbol(sym)
	for i in range(0,x.size): dev.symbol(x[i],y2[i],sym)
	dev.end_symbol()
	
def plot_x3(dev):
Example #7
0
# ex_x3.py
import numpy as np
from vgl import color, geom, BBox, Frame, FrameManager, Data
from vgl import DeviceWindowsMetafile, DevicePygame, DeviceAggdraw, DeviceCairo
from vgl import drawfrm, symbol, drawtick, drawaxis, drawlabel

x = np.arange(-3, 3, 0.2)
y = x**3

data = Data(-3, 3, -1, 10)
fmm = FrameManager()
fmm.create(0, 0, 3, 3, data)
frm = fmm.create(0, 3.4, 3, 3, data)

dev = DeviceWindowsMetafile('x3.wmf', fmm.get_gbbox())

dev.set_device(frm)
drawfrm.draw_frame(dev, frm)
clip = dev.frm.get_clip()
dev.create_clip(clip[0], clip[1], clip[2], clip[3])
dev.polyline(x, y, color.BLUE, 0.001 * frm.hgt())
dev.delete_clip()
dev.close()
Example #8
0
# ex_x2.py
import numpy as np

from vgl import color, geom, BBox, Frame, FrameManager, Data
from vgl import DeviceWindowsMetafile, DeviceAggdraw, DeviceCairo
from vgl import drawfrm, symbol, drawtick, drawaxis, drawlabel

x = np.arange(-3, 3.2, 0.2)
y2 = x**2

data = Data(-3, 3, -1, 10)
fmm = FrameManager()
frm_x2 = fmm.create(0.0, 0.0, 2.3, 4, data)


def plot_x2(dev):
    drawaxis.draw_axis(dev)
    drawtick.draw_tick_2d(dev)
    drawlabel.draw_label_2d(dev)
    dev.polyline(x, y2, color.BLUE, 0.001 * dev.frm.hgt())
    sym = symbol.Circle(0.01, dev.frm.hgt(), 0.003)
    #sym = symbol.RightTriangle(0.02, dev.frm.hgt(), 0.005)
    #sym = symbol.LeftTriangle(0.02, dev.frm.hgt(), 0.005)
    #sym = symbol.Diamond(0.02, dev.frm.hgt(), 0.005)
    #sym = symbol.Square(0.02, dev.frm.hgt(), 0.005)
    dev.begin_symbol(sym)
    for i in range(0, x.size):
        dev.symbol(x[i], y2[i], sym)
    dev.end_symbol()

Example #9
0
from vgl import color, BBox, Frame, FrameManager, Data, symbol
from vgl import DeviceWindowsMetafile, DeviceCairo, DeviceCairoAnimation
import coltbl
from math import sin, cos
import random
from moviepy.editor import *

xwid,xhgt=300,300
data = Data(0,xwid,0,xhgt)
fmm = FrameManager()
frm_x2 = fmm.create(0,0,4,4, data)
clips = []

def rand_tree(dev, order, length, angle):
	global posx, posy, ctbl, dlength, prv_posx, prv_posy, dev_ani, movie
	
	dx = length*sin(angle);
	dy = length*cos(angle);
	scale = random.random()
	turnl = random.random()
	turnr = random.random()
	
	prv_posx = posx
	prv_posy = posy
	
	posx -= dx;
	posy += dy;
	
	dev.line(prv_posx, prv_posy, posx, posy, ctbl[int(length-1)], length*dlength*0.04*dev.frm.hgt())
	
	if length <= 10: