Welcome, Guest

Author Topic: Coding  (Read 275986 times)

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #150 on: February 21, 2013, 04:47:45 PM »
gives rectangular coordinates that draw a circle
outputs at circle_draw.txt
« Last Edit: February 21, 2013, 05:00:37 PM by atomic7732 »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #151 on: February 25, 2013, 09:34:00 PM »
Code: [Select]
from Tkinter import *

value = " "

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()

self.button = Button(frame, text="delete", fg="red", command=self.delete)
self.button.grid(row=1, column=0)

self.w = Canvas(frame, height=300, width=600)
self.w.grid(row=0, column=0, columnspan=2)

self.hi_there = Button(frame, text="Submit", command=self.update)
self.hi_there.grid(row=1, column=1)

self.input = Entry(frame)
self.input.grid(row=2, column=0, columnspan=2)

def update(self):
value = self.input.get()

value = value.split(" ") #how to put in XXX YYY TEXT
#load positions from a text file and put it in a picture on the canvas
#instead of value[2] paste an image
#be able to pan and scale the picture in the canvas
#convert an input of lat long to x y on the canvas

id = self.w.create_text(value[0], value[1], text=value[2])
print "Generated text %d." % id

def delete(self):
self.w.delete(ALL)

root = Tk()

app = App(root)

root.mainloop()

for ircclient-making kips

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #152 on: February 26, 2013, 05:34:31 AM »
Tkinter?

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #153 on: February 26, 2013, 03:35:38 PM »
content of this message: http://pastebin.com/U99v45h0

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #154 on: February 26, 2013, 03:51:38 PM »
woah did you learn that by tutorials or by asking kip?

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #155 on: February 26, 2013, 04:06:03 PM »
/// dump http://ubuntuforums.org/showthread.php?t=1493702


#!/usr/bin/env python

import sys
import socket
import string

HOST="irc.freenode.net"
PORT=6667
NICK="asdf"
IDENT="asdf"
REALNAME="asdf"
CHAN="#asdf"
readbuffer=""

s=socket.socket( )
s.connect((HOST, PORT))
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
s.send("JOIN :%s\r\n" % CHAN)
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Hello There!"))
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "I am a bot"))

while 1:
    readbuffer=readbuffer+s.recv(1024)
    temp=string.split(readbuffer, "\n")
    readbuffer=temp.pop( )

    for line in temp:
        line=string.rstrip(line)
        line=string.split(line)

        if(line[0]=="PING"):
            s.send("PONG %s\r\n" % line[1])
« Last Edit: February 26, 2013, 06:09:42 PM by bong »

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #157 on: February 26, 2013, 04:21:41 PM »
woah did you learn that by tutorials or by asking kip?
I used a bot tutorial and used prior python knowledge and googling for the rest. Also I forgot it needs three imports which I will add when I get home.

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #158 on: February 26, 2013, 05:11:20 PM »
soket sys and string right?

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #159 on: February 26, 2013, 05:44:11 PM »
import socket
import random
import urllib2

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #160 on: February 26, 2013, 05:55:52 PM »
so do you make the stuff you're importing (modules, i tihnk) or is it already in python or do you download it off the internet?

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #161 on: February 26, 2013, 08:13:32 PM »
modules yes

some you have to download but the creator will tell you if you need to, most are built-in

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #162 on: February 28, 2013, 05:43:50 PM »
eu3 province generator

http://pastebin.com/aNMLARVK

it just prints out strings to the terminal and doesn't have a history section yet but i'll fix that

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #163 on: March 07, 2013, 03:21:19 PM »
alliance (which is a list) contains lists of tags. this script prints out all possible alliances between the members of each list.

Code: [Select]

alliances = []

alliance1 = ['tag','doo','poo']

alliance2 =['forever','alone']

alliances.append(alliance1)
alliances.append(alliance2)


def create_alliance(tag1,tag2):
    return 'alliance = {' +'\n'+'\t'+'first = ' + tag1 + '\n'+'\t'+'second = ' + tag2+'\n'+'\t'+'start_date = 1399.1.1'+'\n'+'\t'+'end_date = 1822.1.1'+'\n'+'}'

for list in alliances:
    alllist = []
    for x in xrange(0,len(list)):
        for y in xrange(0,len(list)):
            if x != y:
                temp = [x,y]
                temp.sort()
                alllist.append(tuple(temp))
    for element in alllist:
        print create_alliance(list[element[0]],list[element[1]])

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #164 on: March 07, 2013, 03:34:40 PM »
til if you have a list with type1, type2, and type3 objects and you do
for type1 in list:
    print list
