This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2012-02-25 11:55:34

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

transparent wrote:

veggieman001 wrote:

Code:

final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result;
float x,y,mx,my;
PImage imgTitle = loadImage("http://www.majhost.com/gallery/veggieman/requests/title.png");
PImage imgChar = loadImage("http://www.majhost.com/gallery/veggieman/requests/veggie.png");
PImage imgChar2 = loadImage("http://www.majhost.com/gallery/veggieman/requests/veggie2.png");
PImage imgMuffin = loadImage("http://www.majhost.com/gallery/veggieman/requests/muffin.png");
int nScreen = 0;
int nDirection = 0;
boolean bMuffin = false;
int nScore = 0;
int nTime = 60;
int nTimeCount;
PFont fntScore;

void setup() {
  size(640,480);
  frameRate(30);  
  result = 0;
  x = width/2;
  y = height/2;
  mx = width/2+50;
  my = height/2+50;
  background(imgTitle);
  //fntScore = loadFont("Arial");
}
 
void draw() {
  if (nScreen==1){
     if (nTime==0) {
       nScreen=2;
     }
  background(255,156,231);
  switch(result) {
    case NORTH: y-=ceil(nTime/6); break;
    case EAST: x+=ceil(nTime/6); nDirection=0; break;
    case SOUTH: y+=ceil(nTime/6); break;
    case WEST: x-=ceil(nTime/6); nDirection=1; break;
    case NORTH|EAST: y-=ceil(nTime/6); x+=ceil(nTime/6); nDirection=0; break;
    case NORTH|WEST: y-=ceil(nTime/6); x-=ceil(nTime/6); nDirection=1; break;
    case SOUTH|EAST: y+=ceil(nTime/6); x+=ceil(nTime/6); nDirection=0; break;
    case SOUTH|WEST: y+=ceil(nTime/6); x-=ceil(nTime/6); nDirection=1; break;
  }
  if (x<=49) x=49;
  if (x>=width-49) x=width-49;
  if (y<=59) y=59;
  if (y>=height-59) y=height-59;
  imageMode(CENTER);
  if (!bMuffin){
    mx = round(random(20,620));
    my = round(random(20,460));
    bMuffin=true;
  }
  image(imgMuffin,mx,my);
  if (nDirection==0) image(imgChar,x,y);
  if (nDirection==1) image(imgChar2,x,y);
  if (dist(x,y,mx,my)<=50){
    nScore+=(round(nTime/6)+5);
    bMuffin=false;
  } 
  if (nTimeCount != second()){
    nTime--;
    nTimeCount = second();
  }
 // textFont(fntScore,18);
//  text("Score: " + nScore, 5, 20);
  text("Time: " + nTime, 5, 20);
  }
  if (nScreen==2){
    background(255,255,0);
    textFont(fntScore,22);
    fill(0);
    text("Score: " + nScore, width/2-75, height/2);
  }
}
 
void keyPressed(){
  switch(key) {
    case('w'):case('W'):result |=NORTH;break;
    case('d'):case('D'):result |=EAST;break;
    case('s'):case('S'):result |=SOUTH;break;
    case('a'):case('A'):result |=WEST;break;
    case(' '): nScreen=1;nTimeCount=second();break;
  }
}
 
void keyReleased(){  
  switch(key) {
    case('w'):case('W'):result ^=NORTH;break;
    case('d'):case('D'):result ^=EAST;break;
    case('s'):case('S'):result ^=SOUTH;break;
    case('a'):case('A'):result ^=WEST;break;
  }
}

void mousePressed(){
 if((mouseX>width/2-50)&&(mouseX<width/2+50)){
   if((mouseY>height/2+20)&&(mouseY<height/2+70)){
     nScreen=0;
   }
 }
}

Javascript? Yeah.

Javascript? No...
Though it can be implemented in


Posts: 20000 - Show all posts

Offline

 

#27 2012-02-25 11:59:14

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

Processing?  tongue


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#28 2012-02-25 11:59:47

