コード例 #1
0
def shift(shape, coord):

    for vec in shape:
        __pragma__('opov')
        vec += coord
        __pragma__('noopov')

    return shape
コード例 #2
0
def rotate_up(shape):
    __pragma__('opov')
    new_shape = [
        shape[0] + [0, 1 / 8, -1 / 8], shape[1] + [0, 1 / 8, 1 / 8],
        shape[2] + [0, 1 / 8, 1 / 8], shape[3] + [0, 1 / 8, -1 / 8],
        shape[4] + [0, -1 / 8, 1 / 8], shape[5] + [0, -1 / 8, -1 / 8],
        shape[6] + [0, -1 / 8, -1 / 8], shape[7] + [0, -1 / 8, 1 / 8]
    ]
    __pragma__('noopov')
    return new_shape
コード例 #3
0
    def form_submit(self, event):
        event.preventDefault()

        def success(data, status, xhr):
            self.data = data
            self.form.dispatchEvent(
                __new__(AjaxFormEvent)('ajaxformsuccess', data, xhr))

        def error(xhr, status, error):
            self.form.dispatchEvent(
                __new__(AjaxFormEvent)('ajaxformerror', error, xhr))

        # __pragma__('noalias', 'type')
        # __pragma__('jsiter')
        # __pragma__('jskeys')
        # ajax({
        #     type: self.method,
        #     url: self.action,
        #     data: test,
        #     contentType: 'application/x-www-form-urlencoded',
        #     beforeSend: lambda xhr, settings: csrfCompat(xhr, settings),
        #     success: success,
        #     error: error,
        # })
        # __pragma__('nojskeys')
        # __pragma__('nojsiter')
        # __pragma__('alias', 'type', 'py_type')

        __pragma__(
            'js', '{}', """
ajax ({
    type: self.method, 
    url: self.action, 
    data: formSerialize(self.form), 
    contentType: 'application/x-www-form-urlencoded', 
    beforeSend: (function __lambda__ (xhr, settings) {
        return csrfCompat (xhr, settings);
    }), 
    success: success,
    error: error
});""")
コード例 #4
0
def mix(u, v, s ):
    __pragma__('js', 'var t = typeof s')
    if not t is "number":
        __pragma__('js', '{}', """throw "mix: the last paramter " + s + " must be a number";""")
        
    
    if ( len(u) != len(v) ):
        __pragma__('js', '{}', """throw "vector dimension mismatch";""")

    return u * [1-s for i in u] + v * [s for i in v] 
コード例 #5
0
ファイル: main.py プロジェクト: AlexECX/Devoirs1-Infographie
from org.transcrypt import __pragma__, __new__  # __: skip
from MV import vec4, ortho, flatten  # __: skip
from javascript import Worker, document, alert  # __: skip
from WebGL import initShaders, WebGLUtils  # __: skip

from py_vector import Vector3D
import shapes

__pragma__(
    'js', """/*
The main module: 
- Will setup WebGL.
- Launch JS Workers to recursively divide each faces of an object.
- The last worker calls a render function. It will render each faces 
  using the appropriate subset of points/vectors, with different colors. 
*/""")

gl = None
program = None
__pragma__('js', '//2D or 3D dimension')
render_D = None

worker_count = 0
worker_points = []

BaseColors = [
    vec4(0.0, 0.0, 0.0, 1.0),  # black
    vec4(1.0, 0.0, 0.0, 1.0),  # red
    vec4(1.0, 1.0, 0.0, 1.0),  # yellow
    vec4(0.0, 1.0, 0.0, 1.0),  # green
    vec4(0.0, 0.0, 1.0, 1.0),  # blue
コード例 #6
0
from org.transcrypt import __pragma__  #__: skip
from py_vector import Vector2D, Vector3D
import py_vector

__pragma__('js', """
//make_square is usually prefered.""")


def make_square2D(size=.5):
    square = [
        Vector2D(-size, -size),
        Vector2D(size, -size),
        Vector2D(size, size),
        Vector2D(-size, size),
    ]
    return square


def make_square(size=.5):
    square = [
        Vector3D(-size, -size, 0),
        Vector3D(size, -size, 0),
        Vector3D(size, size, 0),
        Vector3D(-size, size, 0),
    ]
    return square


def make_cube(size=.5, z=0):
    base = [
        Vector3D(-size, size, -size),
コード例 #7
0
from org.transcrypt import __pragma__ #__: skip


# __pragma__('opov')

__pragma__('js',"""
//MV.mix implementation using python operator overload""")
def mix(u, v, s ):
    __pragma__('js', 'var t = typeof s')
    if not t is "number":
        __pragma__('js', '{}', """throw "mix: the last paramter " + s + " must be a number";""")
        
    
    if ( len(u) != len(v) ):
        __pragma__('js', '{}', """throw "vector dimension mismatch";""")

    return u * [1-s for i in u] + v * [s for i in v] 

# __pragma__('noopov')

__pragma__('js', '{}', """
//Custom made Vector classes translated from python to JS.
//Mainly used for operator overload functionnality, and to try the 
//Transcrypt transpiler functionnalities.""")
class Vector:

    coord = []
    normalized = False


    def __init__(self, *args):
コード例 #8
0
from JS import alert, document, window, CustomEvent, JSON  #__: skip
from org.transcrypt import __pragma__, __new__  #__: skip

__pragma__(
    'js', '{}', """
(function () {

  if ( typeof window.CustomEvent === "function" ) return false;

  function CustomEvent ( event, params ) {
    params = params || { bubbles: false, cancelable: false, detail: null };
    var evt = document.createEvent( 'CustomEvent' );
    evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
    return evt;
   }

  CustomEvent.prototype = window.Event.prototype;

  window.CustomEvent = CustomEvent;
})();

class AjaxFormEvent extends CustomEvent {
    constructor(event_name, data, xhr) {
        super(event_name);
        this.xhr = xhr;
        this.data = data;
    }
}""")


class BaseAjaxForm: