<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?action=history&amp;feed=atom&amp;title=GMU%3AProcessing_im_Park%2FPart4</id>
	<title>GMU:Processing im Park/Part4 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?action=history&amp;feed=atom&amp;title=GMU%3AProcessing_im_Park%2FPart4"/>
	<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Processing_im_Park/Part4&amp;action=history"/>
	<updated>2026-04-30T14:27:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Processing_im_Park/Part4&amp;diff=77641&amp;oldid=prev</id>
		<title>Ms: Clean up</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Processing_im_Park/Part4&amp;diff=77641&amp;oldid=prev"/>
		<updated>2016-01-21T12:40:27Z</updated>

		<summary type="html">&lt;p&gt;Clean up&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Sorting Images=&lt;br /&gt;
&lt;br /&gt;
== Pixel Sorting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
PImage img;&lt;br /&gt;
int id = 1;&lt;br /&gt;
int sortMode = 1;&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
  size(600, 400);&lt;br /&gt;
  reset();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void reset() {&lt;br /&gt;
    img = loadImage(&amp;quot;winterpark.jpg&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void draw() {&lt;br /&gt;
  &lt;br /&gt;
  // load em&lt;br /&gt;
  img.loadPixels();&lt;br /&gt;
  &lt;br /&gt;
  color[] pxls = img.pixels;&lt;br /&gt;
  &lt;br /&gt;
  switch(sortMode) {&lt;br /&gt;
    case 1: &lt;br /&gt;
      sortLeft(pxls);&lt;br /&gt;
      break;&lt;br /&gt;
    case 2:&lt;br /&gt;
      sortDown(pxls);&lt;br /&gt;
      break;&lt;br /&gt;
    case 3:&lt;br /&gt;
      sortUp(pxls);&lt;br /&gt;
      break;&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  // update em&lt;br /&gt;
  img.updatePixels();&lt;br /&gt;
  &lt;br /&gt;
  // show em&lt;br /&gt;
  image(img, 0, 0);&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void sortLeft(color[] pxls) {&lt;br /&gt;
  &lt;br /&gt;
  // do something with the pixels (remix them)&lt;br /&gt;
  for(int y = 0; y &amp;lt; height; y++) {&lt;br /&gt;
    &lt;br /&gt;
    for(int x = 0; x &amp;lt; width-1 ; x++) {&lt;br /&gt;
&lt;br /&gt;
      // get indices for left and right pixel&lt;br /&gt;
      int left = y * img.width + x;&lt;br /&gt;
      int right = y * img.width + (x+1);&lt;br /&gt;
&lt;br /&gt;
       // bubble sort step ( exchange pixels according to saturation ... )&lt;br /&gt;
       int posx = mouseX - width / 2;&lt;br /&gt;
     &lt;br /&gt;
       if(green(pxls[right]) - green(pxls[left]) &amp;lt; posx) {&lt;br /&gt;
          // exchange color values of those pixels&lt;br /&gt;
          color tmp= pxls[right];&lt;br /&gt;
          pxls[right] = pxls[left];&lt;br /&gt;
          pxls[left] = tmp;&lt;br /&gt;
       }  &lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void sortDown(color[] pxls) {&lt;br /&gt;
&lt;br /&gt;
  // do something with the pixels (remix them)&lt;br /&gt;
  for(int x = 0; x &amp;lt; width; x++) {&lt;br /&gt;
    &lt;br /&gt;
    for(int y = height - 2; y &amp;gt; 0 ; y--) {&lt;br /&gt;
&lt;br /&gt;
      // get indices for left and right pixel&lt;br /&gt;
      int top = y * img.width + x;&lt;br /&gt;
      int bottom = (y+1) * img.width + x;&lt;br /&gt;
      &lt;br /&gt;
       // bubble sort step ( exchange pixels according to saturation ... )&lt;br /&gt;
       int posx = mouseX - width / 2;&lt;br /&gt;
     &lt;br /&gt;
       if(green(pxls[top]) - green(pxls[bottom]) &amp;lt; posx) {&lt;br /&gt;
          // exchange color values of those pixels&lt;br /&gt;
          color tmp= pxls[top];&lt;br /&gt;
          pxls[top] = pxls[bottom];&lt;br /&gt;
          pxls[bottom] = tmp;&lt;br /&gt;
       }  &lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void sortUp(color[] pxls) {&lt;br /&gt;
&lt;br /&gt;
  // do something with the pixels (remix them)&lt;br /&gt;
  for(int x = 0; x &amp;lt; width; x++) {&lt;br /&gt;
    &lt;br /&gt;
    for(int y = 0; y &amp;lt; height -1 ; y++) {&lt;br /&gt;
&lt;br /&gt;
      // get indices for left and right pixel&lt;br /&gt;
      int top = y * img.width + x;&lt;br /&gt;
      int bottom = (y+1) * img.width + x;&lt;br /&gt;
      &lt;br /&gt;
       // bubble sort step ( exchange pixels according to saturation ... )&lt;br /&gt;
       int posx = mouseX - width / 2;&lt;br /&gt;
     &lt;br /&gt;
       if(green(pxls[top]) - green(pxls[bottom]) &amp;lt; posx) {&lt;br /&gt;
          // exchange color values of those pixels&lt;br /&gt;
          color tmp= pxls[top];&lt;br /&gt;
          pxls[top] = pxls[bottom];&lt;br /&gt;
          pxls[bottom] = tmp;&lt;br /&gt;
       }  &lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void keyPressed() {&lt;br /&gt;
  switch(key) {&lt;br /&gt;
    case &amp;#039; &amp;#039;:  &lt;br /&gt;
      reset();&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;#039;s&amp;#039;:&lt;br /&gt;
      save(&amp;quot;sorted-&amp;quot; + id +&amp;quot;.jpg&amp;quot;);&lt;br /&gt;
      id++;&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;#039;1&amp;#039;:&lt;br /&gt;
      sortMode = 1;&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;#039;2&amp;#039;:&lt;br /&gt;
     sortMode = 2;&lt;br /&gt;
     break;&lt;br /&gt;
    case &amp;#039;3&amp;#039;:&lt;br /&gt;
     sortMode = 3;&lt;br /&gt;
     break;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Tile Sorting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PImage img;&lt;br /&gt;
int d = 10;&lt;br /&gt;
PImage[] tiles;&lt;br /&gt;
int rows, cols, n;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
&lt;br /&gt;
  size(600, 400);&lt;br /&gt;
  img = loadImage(&amp;quot;fall.jpg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
  cols = (img.width/d);&lt;br /&gt;
  rows = (img.height/d);&lt;br /&gt;
&lt;br /&gt;
  n = cols * rows;&lt;br /&gt;
  tiles = new PImage[n];&lt;br /&gt;
&lt;br /&gt;
  for (int i = 0; i &amp;lt; n; i++) {&lt;br /&gt;
&lt;br /&gt;
    int x = d * (i % cols);&lt;br /&gt;
    int y = d * (i / cols);&lt;br /&gt;
&lt;br /&gt;
    tiles[i] = img.get(x, y, d, d);&lt;br /&gt;
    &lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void draw() {&lt;br /&gt;
  &lt;br /&gt;
   sort(tiles);&lt;br /&gt;
   // show tiles&lt;br /&gt;
   for(int i = 0; i &amp;lt; n; i++) {&lt;br /&gt;
     &lt;br /&gt;
     PImage tile = tiles[i];&lt;br /&gt;
&lt;br /&gt;
     int y = d * (i / cols);&lt;br /&gt;
     int x = d * (i % cols);&lt;br /&gt;
     &lt;br /&gt;
     image(tile, x, y, d, d);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void sort(PImage[] tiles) {&lt;br /&gt;
  &lt;br /&gt;
  for(int y = 0; y &amp;lt; rows; y++) {&lt;br /&gt;
    for(int x = 0; x &amp;lt; cols-1; x++) {&lt;br /&gt;
      &lt;br /&gt;
      int pos1 = y * cols + x;&lt;br /&gt;
      int pos2 = y * cols + (x+1);&lt;br /&gt;
      &lt;br /&gt;
      PImage tile1 = tiles[pos1];&lt;br /&gt;
      PImage tile2 = tiles[pos2];&lt;br /&gt;
      &lt;br /&gt;
      if( saturation(average(tile1)) - saturation(average(tile2)) &amp;gt; mouseX ) {&lt;br /&gt;
        PImage tmptile = tiles[pos1];&lt;br /&gt;
        tiles[pos1] = tiles[pos2];    &lt;br /&gt;
        tiles[pos2] = tmptile;&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
color average(PImage img) { &lt;br /&gt;
  img.loadPixels();&lt;br /&gt;
  color[] pxls = img.pixels;&lt;br /&gt;
  &lt;br /&gt;
  float r = 0, g = 0, b = 0;&lt;br /&gt;
  int n = pxls.length;&lt;br /&gt;
  &lt;br /&gt;
  for(int i = 0; i &amp;lt; n; i++) {&lt;br /&gt;
    color c = pxls[i];&lt;br /&gt;
    r += red(c);&lt;br /&gt;
    g += green(c);&lt;br /&gt;
    b += blue(c);&lt;br /&gt;
  }&lt;br /&gt;
  color average = color(r/n, g/n, b/n);&lt;br /&gt;
  return average;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Ms</name></author>
	</entry>
</feed>