transparent
Scratcher
Registered: 2011-04-19
Posts: 1000+

Re: Creating Code

veggieman001 wrote:

transparent wrote:

veggieman001 wrote:

Code:

final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result;
float x,y,mx,my;
PImage imgTitle = loadImage("http://www.majhost.com/gallery/veggieman/requests/title.png");
PImage imgChar = loadImage("http://www.majhost.com/gallery/veggieman/requests/veggie.png");
PImage imgChar2 = loadImage("http://www.majhost.com/gallery/veggieman/requests/veggie2.png");
PImage imgMuffin = loadImage("http://www.majhost.com/gallery/veggieman/requests/muffin.png");
int nScreen = 0;
int nDirection = 0;
boolean bMuffin = false;
int nScore = 0;
int nTime = 60;
int nTimeCount;
PFont fntScore;

void setup() {
  size(640,480);
  frameRate(30);  
  result = 0;
  x = width/2;
  y = height/2;
  mx = width/2+50;
  my = height/2+50;
  background(imgTitle);
  //fntScore = loadFont("Arial");
}
 
void draw() {
  if (nScreen==1){
     if (nTime==0) {
       nScreen=2;
     }
  background(255,156,231);
  switch(result) {
    case NORTH: y-=ceil(nTime/6); break;
    case EAST: x+=ceil(nTime/6); nDirection=0; break;
    case SOUTH: y+=ceil(nTime/6); break;
    case WEST: x-=ceil(nTime/6); nDirection=1; break;
    case NORTH|EAST: y-=ceil(nTime/6); x+=ceil(nTime/6); nDirection=0; break;
    case NORTH|WEST: y-=ceil(nTime/6); x-=ceil(nTime/6); nDirection=1; break;
    case SOUTH|EAST: y+=ceil(nTime/6); x+=ceil(nTime/6); nDirection=0; break;
    case SOUTH|WEST: y+=ceil(nTime/6); x-=ceil(nTime/6); nDirection=1; break;
  }
  if (x<=49) x=49;
  if (x>=width-49) x=width-49;
  if (y<=59) y=59;
  if (y>=height-59) y=height-59;
  imageMode(CENTER);
  if (!bMuffin){
    mx = round(random(20,620));
    my = round(random(20,460));
    bMuffin=true;
  }
  image(imgMuffin,mx,my);
  if (nDirection==0) image(imgChar,x,y);
  if (nDirection==1) image(imgChar2,x,y);
  if (dist(x,y,mx,my)<=50){
    nScore+=(round(nTime/6)+5);
    bMuffin=false;
  } 
  if (nTimeCount != second()){
    nTime--;
    nTimeCount = second();
  }
 // textFont(fntScore,18);
//  text("Score: " + nScore, 5, 20);
  text("Time: " + nTime, 5, 20);
  }
  if (nScreen==2){
    background(255,255,0);
    textFont(fntScore,22);
    fill(0);
    text("Score: " + nScore, width/2-75, height/2);
  }
}
 
void keyPressed(){
  switch(key) {
    case('w'):case('W'):result |=NORTH;break;
    case('d'):case('D'):result |=EAST;break;
    case('s'):case('S'):result |=SOUTH;break;
    case('a'):case('A'):result |=WEST;break;
    case(' '): nScreen=1;nTimeCount=second();break;
  }
}
 
void keyReleased(){  
  switch(key) {
    case('w'):case('W'):result ^=NORTH;break;
    case('d'):case('D'):result ^=EAST;break;
    case('s'):case('S'):result ^=SOUTH;break;
    case('a'):case('A'):result ^=WEST;break;
  }
}

void mousePressed(){
 if((mouseX>width/2-50)&&(mouseX<width/2+50)){
   if((mouseY>height/2+20)&&(mouseY<height/2+70)){
     nScreen=0;
   }
 }
}

Javascript? Yeah.

Javascript? No...
Though it can be implemented in

