コード例 #1
0
ファイル: ptline.py プロジェクト: 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()
コード例 #2
0
ファイル: patline.py プロジェクト: uhwang/vgl
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()
コード例 #3
0
ファイル: test_mesh.py プロジェクト: uhwang/vgl

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
コード例 #4
0
ファイル: julia.py プロジェクト: 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
コード例 #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):
コード例 #6
0
ファイル: x2x3.py プロジェクト: uhwang/vgl
# ex plot x**2, x**3

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()
	
コード例 #7
0
ファイル: sin_movie.py プロジェクト: uhwang/vgl
from vgl import DeviceCairo, DeviceCairoAnimation
from vgl import drawfrm, symbol

dtheta = 0.05
theta = 0
r1 = 3
r2 = 0.2
sint_trail_xpos = 4
sine_trail=[]
sine_plot_range= 8
max_sine_freq=1 # 2 Hz
max_theta = 2*np.pi*max_sine_freq
max_sine_points=int(max_theta/dtheta)
sine_plot_xratio = float(sine_plot_range)/float(max_sine_points)

data = Data(-5,15,-10,10)
fmm = FrameManager()
frm = fmm.create(0.0,0.0,5,5, data)
gbox = fmm.get_gbbox()
sym = symbol.Gradient(0.04, frm.hgt())

def sine_wave(t):
	global theta, sine_trail, sine_plot_xratio, max_sine_points, dev
	
	dev.fill_white()
	drawfrm.draw_frame(dev,frm)
	drawfrm.draw_axis(dev, data)
	drawfrm.draw_grid(dev, data, 1)

	thk=0.001*dev.frm.hgt()
	x1 = r1*np.cos(theta)
コード例 #8
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()
コード例 #9
0
ファイル: ftree02.py プロジェクト: uhwang/vgl
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: