NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/**
* This program is designed to make a kaleidoscope like image
*
* @author Sijia Liang
* @version 8/7/16
*
*/
import java.awt.*;
import turtlegraphics.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.Color;
public class Kaleidoscope
{
private Picture original = null;
private Picture newCanvas = null;
private Graphics g = null;
private Graphics2D g2 = null;
private Picture pic1 = null;
private Picture pic2 = null;
private Picture pic3 = null;
private Picture pic4 = null;
private Color color = null;
private Picture kaleidoscope = null;
private Picture scaled = null;
private Picture clipped = null;

Kaleidoscope(Color color, Picture canv, Picture p1, Picture p2, Picture p3, Picture p4, int length, int height, Picture kaleidoscopeObj, Picture scaledObj, Picture clippedObj)
{
newCanvas = canv;
original = new Picture(length, height);
g = original.getGraphics();
g2 = (Graphics2D)g;
g2.setColor(color);
pic1 = p1;
pic2 = p2;
pic3 = p3;
pic4 = p4;
kaleidoscope = kaleidoscopeObj;
scaled = scaledObj;
clipped = clippedObj;

}
public Picture getDrawing()
{
return original;
}
public Picture Turn()
{
Pixel targetPixel = new Pixel(pic1, 0,0); //set the coordinate for the image origin
Color pixelColor = null; //declare a Color object and set its initial value to null (or nothing)

Picture kaleidoscopeObj = new Picture(206, 206);
Pixel targetPixel1 = new Pixel(kaleidoscopeObj, 0, 0);
Pixel targetPixel2 = new Pixel(kaleidoscopeObj, 0, 0);

for(int y=0; y < pic1.getHeight(); y++) //outside nested loop to traverse the image from top to bottom
{
for(int x = 0; x < pic1.getWidth(); x++) //inside nested loop to traverse the image from left to right
{
if (y>x)
{
targetPixel = pic1.getPixel(x,y); //gets the x,y coordinate of the target pixel
pixelColor = targetPixel.getColor(); //gets the color of the target pixel
targetPixel1 = kaleidoscopeObj.getPixel(205 - x,y);
targetPixel1.setColor(pixelColor);
targetPixel2 = kaleidoscopeObj.getPixel(x,205 - y);
targetPixel2.setColor(pixelColor);
}
}
}
kaleidoscopeObj.write("C:\Users\School-pc\Desktop\CP1 Course Files\Module 9\Mod09 Documents\K1.jpg");
return kaleidoscope;
}
public Picture Flip()
{
Pixel targetPixel = new Pixel(kaleidoscope, 0,0); //set the coordinate for the image origin
Color pixelColor = null; //declare a Color object and set its initial value to null (or nothing)

Picture flip = new Picture(206, 206);
Pixel targetPixel1 = new Pixel(flip, 0, 0);

for(int y=0; y < pic1.getHeight(); y++) //outside nested loop to traverse the image from top to bottom
{
for(int x = 0; x < pic1.getWidth(); x++) //inside nested loop to traverse the image from left to right
{
targetPixel = kaleidoscope.getPixel(x,y); //gets the x,y coordinate of the target pixel
pixelColor = targetPixel.getColor(); //gets the color of the target pixel
targetPixel1 = flip.getPixel(205 - x,y);
targetPixel1.setColor(pixelColor);
}
}
flip.write("C:\Users\School-pc\Desktop\CP1 Course Files\Module 9\Mod09 Documents\K2.jpg");

Picture verticalFlip = new Picture(206, 206);
Pixel targetPixel2 = new Pixel(verticalFlip, 0, 0);

for(int y=0; y < pic1.getHeight(); y++) //outside nested loop to traverse the image from top to bottom
{
for(int x = 0; x < pic1.getWidth(); x++) //inside nested loop to traverse the image from left to right
{
targetPixel = kaleidoscope.getPixel(x,y); //gets the x,y coordinate of the target pixel
pixelColor = targetPixel.getColor(); //gets the color of the target pixel
targetPixel2 = verticalFlip.getPixel(x,205 - y);
targetPixel2.setColor(pixelColor);
}
}
verticalFlip.write("C:\Users\School-pc\Desktop\CP1 Course Files\Module 9\Mod09 Documents\K3.jpg");

Picture diagonalFlip = new Picture(206, 206);
Pixel targetPixel3 = new Pixel(diagonalFlip, 0, 0);

for(int y=0; y < pic1.getHeight(); y++) //outside nested loop to traverse the image from top to bottom
{
for(int x = 0; x < pic1.getWidth(); x++) //inside nested loop to traverse the image from left to right
{
targetPixel = flip.getPixel(x,y); //gets the x,y coordinate of the target pixel
pixelColor = targetPixel.getColor(); //gets the color of the target pixel
targetPixel2 = verticalFlip.getPixel(x,205 - y);
targetPixel2.setColor(pixelColor);
}
}
diagonalFlip.write("C:\Users\School-pc\Desktop\CP1 Course Files\Module 9\Mod09 Documents\K4.jpg");

return flip;
}
public Picture drawPicture()
{
g = newCanvas.getGraphics();
g2 = (Graphics2D)g;

g2.drawImage(kaleidoscope.getImage(), 0, 0, null);
g2.drawImage(pic2.getImage(), 206, 0, null);
g2.drawImage(pic3.getImage(), 206, 206, null);
g2.drawImage(pic4.getImage(), 0, 206, null);
return newCanvas;
}
public Picture scalePicture(double xFactor, double yFactor)
{
AffineTransform scaleTransform = new AffineTransform();
scaleTransform.scale(xFactor, yFactor);
scaled = new Picture((int)(newCanvas.getWidth()*xFactor), (int)(newCanvas.getHeight()*yFactor));
g = scaled.getGraphics();
g2 = (Graphics2D)g;
g2.drawImage(newCanvas.getImage(), scaleTransform, null);
scaled.write("C:\Users\School-pc\Desktop\CP1 Course Files\Module 9\Mod09 Documents\scaled.jpg");
return scaled;
}
public Picture clipPicture(Color color)
{
clipped = new Picture(scaled.getWidth(), scaled.getHeight());
clipped.setAllPixelsToAColor(color);
Ellipse2D.Double clip = new Ellipse2D.Double(0,0,clipped.getHeight(),clipped.getWidth());
//g = clipped.getGraphics();
g2.setClip(clip);
g2.drawImage(scaled.getImage(),0,0,clipped.getHeight(),clipped.getWidth(),null);
clipped.write("C:\Users\School-pc\Desktop\CP1 Course Files\Module 9\Mod09 Documents\clipped.jpg");
return clipped;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.