This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
spcs:summer2014:d6 [2014/07/22 12:02] ffpaladin |
spcs:summer2014:d6 [2014/07/22 12:09] ffpaladin [Part 2: Visual Sorting II. Spend 20-30 min (Yesterday Teams)] |
||
---|---|---|---|
Line 17: | Line 17: | ||
* http://pixelartor.com/ | * http://pixelartor.com/ | ||
* http://hereistoday.com/ | * http://hereistoday.com/ | ||
+ | |||
+ | Non Animating Sort | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | |||
+ | // GLOBAL VARIABLES | ||
+ | |||
+ | |||
+ | int [] array = {90,60,70,50,40,30,20,10,1,80}; | ||
+ | |||
+ | // int i, j, k, l; | ||
+ | |||
+ | // SETUP FUNCTION - Runs Once | ||
+ | |||
+ | void setup () { | ||
+ | |||
+ | size(500,500); | ||
+ | | ||
+ | int min = 0; // index of the array | ||
+ | | ||
+ | | ||
+ | // outer for-loop | ||
+ | for (int i=0; i<10; i++) { | ||
+ | | ||
+ | min = i; | ||
+ | | ||
+ | // inner for-loop | ||
+ | for (int j=i; j<10; j++) { | ||
+ | if (array[j] < array[min]) | ||
+ | min = j; | ||
+ | } | ||
+ | | ||
+ | // swapping | ||
+ | int temp = array[i]; | ||
+ | array[i] = array[min]; | ||
+ | array[min] = temp; | ||
+ | } | ||
+ | | ||
+ | for (int k=0; k<10; k++) | ||
+ | println(array[k]); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | // DRAW LOOP - Infinite Loop | ||
+ | |||
+ | void draw () { | ||
+ | |||
+ | background(255,0,0); | ||
+ | |||
+ | ellipse(mouseX, mouseY, 20, 20); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
Ball Code | Ball Code | ||
Line 98: | Line 154: | ||
===== Part 2: Visual Sorting II. Spend 20-30 min (Yesterday Teams) ===== | ===== Part 2: Visual Sorting II. Spend 20-30 min (Yesterday Teams) ===== | ||
- | Option 1: For those who've not gotten their sorts working, here's my selection sort from class. It's a little buggy: http://pastebin.com/hVFvXvD2 | + | **Option 1:** For those who've not gotten their sorts working, here's my selection sort from class. It's a little buggy: http://pastebin.com/hVFvXvD2 |
- | Option 2: If you are done your sort, take the beginning of class to add the following to the sort program: | + | **Option 2:** If you are done your sort, take the beginning of class to add the following to the sort program: |
- A Pause Button | - A Pause Button | ||
- A Start Button | - A Start Button | ||
- A Reset Button | - A Reset Button | ||
- | Option 3: If you'd rather work on your Seurat (Pixel Splotches), then you can create a way to change the ellipse sizes while within the program. | + | **Option 3:** If you'd rather work on your Seurat (Pixel Splotches), then you can create a way to change the ellipse sizes while within the running program. |
Remember, if your partner is done with the project, to Fork it into your own directory. Forking will allow you to continue the project on your own. You can keep a copy for yourself. | Remember, if your partner is done with the project, to Fork it into your own directory. Forking will allow you to continue the project on your own. You can keep a copy for yourself. | ||
Line 200: | Line 256: | ||
==== Step 2: An object that has x and y ==== | ==== Step 2: An object that has x and y ==== | ||
- | Try to see if you can create objects like you did above. | + | Try to see if you can create objects like you did for the ball classes. |
==== Step 3: Adjacency Matrix ==== | ==== Step 3: Adjacency Matrix ==== | ||
Line 210: | Line 266: | ||
Using some algorithm... Maybe Breadth First Search, draw a path that on the screen that highlights what's going on in the code. See example of lines above. | Using some algorithm... Maybe Breadth First Search, draw a path that on the screen that highlights what's going on in the code. See example of lines above. | ||
- | REMINDER: Shortest Path is NOT the Traveling Sales Person problem. That one is much harder. You do not have to return home like the image above. | + | REMINDER: Shortest Path is NOT the Traveling Sales Person problem. TSP is much harder. You do not have to return home like the image above. |
- | ==== Step 5: Traveling Sales Person ==== | + | ==== Step 5: Traveling Sales Person (Optional) ==== |
Find the shortest distance that Mousey can go INCLUDING his return home. | Find the shortest distance that Mousey can go INCLUDING his return home. | ||
Line 224: | Line 280: | ||
---- | ---- | ||
- | ===== Part 4 - JS Platformer ===== | + | ===== Part 4 - JS Platformer (Teams, if you have time) ===== |
Cookbook! You know what to do. | Cookbook! You know what to do. |