Oh goodness. How did I not notice the first part.
Course that's not javascript.


yes, yes i do.

Offline

 

#29 2012-02-25 12:02:18

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

slinger wrote:

Processing?  tongue

yeah


Posts: 20000 - Show all posts

Offline

 

#30 2012-02-25 12:02:51

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

Sweet :3 I'll post some pascal soon  smile


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#31 2012-02-25 12:04:27

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

Random calculator I dug up, really easy to make but whatev.

Code:

program Calculator;

{$mode objfpc}{$H+}

uses

  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}
var
  x:char; //Confim at end
  i1:integer; //Input 1
  o:char; // Operation
  i2:integer; // Input 2

procedure CloseProgram;
begin
  writeln;
  writeln;
  writeln('Press <Enter> to quit');
  readln;
end;

begin
  repeat
    write('First number: ');
    readln(i1);
    write('Opperation: ');
    readln(o);
    write('Secound number: ');
    readln(i2);
    if o = '+' then
      writeln('The answer is ', i1 + i2)
    else if o = '-' then
      writeln('The answer is ', i1 - i2)
    else if o = '*' then
      writeln('The answer is ', i1 * i2)
    else if o = '/' then
      writeln('The answer is ', i1 / i2);
    write('Do you want to use this again (Y,N) ');
    readln(x);


  until x = 'N';

  CloseProgram;
end.

http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#32 2012-02-25 12:12:27

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

you spelt operation wrong  tongue


Posts: 20000 - Show all posts

Offline

 

#33 2012-02-25 12:15:30

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

As I said, old project  tongue


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#34 2012-02-25 12:18:10

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

pascal looks complicated


Posts: 20000 - Show all posts

Offline

 

#35 2012-02-25 12:20:51

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

Ahh not really, it's easier than C or C++ but as powerful than them  smile
The lazarus IDE is beautiful, it's so easy to get stuff done  big_smile
Anyway look at the code like this (the rest was auto added)

Code:

var //the variables
  x:char; //Confim at end
  i1:integer; //Input 1
  o:char; // Operation
  i2:integer; // Input 2

procedure CloseProgram; //procedure
begin
  writeln;
  writeln;
  writeln('Press <Enter> to quit');
  readln;
end;

begin  //the program
  repeat
    write('First number: ');
    readln(i1);
    write('Opperation: ');
    readln(o);
    write('Secound number: ');
    readln(i2);
    if o = '+' then
      writeln('The answer is ', i1 + i2)
    else if o = '-' then
      writeln('The answer is ', i1 - i2)
    else if o = '*' then
      writeln('The answer is ', i1 * i2)
    else if o = '/' then
      writeln('The answer is ', i1 / i2);
    write('Do you want to use this again (Y,N) ');
    readln(x);


  until x = 'N';

  CloseProgram;
end.

Last edited by slinger (2012-02-25 12:21:30)


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#36 2012-02-25 15:53:35

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

Code:

String word = "cutmeup";
String[] clist = new String[word.length()*4-4];
String firsthalf;
String secondhalf;

void setup(){
  for (int i = 1; i-1 < word.length()-1; i++){
    firsthalf = word.substring(0,i);
    secondhalf = word.substring(i,word.length());
    clist[i-1] = firsthalf+"[b][/b]"+secondhalf;
  }
  for (int j = 1; j-1 < word.length()-1; j++){
    firsthalf = word.substring(0,j);
    secondhalf = word.substring(j,word.length());
    clist[j+word.length()-2] = firsthalf+"[i][/i]"+secondhalf;
  }
  for (int k = 1; k-1 < word.length()-1; k++){
    firsthalf = word.substring(0,k);
    secondhalf = word.substring(k,word.length());
    clist[k+word.length()*2-3] = firsthalf+"[u][/u]"+secondhalf;
  }
    for (int m = 1; m-1 < word.length()-1; m++){
    firsthalf = word.substring(0,m);
    secondhalf = word.substring(m,word.length());
    clist[m+word.length()*3-4] = firsthalf+"[url][/url]"+secondhalf;
  }
  println(clist);
  saveStrings("censorlist.txt",clist);
}

