Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Munchor

Pages: 1 ... 6 7 [8] 9 10 ... 20
106
TI-BASIC / How to get the most repeated value in a list?
« on: May 25, 2011, 09:43:50 am »
So I was learning statistics and when I do 1-Var Stats in the 83+ Series I can't seem to get the most repeated value in a sequence.

We call it "moda" in my language, which means "fashion", so not sure if you have a special name.

So I thought of making a TI-Basic program for it, but I have no idea of how to get the number of elements in a list nor how to do the thing actually.

I really have *no idea* of how to code it, do you guys have any idea?

How it'd look:

Code: [Select]
WHAT LIST?
1
THE MOST REPEATED VALUE IS 10

An example of L1 here would be:

Code: [Select]
10
10
9
8
7
9
10

Thanks a lot!

107
Computer Programming / [Java] Key Events and Multiple Classes
« on: May 24, 2011, 08:13:35 am »
I have two files:

Squared.java
Code: [Select]
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

public class Squared {
JFrame mainFrame = new JFrame("Squared");
public int x = 5;
public int y = 5;
public boolean canRunConstructor = true;

public static void main (String[] args)
{
Squared mySquared = new Squared();
mySquared.Draw();
}
public Squared()
{
// TODO Constructors
}
public void Draw()
{
canRunConstructor = false;
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(480,320);
mainFrame.getContentPane().setLayout(null);
KeyEvents keyEvents = new KeyEvents();
mainFrame.addKeyListener(keyEvents);

BufferedImage img = null;
try {
img = ImageIO.read(new File("bin/block.png"));
} catch (IOException e) {
e.printStackTrace();
}
JLabel picLabel = new JLabel(new ImageIcon( img ));
picLabel.setBounds(x,y,40,40);

mainFrame.add(picLabel);

mainFrame.setVisible(true);
}
}

KeyEvents.java
Code: [Select]
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class KeyEvents implements KeyListener {

@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 39) //Right key
{
Squared mySquared = new Squared();
mySquared.x = mySquared.x + 5;
mySquared.mainFrame.repaint();
}
System.out.println(e.getKeyCode());
}

@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub

}

@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub

}

}

What i'm trying to do is when I press <RIGHT> in the keyboard, the block moves right, any idea what's wrong? I can't detailedly explain my code now.

108
Computer Programming / Java Accessing Image Problem
« on: May 23, 2011, 04:48:42 pm »
Code: [Select]
import javax.swing.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

public class Squared {
public static void main (String[] args)
{
Squared mySquared = new Squared();
}
public Squared()
{
Draw();
}
public void Draw()
{
JFrame mainFrame = new JFrame("Squared");
mainFrame.setSize(480,320);


BufferedImage img = null;
try {
img = ImageIO.read(new File("block.png"));
} catch (IOException e) {
e.printStackTrace();
}

JLabel picLabel = new JLabel(new ImageIcon( img ));
mainFrame.add(picLabel);

mainFrame.setVisible(true);
}
}

I have file named "Squared.java" and an image called "block.png" in the same folder and in the same package (using Eclipse); I get this:

Code: [Select]
javax.imageio.IIOException: Can't read input file!
Why can't it get the file, it's in the same directory. Thanks :)

109
Axe / Axe Bullets
« on: May 20, 2011, 07:41:12 pm »
First of all, I shall explain why this isn't in the Axe Q&A topic. It's because this is something harder and that I need an explanation but not just for me, I think everybody can benefit if anyone can teach me this.

Code: [Select]
.A
0->Y->B->X->A
ClrDraw^^r
[38283B123C501028]->Pic1A
[1C14DC483C0A0814]->Pic1B

