Curve Curve Ninjas December 19, 2012 Curve Ninjas Curve Overview - - PowerPoint PPT Presentation

curve
SMART_READER_LITE
LIVE PREVIEW

Curve Curve Ninjas December 19, 2012 Curve Ninjas Curve Overview - - PowerPoint PPT Presentation

Overview Using Curve Implementation Lessons Curve Curve Ninjas December 19, 2012 Curve Ninjas Curve Overview Using Curve Implementation Lessons Ninjas Shinobi Kun An John Chan David Mauskop Wisdom Omuya Zitong Wang Curve Ninjas


slide-1
SLIDE 1

Overview Using Curve Implementation Lessons

Curve

Curve Ninjas December 19, 2012

Curve Ninjas Curve

slide-2
SLIDE 2

Overview Using Curve Implementation Lessons

Ninjas

Shinobi Kun An John Chan David Mauskop Wisdom Omuya Zitong Wang

Curve Ninjas Curve

slide-3
SLIDE 3

Overview Using Curve Implementation Lessons

Overview

Simple, yet expressive

Overview 2D graphics and animations Minimal set of built-ins Easily tailored to more specific domains Static scoping, strongly-typed, call by value

Curve Ninjas Curve

slide-4
SLIDE 4

Overview Using Curve Implementation Lessons

Motivation

Bezier curves

Motivating Observation All the geometric objects that form the building blocks of a graphics language generalize to Bezier curves A Bezier curve is defined by two “anchor” points and any number of “control” points (for us, two)

Curve Ninjas Curve

slide-5
SLIDE 5

Overview Using Curve Implementation Lessons

Bezier curve example

Screenshots from an animation written in Curve

t = 4 t = 5 t = 6

Curve Ninjas Curve

slide-6
SLIDE 6

Overview Using Curve Implementation Lessons

Basic syntax

1

// Declaration statements

2

Point p ;

3

Curve c ;

4

Layer l ;

5

int i ;

6 7

// Assignment statements

8

p = (x , y ) ;

9

c1 = ( p . getX ( ) , y1 ) ( x2 , p . getY ( ) ) ( x3 , y3 ) ( x4 , y4 ) ;

10

c2 = rectangleP (p , 100 , 200) ;

11

l = [ c1 , c2 ] ;

Curve Ninjas Curve

slide-7
SLIDE 7

Overview Using Curve Implementation Lessons

Basic syntax

1

// Control flow

2

f o r ( i = 0; i < 10; i++) { }

3

w h i l e ( i < 10) {i++;}

4

i f ( i < 10) { } e l s e { }

5 6

// Function declaration

7

Layer square ( Point p , int size ) { }

8 9

// Animation built−ins

10

draw ( l ) ;

11

pause (1000) ;

12

clear () ;

Curve Ninjas Curve

slide-8
SLIDE 8

Overview Using Curve Implementation Lessons

Example Program

int drawTree(int x, int y, int n) { Curve left; Curve right; if (n == 0) return 1; drawTree(x - exp(2, n), y - 50, n - 1); drawTree(x + exp(2, n), y - 50, n - 1); left = lineP((x, y), (x - exp(2, n), y - 50)); right = lineP((x, y), (x + exp(2, n), y - 50)); draw([left, right]); pause(100); return 1; }

Curve Ninjas Curve

slide-9
SLIDE 9

Overview Using Curve Implementation Lessons

Result

Curve Ninjas Curve

slide-10
SLIDE 10

Overview Using Curve Implementation Lessons

Frontend

What is included Scanner Parser AST Interpreter Semantic checker

Curve Ninjas Curve

slide-11
SLIDE 11

Overview Using Curve Implementation Lessons

Frontend

AST Variable Declaration Function Declaration

Curve Ninjas Curve

slide-12
SLIDE 12

Overview Using Curve Implementation Lessons

Frontend

Interpreter Not part of final deliverable. Useful testing tool when implementing the scanner, parser, and AST. Easier to implement and modify compared with the compiler.

Curve Ninjas Curve

slide-13
SLIDE 13

Overview Using Curve Implementation Lessons

Frontend

Semantic checker All kinds of type mismatches including variable assignment, LHS & RHS of an assignment statement or binary operation, parameter of user-defined function, built-in function, standard library function, etc. Number of parameters mismatched with the definition of the function. Return type mismatches with the definition of the function’s return type. Undeclared variables or functions. Lack of return statement for user-defined functions.

Curve Ninjas Curve

slide-14
SLIDE 14

Overview Using Curve Implementation Lessons

Backend

Bytecode Rta - Prepares for a Return Ind/Ins - Indirect Load/Store Ogr - Open Graph

Curve Ninjas Curve

slide-15
SLIDE 15

Overview Using Curve Implementation Lessons

Backend

Compiler Creates bytecode Record keeping - offsets for variables (global/local) and functions, return types, enumerates bytecode so subroutines have targets Built-ins

Curve Ninjas Curve

slide-16
SLIDE 16

Overview Using Curve Implementation Lessons

Backend

Execute - Bytecode interpreter Performs actions indicated by bytecode Initializes Graphics environment Maintains a stack Due to small size of instruction set, this code is terse

Curve Ninjas Curve

slide-17
SLIDE 17

Overview Using Curve Implementation Lessons

Lessons Learned

Big groups aren’t so bad Pacing is key Test, test, and test again

Curve Ninjas Curve