here is some processing i wrote just a moment ago
it goes through a word and creates a list of all the things like wh[b][/b]at (censor workarounds) which could be used for making a censor list on fluxbb forums

it does have a few flaws like no blocking of multiples and the impossible color tag


Posts: 20000 - Show all posts

Offline

 

#37 2012-02-25 16:46:04

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Creating Code

Cool! So that's Processing, eh? I  thought it looked like Java, but there is no main method.  hmm


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#38 2012-02-25 17:45:43

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

it's based off of java (and usually compiles to it) but is meant to be more simplistic and easier to do visuals with

and yeah there's no main but there's setup and draw which are called at the beginning and repeatedly respectively


Posts: 20000 - Show all posts

Offline

 

#39 2012-02-25 18:42:40

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Creating Code

ssss wrote:

nathanprocks wrote:

rdococ wrote:

Codes? Huh? Did you mean Code? I understand why you said Codes, but there's no plural to Code. "Code" is used no matter how much code there is.

Well, I'm making a chat in Command Prompt (EDIT.exe)! I won't post the code yet, because it's unfinished. But I will post it any time soon.

Command Prompt is cmd.exe not EDIT.exe... EDIT.exe is the MS-DOS text editor. Lol.

well edit.exe is actually a batch program  hmm   smile

. . . Then shouldn't it be edit.bat?

Offline

 

#40 2012-02-25 19:18:30

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: Creating Code

I made this when I was still obsessed of making batch scripts with Paddle in it.

Code:

@echo off
title PADDLE
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)

call :ColorText 74 "Out in the wild.... there is something..... "
ping localhost > nul
echo.
call :ColorText 74 "called..... "
ping localhost > nul
echo.
call :ColorText 0e "Paddle"
echo.
call :ColorText 0e "2"
echo.
call :ColorText 0e "See"
ping localhost > nul
echo.
echo Programmed by cocolover76. DO NOT EXIT YET.
ping localhost > nul
start http://i39.tinypic.com/2nav6o7.gif
echo Moo. You can exit now.
:g
goto g
goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#41 2012-02-25 19:19:42

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: Creating Code

maxskywalker wrote:

ssss wrote:

nathanprocks wrote:

Command Prompt is cmd.exe not EDIT.exe... EDIT.exe is the MS-DOS text editor. Lol.

well edit.exe is actually a batch program  hmm   smile

. . . Then shouldn't it be edit.bat?

It's edit.com.
NOT a website, a program.

Last edited by cocolover76 (2012-02-25 19:20:10)


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#42 2012-02-25 20:22:21

what-the
Scratcher
Registered: 2009-10-04
Posts: 1000+

Re: Creating Code

Who knows what this does and is from?

Code:

void setup() {                
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   
  delay(1000);              
  digitalWrite(13, LOW);    
  delay(1000);              
}

I love using this software it just makes things come to life.


http://imageshack.us/m/64/9034/ddfss.pngMy site
Find someone post count. Click posts under username. Find number of pages. Times that by 40 for min and 60 for max and you have a rough estimate of post count.

Offline

 

#43 2012-02-26 01:13:37

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

veggieman001 wrote:

Code:

String word = "cutmeup";
String[] clist = new String[word.length()*4-4];
String firsthalf;
String secondhalf;

