Skip to content

Commit 18187ce

Browse files
committed
add all projects
0 parents  commit 18187ce

File tree

1,377 files changed

+318007
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,377 files changed

+318007
-0
lines changed

Images/DBL6-Domino.jpg

19.5 KB
Loading

Images/OldGrTown.png

625 KB
Loading

Images/UV_Grid_Sm.jpg

636 KB
Loading

Images/dice_texture.png

5.75 KB
Loading

Images/door1.jpg

71.6 KB
Loading

Images/door2.jpg

8.71 MB
Loading

Images/house.png

220 KB
Loading

Images/palace-facade.jpg

159 KB
Loading

Images/roof-red.jpg

26.8 KB
Loading

Images/roof-white.jpg

91.9 KB
Loading

Images/roof1.jpg

383 KB
Loading

Images/roof2.jpg

1.17 MB
Loading

Images/shop-facade.jpg

233 KB
Loading

Images/window-brown.jpg

297 KB
Loading

Images/window-white.jpg

177 KB
Loading

Images/window1.jpg

70.4 KB
Loading

Images/window2.jpg

59.8 KB
Loading

Libs/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Library Sub-Directory for CS559 Workbooks
2+
3+
This directory contains files used by CS559 workbooks. It is included in workbooks.
4+
5+
Students should not edit the files in this directory or add to them without explicit instructions from the course staff.
6+
7+
Students are welcome to read the code.
8+
9+
Some of the files in this directory are written by Michael Gleicher and / or Florian Heimerl for the class.
10+
11+
Some of the files in this directory are open source libraries provided for students to use in their assignments. These files are provided under the terms of their respective licenses. The sources of these files are:

Libs/dragPoints.js

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*jshint esversion: 6 */
2+
// @ts-check
3+
/**
4+
* Simple thing to make a list of points in a Canvas draggable
5+
*
6+
* Designed for making quick UIs for CS559 demos
7+
*/
8+
9+
/**
10+
* Set up Draggable Points for an HTML Canvas
11+
* pass in the array of point positions (which it will change in the future)
12+
* and this will add the appropriate event handlers to the Canvas
13+
*
14+
* The "redraw" function is called for any event that changes the state of
15+
* the points (mouse down, up, move).
16+
* If the redraw is called by something else (e.g., and animation loop) it
17+
* can be set to null
18+
*
19+
* @param {HTMLCanvasElement} canvas - canvas to attach to
20+
* @param {Array<Array<number>>} pointList - list of points
21+
* @param {?FrameRequestCallback} redraw - function to be called when things change
22+
* @param {number} [circleRadius =10] - radius of circles (for hit testing)
23+
* @param {function} [changeNumber=undefined] - function to call if the number of points changes
24+
}}
25+
*/
26+
export function draggablePoints(canvas, pointList, redraw, circleRadius=10,changeNumber=undefined)
27+
{
28+
// keep state within the closure of the function
29+
let theCanvas = canvas;
30+
let thePoints = pointList;
31+
let theRedraw = redraw;
32+
let dragging = -1;
33+
34+
if (!circleRadius) { circleRadius=10; }
35+
let circRadiusSq = circleRadius * circleRadius;
36+
37+
canvas.addEventListener("mousedown",mouseDown);
38+
canvas.addEventListener("mousemove",drag);
39+
canvas.addEventListener("mouseup",endDrag);
40+
canvas.addEventListener("mouseleave",endDrag);
41+
42+
// box up the redraw
43+
function doRedraw() {
44+
if (theRedraw) {
45+
// rather than drawing immediately, queue up a redraw
46+
// note that this runs the redraw once (just not now)
47+
window.requestAnimationFrame(theRedraw);
48+
}
49+
}
50+
51+
// get the mouse position relative to a canvas
52+
function mousePosition(evt) {
53+
// remember - the clientX,clientY is not the actual mouse position
54+
// in the canvas coorindate system!
55+
let x = evt.clientX;
56+
let y = evt.clientY;
57+
var canvasbox = theCanvas.getBoundingClientRect();
58+
x -= canvasbox.left;
59+
y -= canvasbox.top;
60+
return [x,y];
61+
}
62+
63+
// select the point nearest to the mouse
64+
// note that this returns the index of the point - it does not set selection
65+
// or cause a redraw - you probably don't want to use this
66+
// as a handler
67+
function pickPoint(evt) {
68+
let [x,y] = mousePosition(evt);
69+
70+
// nothing is selected, and minimum distance
71+
let sel=-1;
72+
let minD=circRadiusSq;
73+
thePoints.forEach((pt,i)=>{
74+
let dx = pt[0]-x;
75+
let dy = pt[1]-y;
76+
let d = dx*dx+dy*dy;
77+
if (d<minD) {
78+
minD = d;
79+
sel = i;
80+
}
81+
});
82+
return sel;
83+
}
84+
85+
// mouse click - perform dragging
86+
// if shift is held down, make a new point
87+
// if ctrl or meta is held down, delete the point
88+
// we need to do meta for the mac, where ctrl means something
89+
/**
90+
*
91+
* @param {MouseEvent} evt
92+
*/
93+
function mouseDown(evt) {
94+
if (evt.shiftKey) {
95+
// we need to decide where to put the point
96+
// guess 1 = after the selected point
97+
let select = pickPoint(evt);
98+
99+
if (select >=0) {
100+
let p1 = select;
101+
let p2 = (select+1) % thePoints.length;
102+
let newPt = [(thePoints[p1][0]+thePoints[p2][0])/2,
103+
(thePoints[p1][1]+thePoints[p2][1])/2];
104+
thePoints.splice(p1+1,0,newPt);
105+
} else {
106+
// easy part is where,
107+
// the harder part is what position
108+
let xy = mousePosition(evt);
109+
thePoints.push(xy);
110+
if (changeNumber) changeNumber();
111+
doRedraw();
112+
}
113+
} else if (evt.ctrlKey || evt.metaKey) {
114+
// do not delete the only point
115+
if (thePoints.length > 1) {
116+
let select = pickPoint(evt);
117+
if (select>=0) {
118+
thePoints.splice(select,1);
119+
if (changeNumber) changeNumber();
120+
doRedraw();
121+
}
122+
}
123+
} else {
124+
let select = pickPoint(evt);
125+
126+
if (select >= 0) {
127+
dragging = select;
128+
doRedraw();
129+
}
130+
}
131+
}
132+
function endDrag(evt) {
133+
dragging = -1;
134+
doRedraw();
135+
}
136+
function drag(evt) {
137+
if (dragging >= 0) {
138+
let xy = mousePosition(evt);
139+
thePoints[dragging] = xy;
140+
doRedraw();
141+
}
142+
}
143+
}

Libs/helpers.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*jshint esversion: 6 */
2+
// @ts-check
3+
/**
4+
* CS559 Helper Library
5+
*
6+
* Small utility functions to make the workbooks and demonstrations easier
7+
* to write.
8+
*
9+
* students are welcome to read this code and use it, but they should not
10+
* modify it unless instructed to by course staff
11+
*/
12+
13+
/**
14+
* Call a function on window.onload
15+
* - calls any previous function that was there
16+
* - by placing it in a function, the old function can be easily stored in closure
17+
*/
18+
export function onWindowOnload(newFunction)
19+
{
20+
let oldFunction = window.onload;
21+
window.onload = function(ev) {
22+
// technically, window.onload is an event handler and can expect that
23+
// "this" is the window, so we have to use apply
24+
if (oldFunction)
25+
oldFunction.apply(window,ev);
26+
newFunction();
27+
};
28+
}

0 commit comments

Comments
 (0)