it'll print all the items of any type

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #165 on: March 07, 2013, 04:10:57 PM »
write a

<title of program> for n00bs

guide

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #166 on: March 11, 2013, 04:37:06 PM »
a thing that i will use in the future

updated code for kips:

Code: [Select]
def char_replace(syl, fulltxt, rep):
j = 0
for i in fulltxt:
if fulltxt[j] == syl:
fulltxt[j] = rep
else:
pass
j += 1
return fulltxt

def conv_to_out(txt):
out = ""
j = 0
for i in txt:
out += i
return out

text = raw_input("Enter text: ")
text = text.split(' ')

#things to change
text = char_replace('ka', text, unichr(57344))
# most likely always the last 2
text = char_replace(' ', text, '')
text = char_replace('/', text, ' ')
text = conv_to_out(text)
text = text.encode('utf-8')

#print text

f = open('pony.txt','w+b')
f.write(text)
« Last Edit: March 11, 2013, 04:54:38 PM by atomic7732 »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #167 on: March 11, 2013, 06:03:37 PM »
wow 5 characters what a pro

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #168 on: March 12, 2013, 05:25:05 PM »
n-body 2d gravity simulator in the works

Code: [Select]
g = 6.67384
list = []

def calc_grav(m1, m2, r):
f = g*((m1*m2)/r**2)
return f

class object:
lx = 0
ly = 0
lr = 0
lt = 0
mass = 0
vx = 0
vy = 0
vr = 0
vt = 0
def __init__(self, x, y, r, t, m, vx, vy, vr, vt):
self.lx = x
self.ly = y
self.lr = r
self.lt = t
self.mass = m
self.vx = vx
self.vy = vy
self.vr = vr
self.vt = vt

#generate two test objects
sun = object(0.0, 0.0, 0.0, 0.0, 1000.0, 0.0, 0.0, 0.0, 0.0)
pl1 = object(1000.0, 0.0, 1000.0, 0.0, 10.0, 0.0, 40.0, 40.0, 90.0)
pl2 = object(2000.0, 0.0, 2000.0, 0.0, 15.0, 0.0, 15.0, 15.0, 90.0)

list.append(sun)
list.append(pl1)
list.append(pl2)

#calculate distance
#insert method thing here
d = sun.lx - pl1.lx #temporary

#calculate gravitational force
i = 0
combos = []
for o in list:
j = 0
for p in list:
# print "%s, %s" % (i, j)
if i >= j:
pass
else:
print calc_grav(o.mass, p.mass, d)
j += 1
i += 1

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #169 on: March 16, 2013, 03:41:21 PM »
sfdjkasl

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #170 on: March 16, 2013, 04:14:18 PM »
i spy redit

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #171 on: March 27, 2013, 06:39:19 AM »
damn i lost like 6 links to ircbots
now i have to look them up again

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #172 on: March 27, 2013, 06:46:04 AM »
what is my port

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #173 on: March 27, 2013, 07:21:49 AM »
help

while 1: # Be careful with these! it might send you to an infinite loop
  ircmsg = ircsock.recv(2048) # receive data from the server
  ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
  print(ircmsg) # Here we print what's coming from the server

  if ircmsg.find(":Hello "+ botnick) != -1: # If we can find "Hello Mybot" it will call the function hello()
    hello()

  if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
    ping()
   
   if data.find ( 'PING' ) != -1:
      irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
   if data.find ( '!kolok quit' ) != -1:
      irc.send ( 'PRIVMSG ##Universesandbox :Fine, if you dont want me\r\n' )
      irc.send ( 'QUIT\r\n' )

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #174 on: March 27, 2013, 07:42:23 AM »
the indents are spaces either indent with spaces or change them all to tabs

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #175 on: March 27, 2013, 07:48:23 AM »
so do i like tab after the colon or??

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #176 on: March 27, 2013, 08:04:07 AM »
everywhere there is an indent, remove it, and tab

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #177 on: March 28, 2013, 07:45:19 PM »
it's a prototype for god's sake!

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Python
« Reply #178 on: March 28, 2013, 07:51:37 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '102879'.

« Last Edit: March 22, 2021, 01:53:31 AM by FiahOwl »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #179 on: March 28, 2013, 09:42:03 PM »
wow that's amazing