void setup(){
  for (int i = 1; i-1 < word.length()-1; i++){
    firsthalf = word.substring(0,i);
    secondhalf = word.substring(i,word.length());
    clist[i-1] = firsthalf+"[b][/b]"+secondhalf;
  }
  for (int j = 1; j-1 < word.length()-1; j++){
    firsthalf = word.substring(0,j);
    secondhalf = word.substring(j,word.length());
    clist[j+word.length()-2] = firsthalf+"[i][/i]"+secondhalf;
  }
  for (int k = 1; k-1 < word.length()-1; k++){
    firsthalf = word.substring(0,k);
    secondhalf = word.substring(k,word.length());
    clist[k+word.length()*2-3] = firsthalf+"[u][/u]"+secondhalf;
  }
    for (int m = 1; m-1 < word.length()-1; m++){
    firsthalf = word.substring(0,m);
    secondhalf = word.substring(m,word.length());
    clist[m+word.length()*3-4] = firsthalf+"[url][/url]"+secondhalf;
  }
  println(clist);
  saveStrings("censorlist.txt",clist);
}

here is some processing i wrote just a moment ago
it goes through a word and creates a list of all the things like wh[b][/b]at (censor workarounds) which could be used for making a censor list on fluxbb forums

it does have a few flaws like no blocking of multiples and the impossible color tag

Very awesome  smile


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#44 2012-02-26 01:46:18

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Creating Code

slinger wrote:

veggieman001 wrote:

Code:

String word = "cutmeup";
String[] clist = new String[word.length()*4-4];
String firsthalf;
String secondhalf;

void setup(){
  for (int i = 1; i-1 < word.length()-1; i++){
    firsthalf = word.substring(0,i);
    secondhalf = word.substring(i,word.length());
    clist[i-1] = firsthalf+"[b][/b]"+secondhalf;
  }
  for (int j = 1; j-1 < word.length()-1; j++){
    firsthalf = word.substring(0,j);
    secondhalf = word.substring(j,word.length());
    clist[j+word.length()-2] = firsthalf+"[i][/i]"+secondhalf;
  }
  for (int k = 1; k-1 < word.length()-1; k++){
    firsthalf = word.substring(0,k);
    secondhalf = word.substring(k,word.length());
    clist[k+word.length()*2-3] = firsthalf+"[u][/u]"+secondhalf;
  }
    for (int m = 1; m-1 < word.length()-1; m++){
    firsthalf = word.substring(0,m);
    secondhalf = word.substring(m,word.length());
    clist[m+word.length()*3-4] = firsthalf+"[url][/url]"+secondhalf;
  }
  println(clist);
  saveStrings("censorlist.txt",clist);
}

here is some processing i wrote just a moment ago
it goes through a word and creates a list of all the things like wh[b][/b]at (censor workarounds) which could be used for making a censor list on fluxbb forums

it does have a few flaws like no blocking of multiples and the impossible color tag

Very awesome  smile

thank you sir


Posts: 20000 - Show all posts

Offline

 

#45 2012-02-26 04:05:55

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

what-the wrote:

Who knows what this does and is from?

Code:

void setup() {                
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   
  delay(1000);              
  digitalWrite(13, LOW);    
  delay(1000);              
}

I love using this software it just makes things come to life.

Hmm, java?
And no I have absolutely no idea what that does other than delay 1000 ticks and write something  tongue
Is it from a digital clock? :p


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#46 2012-02-26 08:03:18

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

Really old AI chat bot I just fixed up, it's called "learnbot".

Code:

program LearnBot;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}
procedure spacer;  // creates a space
begin
  writeln;
  writeln;
end;
procedure intro;  // feel free to edit :P
begin
  writeln('LearnBot is currently under development by Slinger.');
end;
procedure instructions;
begin
  writeln('This is LearnBot a chatbot AI.');
  writeln('Type "teach" to teach me something and type "wipe" to clear my memory');
  writeln('Press <Enter> to continue');
  readln;
end;
var
  command: string;
  wipe: integer;
  teachLoop: integer;
  lookUpLoop: integer;
  phraseMemory: array[1..100] of string;
  responseMemory: array[1..100] of string;