Repeat getKey(15)
  ClrDraw
  Pic1A->O 

  If getKey(3)
    Pic1A->O
  End

  If getKey(2)
    Pic1B->O
  End

  Pt-On(X/256,Y/256,O
  DispGraph
End

I had this code, and I wanted to implement bullets. This is what I used to do:

Code: [Select]
If getKey(54)
  Pxl-On(X+8,Y+2)^r
End
.CODE
Horizontal -^r

This is quite a dirty hack because this way bullets can only go to the right.

However, let's say one needs to make bullets for both sides. What code have you guys written for this before?

(This is more a sort of a discussion)

110
Axe / Physics Introduction Axe Tutorial
« on: May 20, 2011, 11:31:21 am »
One of the things that I could never understand in Axe was acceleration/velocity and physics. And although everybody kept saying Builderboy's tutorials were the best for the job, I thought they were too advanced for me when I read them. When I read Axe Physics tutorials I was confused. Of course the tutorials were great, but just not for a true beginner.

All of my games were always non-realistic, without acceleration and using simple code and lots of dirty hacks. The other I finally understood acceleration and physics, and decided to write this very simple tutorial for the job.

Also, you may note most of the code in this tutorial is not optimized so you can understand it better.

Let's start with displaying an image and gravity:

Code: [Select]
.Y Position of the block
0→Y
.X Position of the block
44→X

Repeat getKey(15)
  ClrDraw

  .Draw a line at the bottom
  Line(0,63,95,63)

  .Draw our main image, a square of width=8
  Rect(X,Y,8,8

  !If (pxl-Test(X+3,Y+8))
    Y+1→Y
  End

  DispGraph
End

Irrealistic Gravity

This code draws a square and it will fall down vertically (gravity) until it hits the line. However, this code is not realistic. If you're surprised, don't worry, it's easy to get.

When an object falls down from, let's say, the top of a building, it will fall down vertically and it's speed will increase. So, the highest speed reached is higher if you throw it from a higher building. Newton calls this speed 'gravitational acceleration'.

So how to make this realistic? We will need a variable for the acceleration and a variable for the Y position of the sprite, so we don't change the Y position of the sprite directly, but add to its speed.

Now the next code uses the Fixed Point or as I prefer the x256 mode. We multiply the X and Y positions of stuff by 256 to get more precision. So if in the code I write X+1→X I'm adding 1/256 of a pixel to X. If you ever had the need to move a sprite/block to the right but not so fast as X+1→X then you can use the x256 mode. It's very important in Axe Physics.

To display sprites we write lines such as Pt-On(X/256,Y/256,PTR. So when we display them, we divide their positions by 256 to fit on the graphscreen. Functions like pxl-Test also require us to divide variables by 256 (if we're using the x256 mode).

Here's how it works to check if a pixel is black:

Code: [Select]
.X And Y Positions as pxl-Test( arguments
If (pxl-Test(X/256,Y/256))
  .CODE
End

Now here's some code that you can use as an example of acceleration and the x256 mode.

Code: [Select]
.Y Position of the block
0→Y
.Y Acceleration of the block
0→B
.X Position of the block
0→X

Repeat getKey(15)
  ClrDraw

  .Draw a line at the bottom
  Line(0,63,95,63)

  .Draw our main image, a square of width=8
  Rect(X/256,Y/256,8,8)

  .If nothing beneath block, make block go down
  !If (pxl-Test(X/256+3,Y/256+8))
    B+4→B
  End

  .If something beneath block, make block stop
  If (pxl-Test(X/256+3,Y/256+8))
    0→B
  End

  Y+B→Y

  DispGraph
End

More realistic gravity

As you can see, the speed of the block in this code gets higher and higher. However, if it hits the line, it immediately stops.

Now there's a very important concept you need to understand. Vectors and Components of Vectors. A movement can be represented by a vector, here is an example:



The ball is moving right because there's a force in the direction where it is going.

Now let's imagine a ball being thrown in the air:



The ball is not moving to a single direction, but both up and right. The vector has a force, but it can be split in two forces, the X force and Y force. The Y force is the vertical component of the force and the X component is the horizontal component of the force.

So, the last image could be actually represented this way:



When we add Fx to Fy we have the F force in the previous image.

In Axe, to make acceleration work like in real lifes, we have 4 variables:

Code: [Select]
.X Position
0→X
.Y Position
0→Y
.X Acceleration
0→A
.Y Acceleration
0→B
Repeat getKey(15)
  ClrDraw
 
  .CODE
 
  .Sum acceleration to the positions of the sprites
  X+A→X
  Y+B→Y 
 
  .MORE CODE
 
End

This will make sprites moving much more realistic.

Yet again, note this tutorial is just to let you more comfortable with some concepts and acceleration and Physics in Axe. I recommend you to move on to more advanced tutorials such as Builderboy's and others which can be found in axe.omnimaga.org.

Thanks
I'd like to thank Builderboy for inspiring me to learn Physics by making awesome games.

Thanks squidgetx for a tutorial you wrote on Omnimaga.

Thanks all Omnimaga members for support!

Attached is a PDF version of this tutorial.

111
OmnomIRC Development / SpyBot Didn't Notice a Post
« on: May 15, 2011, 09:36:22 am »
Quote
[07:24:31] * \david\ ([email protected]) has joined #omnimaga
[07:24:31] * Netbot45 sets mode: +v \david\
[07:25:08] <+SpyBot45> (O) New post by Deep Thought in David's Z80 Assembly Questions http://omniurl.tk/8375/154755
[07:25:59] * +alberthro ([email protected]) Quit (Quit: [2nd] [On] *poof*)
[07:31:33] <+SpyBot45> (O) New post by Aichi in A·Map - Online Tilemap Editor http://omniurl.tk/7979/154757
[07:31:42] <+SpyBot45> (O) New post by broooom in Ndless 2.0 for TI-Nspire enter http://omniurl.tk/6770/154758
[07:32:41] <+SpyBot45> (O) New post by Deep Thought in Linux Applications http://omniurl.tk/8410/154759
[07:32:58] <+SpyBot45> (O) New post by Scout in A·Map - Online Tilemap Editor http://omniurl.tk/7979/154760
[07:33:35] <+\david\> Hum SpyBot just failed

The thing is I posted in my Z80 Assembly Questions topic at  09:32:08, you can see it here. So why didnt' SpyBot notify it? Was it down for a bit or something or is it worse?

112
Computer Programming / Opening a Website from C++
« on: May 14, 2011, 02:57:47 pm »
I was wondering how you open a website in C++. I need it to be cross-platform, no "windows.h" please.

Thanks :)

113
Computer Programming / C++ wxWidgets Text Editor
« on: May 13, 2011, 05:06:07 pm »
I was trying to make a text editor in C++ but I found no tutorials on the web. So I had to do some research on a few stuff to put it up and running. It is very simple, it is more of an example and has no Save/Open options, maybe I'll add those later.

If you want the full code you can find it here. In case you want a screenshot of it, here's one taken in Linux Mint (it is cross-platform don't worry)

Spoiler For Spoiler:


Here's the main part of the program, commented:

Code: [Select]
wxTextCtrl *textControl = new wxTextCtrl;                                  //Define the new textCtrl
   
    textControl = new wxTextCtrl(this, ID_TextBox,
      wxT(""), wxDefaultPosition, wxDefaultSize,
      wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr); //Creates a text box, with no text, id=ID_TextBox, it's multiline
     
    wxMenu *menuFile = new wxMenu;                                         //Create a new menu to be placed on a menu bar

    menuFile->Append( ID_About, _("&About...") );                          //Add the first option to the menu (will show up on top)
    menuFile->AppendSeparator();                                           //Add a separator, this is handy
    menuFile->Append( ID_Quit, _("E&xit") );                               //Add an option to the menu

    wxMenuBar *menuBar = new wxMenuBar;                                    //Create a new menu bar
    menuBar->Append( menuFile, _("&File") );                               //Append the file menu

    SetMenuBar( menuBar );                                                 //Defines the window menu bar to menuBar
   
    Maximize();                                                            //Maximizes the window

Attached is the source file.

114
ASM / David's Z80 Assembly Questions
« on: May 13, 2011, 03:38:10 pm »
I decided to create a topic to gather all my z80 asm questions since I have a few and I'm still learning.

First of all, I'd like you guys to know how advanced I am, this was my (best?) program:

Code: [Select]
.nolist 
#include "ti83plus.inc" 
.list 
   .org userMem-2 
   .db $BB,$6D 
Init: 
  B_CALL _ClrLCDFull 
   
  ld hl,0
  ld (curCol), hl
  ld hl,Welcome
  B_CALL _PutS

  B_CALL _GetKey 
   
  cp kEnter 
   
  jr z,Win 
   
  B_CALL _ClrLCDFull 

  ld hl,0 
  ld (curCol), hl
   
  ld hl,LoseTxt 
   
  B_CALL _PutS 
   
  B_CALL _GetKey 
  B_CALL _ClrLCDFull 
  ret 

LoseTxt: 
  .db "LOSE",0   
   
Win: 
  B_CALL _ClrLCDFull

  ld hl,0 
  ld (curCol), hl
   
  ld hl,WinTxt

  B_CALL _PutS
  B_CALL _GetKey
  B_CALL _ClrLCDFull
  ret
WinTxt:
  .db "WIN",0
Welcome:
  .db "Press ",$C1,"ENTER]",0

If you run it, it asks you to press [ENTER], if you do, you win, if you don't, well you lose The Game.

My first question is how to make Axe-like loops in Asm? In Axe, I'd do something like Repeat getKey(15). How would I do that in Assembly?

Code: [Select]
TitleScreen:
 ;Title Screen code
Loop:
 ;Code
 cp kClear
 jr z, TitleScreen
 jr Loop

I thought of this, but I can't test it right now. Thanks :D

<Edit>
I actually tried this and it looped forever, freezing my calc:

Code: [Select]
Start:
  cp kClear
  jr z, End
  jr Start
End:
  ret

I'm pretty sure I'm doing something wrong, but I'm a bit rusty at z80 asm.

115
Site Feedback and Questions / Appeal: tweet #omnimaga
« on: May 13, 2011, 10:04:30 am »
I have started using Twitter a few weeks back and when I tweet about my calculator projects or about the calculator community, I always tweet #omnimaga. So if I am saying my Mission Copter game is finished I would say "yay, finish Mission Copter #omnimaga #cemetech".

In this page you can see all tweets that had #omnimaga on them. There are not many of them, but I think that since some of us use Twitter, why not tweet #omnimaga Omnimaga is becoming very popular on Facebook and through gaming websites, also because of nDoom (tweets with nDoom on it here). So, I think people who want to know about #omnimaga could tweet and find some neat stuff.

So I turn this topic into an appeal, tweet #omnimaga so finding stuff about Omnimaga and calculators is easier on Twitter!

Thanks

116
Site Feedback and Questions / Changing OmnomIRC forum name
« on: May 12, 2011, 11:05:35 am »
The current name of OmnomIRC's subforum is "OmnomIRC Chat and SpyBot45 Suggestions & Bug Reports".

I think it's too big and it kind of enlarges the Latest Activity page, it kind of annoys me because it takes two lines in that page and I can see less stuff.

Could it be changed something shorter like "OmnomIRC and Spybot subforum" or "OmnomIRC and Omnimaga Channnel bots". I don't know, but I'd really, really like it. Thanks a lot!

117
General Calculator Help / TI Connect 8XP Files Comments
« on: May 10, 2011, 02:50:50 am »
Does TI Connect change the comment in a 8XP file?

118
I just checked the stats to try and find out what the record of most online users is and I think I found it, it's 78.

However, it is listed under "Users Online:", shouldn't it be, "Maximum Users Online" or something like that?

119
Miscellaneous / What the Finns need to know about Portugal
« on: May 07, 2011, 12:17:34 pm »
I found this awesome video following a campaign organized by a political party in Finland criticizing Portugal, so I thought I should post this to shut Finn's mouth.


120
Computer Programming / IRC Score Bot
« on: May 07, 2011, 08:57:50 am »
I made a score bot for IRC:

Code: [Select]
#!/usr/bin/env python

import datetime
import hashlib
import os
import random
import sys
import time
import urllib

from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor

class MyBot(irc.IRCClient):

    def _get_nickname(self):
        return self.factory.nickname

    nickname = property(_get_nickname)

    def signedOn(self):
        self.join(self.factory.channel)

    def joined(self, channel):
        print "*** Joined %s" % channel
        self.myDict = {}

    def privmsg(self, user, channel, msg):
        user = user.split('!')[0]
        if msg[len(msg)-2:] == "++":
            if msg.split('++')[0] == user:
                self.msg(channel,"You can't plus yourself")
                return

            try:
                self.myDict[msg.split('++')[0]] += 1
                print "+1 for %s" % user
                return
            except KeyError:
                self.myDict[msg.split('++')[0]] = 1
                print "The first +1 for %s" % user
                return

        if msg[len(msg)-2:] == "--":
            try:
                self.myDict[msg.split('--')[0]] = self.myDict[msg.split('--')[0]] - 1
                print "-1 for "+user
                return
            except:
                self.myDict[msg.split('--')[0]] = -1
                print "The first -1 for %s" % user
                return

        if msg.split()[0] == '!score':
            try:
                msgToDisplay = msg.split()[1] + ": " + str(self.myDict[msg.split()[1]])
                self.msg(channel,msgToDisplay)
                print "I answered to %s: %s" % (user,msgToDisplay)
                return
            except KeyError:
                self.msg(channel,"Non-existing member: %s" % msg.split()[1])
                print "Non-existing member: %s" % msg.split()[1]

class MyBotFactory(protocol.ClientFactory):
    protocol = MyBot

    def __init__(self, channel, nickname='scoreBot'):
        self.channel = channel
        self.nickname = nickname

    def clientConnectionLost(self, connector, reason):
        print "Lost connection (%s), reconnecting." % (reason,)
        connector.connect()

    def clientConnectionFailed(self, connector, reason):
        print "Could not connect: %s" % (reason,)

def main():
    network = 'irc.freenode.net'
    reactor.connectTCP(network, 6667, MyBotFactory('#python-forum'))
    reactor.run()

if __name__ == "__main__":
    main()

If you say stuff like:

Code: [Select]
netham45++

It will set netham45's score to what it was +1.

You can also do netham45--.

If you say !score netham45 it will say in a public message netham45's score.

It also won't let you ++ yourself.

The code is quite clean, but for variables' names. There is not a linking function yet (to link usernames). What do you think?

Pages: 1 ... 6 7 [8] 9 10 ... 20