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

#1 2012-02-25 04:27:06

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

Creating Code

Post any type of program code you have created. Just don't make it over 500lines :3
edit: I'll post my code as soon as I have time to create a program  tongue
edit2: Please make your code only command code (idk what it's called). No gui. Plus it would be cool to see something like mathematical stuff :3
As paddle2see pointed out my original post was really broad, i have now narrowed it down.

Last edited by slinger (2012-02-26 09:49:43)


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

Offline

 

#2 2012-02-25 04:54:54

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Creating Code

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.

Offline

 

#3 2012-02-25 05:37:42

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Creating Code

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.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#4 2012-02-25 05:42:56

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Creating Code

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.

I know -- I am making it in the MS-DOS text editor.

Offline

 

#5 2012-02-25 05:56:08

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Creating Code

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


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#6 2012-02-25 05:58:01

rdococ
Scratcher
Registered: 2009-10-11
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

Yeah -- I'm using a batch program to make a batch program.

Offline

 

#7 2012-02-25 05:59:18

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Creating Code

rdococ 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

Yeah -- I'm using a batch program to make a batch program.

I attempted to make a chat script in batch but I epic failed.  tongue


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#8 2012-02-25 06:00:28

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Creating Code

nathanprocks wrote:

rdococ wrote:

ssss wrote:


well edit.exe is actually a batch program  hmm   smile

Yeah -- I'm using a batch program to make a batch program.

I attempted to make a chat script in batch but I epic failed.  tongue

Actually, mine does not connect, it's just a chat BOT.

Offline

 

#9 2012-02-25 06:18:54

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Creating Code

rdococ wrote:

nathanprocks wrote:

rdococ wrote:


Yeah -- I'm using a batch program to make a batch program.

I attempted to make a chat script in batch but I epic failed.  tongue

Actually, mine does not connect, it's just a chat BOT.

hehehe.   chat bots are difficult  cool

I would know.


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#10 2012-02-25 06:25:01

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

Re: Creating Code

Yeah they are :L
Unless you teach it everything on the go while running the program.
Otherwise you have to get it to understand and parse sentences  tongue

Last edited by slinger (2012-02-25 06:33:16)


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

Offline

 

#11 2012-02-25 08:19:03

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Creating Code

The way you have this defined is really too broad!  People can write code that do just about anything on a computer.  Can you narrow it down to a particular interest of some sort, say a specific language, or a particular kind of coding that you are interested in?  And it would be great if you could start with an example of your own  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#12 2012-02-25 08:20:53

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

Re: Creating Code

Ok, sure  smile  I'll edit my post now.


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

Offline

 

#13 2012-02-25 08:54:49

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Creating Code

Just a quick little java snippet. Even if you don't know java syntax, it should be obvious what it does.  tongue

Move.java

Code:

import java.awt.AWTException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;


public class Move {
    static Robot r;
    static int x = 1000;
    static int rad = 100;
    
    static float i = 0;
    public static void main(String[] args) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice d = ge.getDefaultScreenDevice();
        int h = d.getDefaultConfiguration().getBounds().height;
        int w = d.getDefaultConfiguration().getBounds().width;
        try {
            r = new Robot();
        } catch (AWTException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        while (i < x){
            i = (float) (i+0.1);
            r.delay(1);
            r.mouseMove((int)(Math.sin(Math.toRadians(i))*rad)+(w/2), (int)(Math.cos(Math.toRadians(i))*rad)+(h/2));
        }
    }
}

http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#14 2012-02-25 08:56:20

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

Re: Creating Code

It moves the robot, cool  smile  I'm planning on learning java for school next year  smile


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

Offline

 

#15 2012-02-25 09:09:15

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Creating Code

slinger wrote:

It moves the robot, cool  smile  I'm planning on learning java for school next year  smile

Not exactly... the robot moves the mouse around in a circle in the center of the screen.  tongue
CURSE YOU 60 SECOND RULE!


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#16 2012-02-25 09:23:32

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

Re: Creating Code

VB.net code to receive data from Scratch when in Mesh.

Code:

Imports System.Net.Sockets
Imports System.Text
Module Module1
    Sub Main()
        For value As Integer = 0 To 50
            Dim tcpClient As New System.Net.Sockets.TcpClient()
            tcpClient.Connect("127.0.0.1", 42001)
            Dim networkStream As NetworkStream = tcpClient.GetStream()
            If networkStream.CanWrite And networkStream.CanRead Then
                ' Do a simple write.
                Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
                'networkStream.Write(sendBytes, 0, sendBytes.Length)
                ' Read the NetworkStream into a byte buffer.
                Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                ' Output the data received from the host to the console.

                Dim returndata As String = Encoding.ASCII.GetString(bytes)
                Console.WriteLine(("Host returned: " + returndata))
            Else
                If Not networkStream.CanRead Then
                    Console.WriteLine("cannot not write data to this stream")
                    tcpClient.Close()
                Else
                    If Not networkStream.CanWrite Then
                        Console.WriteLine("cannot read data from this stream")
                        tcpClient.Close()
                    End If
                End If
            End If
           
            Threading.Thread.Sleep(4000)
        Next
    End Sub
End Module

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

 

#17 2012-02-25 09:24:46

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

Re: Creating Code

Nice  smile  That would be useful :3


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

Offline

 

#18 2012-02-25 09:34:15

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: Creating Code

Some C code for finding the fibonacci pattern. I used it for this scratch project.

Code:

#include <stdio.h>
double getNextNumber(double lastNumber, double lastLastNumber)
{
    double newNumber = lastNumber + lastLastNumber;
    return newNumber;
}

void fibonacci(int length)
{
    double lastNumber = 1;
    double lastLastNumber = -1;
    double nextNumber = 0;
    int i = 0;
    while(i < (length + 1))
    {
        nextNumber = getNextNumber(lastNumber, lastLastNumber);
        int tempLastNumber = nextNumber;
        lastLastNumber = lastNumber;
        lastNumber = tempLastNumber;
        printf("%G\n", nextNumber);
        i++;
    }
    return;
}

int main()
{
    fibonacci(30);
    return 0;
}

Output:

Console wrote:

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040

And surface area of a cylinder code:

Code:

#include <stdio.h>

#define PI 3.14
int main()
{
    float diameter;
    float height;
    float radius;
    float surfaceArea;
    
    printf("Please enter a diameter: ");
    scanf("%f", &diameter);
    printf("Please enter a height: ");
    scanf("%f", &height);
    
    radius = diameter/2;
    //Surface Area of a cylinder is 2PIr^2 + 2PIrh
    surfaceArea = (2 * PI * (radius * radius)) + (2 * PI * radius * height);
    printf("\nDiamater is %f, and height is %f\n", diameter, height);
    printf("\nSurface Area is %.3f\n", surfaceArea);
    return 0;
}

And extremely simple C code (try to figure this out  tongue )

Code:

#include <stdio.h>

int main()
{
    printf("Hello World!\n");
    return 0;
}

Last edited by gbear605 (2012-02-25 09:48:05)


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#19 2012-02-25 09:57:12

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

Re: Creating Code

hmm I don't know what that code does, lol!
I'm working on a "Words with Philosoraptor" program that retrieves a random quote and then outputs it  smile  I just need more quotes now, lol.


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

Offline

 

#20 2012-02-25 10:03:22

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

Re: Creating Code

Lol :p


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

Offline

 

#21 2012-02-25 11:36:50

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

Re: Creating Code

Woot, I made it now so that it can use ANY length of text file perfectly! It uses a loop to check how many lines are in the file, then outputs it.


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

Offline

 

#22 2012-02-25 11:43:06

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

Re: Creating Code

Nice  smile  That's great  big_smile


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

Offline

 

#23 2012-02-25 11:48:53

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

Re: Creating Code

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;
   }
 }
}

Posts: 20000 - Show all posts

Offline

 

#24 2012-02-25 11:49:47

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

Re: Creating Code

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.


yes, yes i do.

Offline

 

#25 2012-02-25 11:53:08

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

Re: Creating Code

Looks like it  tongue


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

Offline

 

Board footer