begin
  intro;
  spacer;
  instructions;
  spacer;
  teachLoop := 1;
  repeat
    write('Command: ');
    readln(command);

    if command = 'wipe' then  //wipes the memory
      begin
        wipe := 1;
        repeat
          phraseMemory[wipe] := '';
          responseMemory[wipe] := '';
          wipe := wipe + 1;

        until wipe > 100 ;
        writeln('Memory wiped.');
        teachLoop := 1;

      end;

    if command = 'teach' then
      begin
      write('Teach me what? ');
      readln(phraseMemory[teachLoop]);
      write('How should I respond? ');
      readln(responseMemory[teachLoop]);
      writeln;
      teachLoop := teachLoop + 1;

      end
    else
      begin

        lookUpLoop := 0;
        repeat
          lookUpLoop := lookUpLoop + 1;
        until (command = phraseMemory[lookUpLoop]) or (lookUpLoop > 101);
        writeln(responseMemory[lookUpLoop]);
      end;


  until command = 'done';

end.

If you want the program it's on sourceforge (the fixed up one) right here.

Last edited by slinger (2012-02-26 08:03:45)


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#47 2012-02-26 08:25:10

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Creating Code

Code:

import java.util.Random;
import java.util.Scanner;
import java.io.*;

public class philosoraptor {
    static boolean running = true;
    
    public static void main(String args[]){
        init();
        
        Scanner scan = new Scanner(System.in);
        String command;
        while(running){
            command = scan.nextLine();
            if (command.equals("quote")){
                getquote();
            }
            if (command.equals("close")){
                running = false;
            }
        }
        
    }
    
    static int lines = 0;
    
    public static void init(){

        FileInputStream fileCheck = null;
        try {
            fileCheck = new FileInputStream("philosoraptor.txt");
        } catch (FileNotFoundException e) {
            System.out.println("Error finding file");
        }
        boolean getlines = true;
        while(getlines){
            try{
                String line = new DataInputStream(fileCheck).readLine();
                lines++;
                if (line == null){
                    getlines = false;
                }
            }
            catch(IOException x){
                getlines = false;
            }
        }
        lines--;
        System.out.println("Loaded philosoraptor.txt with " + lines + " lines of text!");
        
        
    }
    

    static String quote;
    public static void getquote() {
        Random rand = new Random();
        
        int count = 0;
        int place = rand.nextInt(lines);
        FileInputStream fileIn;
            try{
                fileIn = new FileInputStream ("philosoraptor.txt");
                while(count <= place){
                    quote = new DataInputStream(fileIn).readLine();
                    count++;
                }
                
            fileIn.close();
            }
            catch(IOException e){
                System.out.println("Philosoraptor is confuzzled.");
            }
            
            System.out.println(quote);
    }

}

This is the code for my Philosoraptor program  big_smile  Here is the txt file, the .java file, and the .class file. If you just want to see it work, download the .class file into the same folder as the txt. Then just run it from command line, or with a batch script

Code:

java philosoraptor

http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#48 2012-02-26 08:25:34

what-the
Scratcher
Registered: 2009-10-04
Posts: 1000+

Re: Creating Code

slinger wrote:

what-the wrote:

Who knows what this does and is from?

Code:

void setup() {                
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   
  delay(1000);              
  digitalWrite(13, LOW);    
  delay(1000);              
}

I love using this software it just makes things come to life.

Hmm, java?
And no I have absolutely no idea what that does other than delay 1000 ticks and write something  tongue
Is it from a digital clock? :p

Yes it is Java. It's used to program a micro-controller, in this case an ATmega on an Arduino board. That will make pin 13 which has an LED connected to it, flash on and off.
So when I said "it just make things come to life" I meant it literately.


http://imageshack.us/m/64/9034/ddfss.pngMy site
Find someone post count. Click posts under username. Find number of pages. Times that by 40 for min and 60 for max and you have a rough estimate of post count.

Offline

 

#49 2012-02-26 08:33:54

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Creating Code

Cool  smile

16Skittles wrote:

Code:

import java.util.Random;
import java.util.Scanner;
import java.io.*;

public class philosoraptor {
    static boolean running = true;
    
