DAT405 Creative Coding

Posted on Updated on

OK! This module is  starter module for learning to code using Processing  language. YAY! Its a reasonably platform independent java based IDE.

The end project was to make a space invader based game. Which I did with some coaching as I was changing all kind life choices such as work and domicility.

Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping.

vsdLA

 

  • » Free to download and open source
  • » Interactive programs with 2D, 3D or PDF output
  • » OpenGL integration for accelerated 2D and 3D
  • » For GNU/Linux, Mac OS X, and Windows

https://processing.org/

Week 1 code

Its a basic alarm.

// task 6 -7
import processing.video.Movie; // this code enable video(sound)

int alarmHour=12;// set hr for alarmHour variable. IE the alarm time hr
int alarmMin=45;// set minutes for alarm
int alarmSec=30;// set Second for alarm

long lastTime = 0; // this variable uses long. a variable type that extends number base beyond int
lastTime = millis();
int upToEightCounter=1;
String dayOfWeek=”Friday”;
boolean alwaysTrue=true;

while (alwaysTrue)
{
if (dayOfWeek==”Monday” || dayOfWeek==”Tuesday” || dayOfWeek==”Wednesday” || dayOfWeek==”Thursday” || dayOfWeek==”Friday” )

{
if (hour()==alarmHour && minute() ==alarmMin && second() ==alarmSec)
{
println(” Wake Up sleepy Head”);
Movie alarm = new Movie(this, “alarm.m4v”);//
alarm.play();
print(“Counting: “);
while (upToEightCounter<=8)
{
if ( millis() – lastTime > 1000 )
{
lastTime = millis();
print(” ” + upToEightCounter);
upToEightCounter++;
}
}
}
} else
{
if (dayOfWeek==”Saturday” || dayOfWeek==”Sunday”)
{
if (hour()==alarmHour && minute() ==alarmMin && second() ==alarmSec)
{
println(“Its weekend so go back to bed!”);
}
}
}
print(” ..working.. “);
int total=0;
for (int count = 0; count <1000000000; count = count+1)
{
total = total+count;
}
}

Just need comments!!

Later shall add much partial completed code for Invaders as the 2d Array work may be worth revisiting.invader

If i am honest, I really struggled getting this to even 1/2 work. I am not natural at the abstraction of coding and prefer HTML, CSS and visual elements with web development. Below is the page one code (processing) for the space invaders that i made.The graphics in the game were hand drawn by me and scanned into Photoshop and given a bitmap feel. AS you you see the code using a 2D array to layout the ships.


 

PImage invader;
PImage backgroundSky;
boolean[][] invaderBox= new boolean [18][18];
int invaderSpacing;
void setup()
{

size(800, 600);
rectMode(CENTER);
imageMode (CENTER);
backgroundSky =loadImage(“backgoundSky.png”);
shipSetup();
invaderSetup();
invaderSpacing = width/10;

invaderBox [1][0] = true; // column1 row0
invaderBox [1][1] = true; //column 1 row1
invaderBox [1][2] = true; //column 1 row2
invaderBox [1][3] = true;
invaderBox [1][4] = true;
invaderBox [3][0] = true;
invaderBox [3][1] = true;
invaderBox [3][2] = true;
invaderBox [3][3] = true;
invaderBox [3][4] = true;
invaderBox [5][0] = true;
invaderBox [5][1] = true;
invaderBox [5][2] = true;
invaderBox [5][3] = true;
invaderBox [5][4] = true;
invaderBox [7][0] = true;
invaderBox [7][1] = true;
invaderBox [7][2] = true;
invaderBox [7][3] = true;
invaderBox [7][4] = true;
invaderBox [9][0] = true;
invaderBox [9][1] = true;
invaderBox [9][2] = true;
invaderBox [9][3] = true;
invaderBox [9][4] = true;
}

void draw ( ) {
background(0);
laserDraw(); //calls laser draw from laser tab
shipDrawn(); // calls ship drawn from Ship tab
shipMove();
stroke(3, 255, 290);
noFill();
rect(400, 300, 799, 599);
translate(0, 30);// start point
for (int i = 0; i <18; i++) {
drawColumn(i);
}
if ((frameCount % 40) == 0) { // sets speed of row movement
for (int i=invaderBox.length-2; i>=0; i–) {
invaderBox[i+1][0] =invaderBox[i][0]; // moves row 0 when frame rate is divisable by 20
invaderBox[i+1][1] =invaderBox[i][1];
invaderBox[i+1][2] =invaderBox[i][2];
invaderBox[i+1][3] =invaderBox[i][3];
invaderBox[i+1][4] =invaderBox[i][4];
}
}
}void drawColumn(int columnNum)// spacing between invaders
{
translate(columnNum*50, 0);//first translation moves us to the correct horizontal position, ready to draw the column
for (int i=0; i<invaderBox[columnNum].length; i++) { // calls column length as long as itl ess than array size
if (invaderBox[columnNum][i] == true) drawInvader();
translate(0, 50); // we have just drawn a invader, so translate down a bit, ready to draw the next invader below
}
translate(-columnNum*50, -invaderBox[columnNum].length*50); // undoes both of the previous translations so that origin is back at top left hand corner of window
}void mousePressed( ) {
// Your code goes in here !!!
}void keyPressed ( ) {
// Your code goes in here !!!
keyPressShip();
laserPressed ();
}


 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s