    public static void main(String args[]){
        init();
        
        Scanner scan = new Scanner(System.in);
        String command;
        while(running){
            command = scan.nextLine();
            if (command.equals("quote")){
                getquote();
            }
            if (command.equals("close")){
                running = false;
            }
        }
        
    }
    
    static int lines = 0;
    
    public static void init(){

        FileInputStream fileCheck = null;
        try {
            fileCheck = new FileInputStream("philosoraptor.txt");
        } catch (FileNotFoundException e) {
            System.out.println("Error finding file");
        }
        boolean getlines = true;
        while(getlines){
            try{
                String line = new DataInputStream(fileCheck).readLine();
                lines++;
                if (line == null){
                    getlines = false;
                }
            }
            catch(IOException x){
                getlines = false;
            }
        }
        lines--;
        System.out.println("Loaded philosoraptor.txt with " + lines + " lines of text!");
        
        
    }
    

    static String quote;
    public static void getquote() {
        Random rand = new Random();
        
        int count = 0;
        int place = rand.nextInt(lines);
        FileInputStream fileIn;
            try{
                fileIn = new FileInputStream ("philosoraptor.txt");
                while(count <= place){
                    quote = new DataInputStream(fileIn).readLine();
                    count++;
                }
                
            fileIn.close();
            }
            catch(IOException e){
                System.out.println("Philosoraptor is confuzzled.");
            }
            
            System.out.println(quote);
    }

}

This is the code for my Philosoraptor program  big_smile  Here is the txt file, the .java file, and the .class file. If you just want to see it work, download the .class file into the same folder as the txt. Then just run it from command line, or with a batch script

Code:

java philosoraptor

.jar available? :p


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#50 2012-02-26 08:37:56

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Creating Code

slinger wrote:

Cool  smile

16Skittles wrote:

Code:

import java.util.Random;
import java.util.Scanner;
import java.io.*;

public class philosoraptor {
    static boolean running = true;
    
    public static void main(String args[]){
        init();
        
        Scanner scan = new Scanner(System.in);
        String command;
        while(running){
            command = scan.nextLine();
            if (command.equals("quote")){
                getquote();
            }
            if (command.equals("close")){
                running = false;
            }
        }
        
    }
    
    static int lines = 0;
    
    public static void init(){

        FileInputStream fileCheck = null;
        try {
            fileCheck = new FileInputStream("philosoraptor.txt");
        } catch (FileNotFoundException e) {
            System.out.println("Error finding file");
        }
        boolean getlines = true;
        while(getlines){
            try{
                String line = new DataInputStream(fileCheck).readLine();
                lines++;
                if (line == null){
                    getlines = false;
                }
            }
            catch(IOException x){
                getlines = false;
            }
        }
        lines--;
        System.out.println("Loaded philosoraptor.txt with " + lines + " lines of text!");
        
        
    }
    

    static String quote;
    public static void getquote() {
        Random rand = new Random();
        
        int count = 0;
        int place = rand.nextInt(lines);
        FileInputStream fileIn;
            try{
                fileIn = new FileInputStream ("philosoraptor.txt");
                while(count <= place){
                    quote = new DataInputStream(fileIn).readLine();
                    count++;
                }
                
            fileIn.close();
            }
            catch(IOException e){
                System.out.println("Philosoraptor is confuzzled.");
            }
            
            System.out.println(quote);
    }

}

This is the code for my Philosoraptor program  big_smile  Here is the txt file, the .java file, and the .class file. If you just want to see it work, download the .class file into the same folder as the txt. Then just run it from command line, or with a batch script

Code:

java philosoraptor

.jar available? :p

You can run the .class file, but I'm looking into how to make it a jar.
Also, you SHOULD be able to add an unlimited amount of quotes to philosoraptor.txt and it will automatically detect them, although it is horribly inefficient and will take longer to load and longer to read the more quotes there are.  tongue

Edit: I can't seem to get the command line window to appear when I use the .jar. Also, it just seems like a waste since there is only one class.

Last edited by 16Skittles (2012-02-26 08:43:10)


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

Board footer