Sorry for the downtime, welcome back!!

Creating KG-Chart for Mac

Forum and Craft Related Topics...
nintandrew
Rank 5 - Frog Mario
Rank 5 - Frog Mario
Posts: 209
Joined: Mon Jun 16, 2008 7:36 pm

Creating KG-Chart for Mac

Post by nintandrew »

Hello, I've been trying to learn objective-c (the language Mac and iPhone apps are written in) and then learn how to make apps for Mac/iPhone from tutorials on YouTube. Once I really start trying to make the program, I want to make a Mac based Cross-Stitching program that is Sprite Stitch themed, (I'm thinking of a name that includes "Sprite Stitch" somewhere in it, if it's okay with Johloh) but it will still turn any picture to stitches, not just sprites, and is free like KG-Chart. I'm still a long way off i think, but it is my goal. I also hope that I could use input from this board for what hex colors match DMC colors the best. I know there are pages that say it, but I think it would be cooler to use real people's input from here. Also, I don't know much about publishing an App, but I hope I can share it at no cost. (Maybe I can post the code for the program and give instructions on how to assemble it) If you want to learn Objective-C, there are great tutorials on YouTube by thenewboston on it and he also has a series for iPhone App development.

Back to learning, later. :cool:
Eyup

User avatar
FouFou
Rank 3 - Star Mario
Rank 3 - Star Mario
Posts: 51
Joined: Sat May 22, 2010 6:39 pm

Re: Creating KG-Chart for Mac

Post by FouFou »

Sounds like an ambitious project! I wish you luck with that!
I found this site that converts RBG to DMC values, which should probably help.
http://www.csh.rit.edu/~vance/pages/color.html

nintandrew
Rank 5 - Frog Mario
Rank 5 - Frog Mario
Posts: 209
Joined: Mon Jun 16, 2008 7:36 pm

Re: Creating KG-Chart for Mac

Post by nintandrew »

Thanks FouFou for that link. I just about finished the first book on programing in c on the Mac and will soon be moving to objective-C, but not before finishing a program in C. I'm not done, and not totally sure what I want it to do, but I think it should let you enter in what colors you have and tell you the name of the color and if your have them wrapped up or not (like on a bobbin). So I had a question that I would like the opinion of SpriteStitch for. I think that there should be a universal name for each color that should not differ from person to person (if there all ready aren't any, I just read that the names people use change and are not reliable.) so I was wondering if anyone would object this list:

http://www.dmc.com/mjRS/1/doc/US_colord ... bfloss.pdf

This info will help me down the line as well.

Also, since this program is written in C, it should be able to compile on a PC, and I will put the code on here if anyone wants to use it for themselves. (You do need a compiler, but there are free ones on the web.) Thanks.
Eyup

User avatar
StitchPlease
Rank 7 - Kuribo Mario
Rank 7 - Kuribo Mario
Posts: 401
Joined: Fri Oct 23, 2009 2:26 pm
Contact:

Re: Creating KG-Chart for Mac

Post by StitchPlease »

I would think because that list is made by DMC those would be the official color names anyway, but I think it's a good idea. Also the idea about making a database of all the different colors you currently have would be an awesome idea. I was trying to work on something like that, but I'm no programmer. :swoon: Good luck, and I'm looking forward to your program!

User avatar
FouFou
Rank 3 - Star Mario
Rank 3 - Star Mario
Posts: 51
Joined: Sat May 22, 2010 6:39 pm

Re: Creating KG-Chart for Mac

Post by FouFou »

I will say that there isn't a DMC color for every RBG color you'll run into, so you'll probably need to come up with a way of rounding the RBG color - which you should be able to do in C if you're looking at the image pixel by pixel.

I would suggest using something like ImageMagic for resizing images. I think ImageMagic can also access pixels by pixels too.

User avatar
johloh
Site Admin
Posts: 1997
Joined: Fri Apr 11, 2008 4:33 pm
Contact:

Re: Creating KG-Chart for Mac

Post by johloh »

nintandrew wrote:I'm thinking of a name that includes "Sprite Stitch" somewhere in it, if it's okay with Johloh
I'm not opposed to it, I'd have to see a finished product before I gave the official go ahead...sounds like quite an ambitious project, I'm interested to see how it turns out!
Image "I can't drive, so I'm gonna walk all over you!"

nintandrew
Rank 5 - Frog Mario
Rank 5 - Frog Mario
Posts: 209
Joined: Mon Jun 16, 2008 7:36 pm

Re: Creating KG-Chart for Mac

Post by nintandrew »

Okay, so I got This program done. It's written in C, so I think it would compile on Windows. Unfortunately, you need a compiler, but there are free ones online that will work. Also, there are four documents you need to make this work, but their extension is not allowed to be attached here (there is no extension, they're just documents) so if you want to use this, I can email them. If you have a Mac, you probably have a program called Xcode, which is supposed to come with OSX, otherwise it's free to download from apple's site (you have to make a developer account, but that's free as well) and I can email you the entire folder with the documents and code and all that and you can compile it in Xcode. As far as I know, it's working on my machine, but I haven't actually started entering my floss yet, I've just been testing. If I can hear that one other person was able to use this, I can move on to objective-C, which is one step closer to making what I want.
Thanks.

This is the code for the program, you need to copy it into your compiler if running on Windows, otherwise I can send you the Xcode project.
Spoiler

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


char code[454][7];
char name [454][26];
char haveslist [454][11];
char wrapped [454][15];
char input [25];
char onbobbin[10];
char notonbobbin[14];
char all[4];
char have[6];
char donthave[12];
int i;
int f;
int h;
int r;
int len;
int arrays (int f, int *hPtr);
void edit (int i);

int main (int argc, const char * argv[]) {
	int h;
	for (r=0; r=100000; r++) {
		fpurge(stdin);
		
	char onbobbin[] = "on bobbin";
	char notonbobbin[] = "not on bobbin";
	char all[] = "all";
	char have[] = "have";
	char donthave[] = "don't have";
	
		if (r!=0) {
		printf("\n-----------\n");
		}
	printf("\nEnter code, name of color, \"on bobbin\", \"not on bobbin\", \"have\", \"don't have\" or \"all\" (q=quit):\n ");
	fgets(input, 25, stdin);
	len = strlen(input);
	input[len - 1] = '\0';
		
		if (*input == 'q') {
			printf("Quitting.");
			return (0);
		}
		else if (*input == '\0'){
			f = 6;
		}
		
	else if (strcmp(input, onbobbin) == 0) {
		f=1;
	}
	
	else if (strcmp(input, notonbobbin) == 0) {
		f=2;
	}
	else if (strcmp(input, have) == 0) {
		f=3;
	}
	else if (strcmp(input, donthave) == 0) {
		f=4;
	}
	else if (strcmp(input, all) == 0) {
		f=5;
	}
	else {f=0;}
		
		arrays(f, &h);
				
		if (h!=1 && f==0) {
		edit(i);

	}
		else if (h == 1 && f==0) {
			printf("Invalid entry.\n");
		}
		
	}
	
	printf("-----------\n");
	
    return 0;
	
}

int arrays (int f, int *hPtr) {
	char compare5[] = "don't have";
		
FILE *namelist = fopen("../../namelist", "r+");
FILE *codelist = fopen("../../codelist", "r+");
FILE *wrappedlist = fopen("../../wrapped", "r+");
FILE *havelist = fopen("../../havelist", "r+");


fseek(namelist, 0, SEEK_SET);
fseek(codelist, 0, SEEK_SET);
fseek(wrappedlist, 0, SEEK_SET);
fseek(havelist, 0, SEEK_SET);

	

for (i=0; i<=453; i++) {
	
	fgets(wrapped[i], 15, wrappedlist);
	fgets(code[i], 7, codelist);
	fgets(name[i], 26, namelist);
	fgets(haveslist[i], 12, havelist);

	len = strlen(code[i]);
	code[i][len - 1] = '\0';
	len = strlen(name[i]);
	name[i][len - 1] = '\0';
	len = strlen(wrapped[i]);
	wrapped[i][len - 1] = '\0';
	len = strlen(haveslist[i]);
	haveslist[i][len - 1] = '\0';
	if (f==1 && (strncmp(input, wrapped[i],1) == 0) && i!=454) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
			printf("%s, %s\n-----------\n%s\n",code[i],name[i],wrapped[i]);
	}
	else if (f==1 && (strncmp(input, wrapped[i],1) == 0) && i==454) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],wrapped[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=0;
		return(i,f);
	}
	else if (f==2 && (strcmp(input, wrapped[i]) == 0) && i!=454){
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
	}
	else if (f==2 && (strcmp(input, wrapped[i]) == 0) && i==454){
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=0;
		return(i, f);
	}
	
	else if (f==0 && (strcasecmp(input, code[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) != 0)) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		f=0;
		*hPtr=0;
		return(i, f);
	}
	else if (f==0 && (strcasecmp(input, code[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) == 0)) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		f=0;
		*hPtr=0;
		return(i, f);
	}
	else if (f==0 && (strcasecmp(input, name[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) != 0)) {
		printf("\n");
		if (i>=3) {
		printf("#");
	}
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		f=0;
		*hPtr=0;
		return(i, f);
	}
	else if (f==0 && (strcasecmp(input, name[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) == 0)) {
		printf("\n");
		if (i>=3) {
		printf("#");
		 }
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		f=0;
		*hPtr=0;
		return(i, f);
		}	
			 
	else if(f==5 && i!=454 && strncmp(haveslist[i], compare5, (size_t)1)!=0){
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
	}
	else if(f==5 && i!=454 && (strncmp(haveslist[i], compare5, (size_t)1)==0)){
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
	}
	
	
	else if (f==3 && (strncmp(input, haveslist[i], (size_t)1)==0) && i!= 454) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
		}
	else if (f==3 && (strncmp(input, haveslist[i], (size_t)1)==0) && i== 454) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=0;
		return(i, f);
	}
	else if (f==4 && (strcmp(input, haveslist[i])==0) && i != 454) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
	}
	else if (f==4 && (strcmp(input, haveslist[i])==0) && i == 454) {
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=0;
		return(i, f);
	}
	else if (f==5 && i==454 && (strncmp(haveslist[i], compare5, (size_t)1)!=0)){
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		
		printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=0;
		return(i, f);
	}
	else if (f==5 && i==454 && (strncmp(haveslist[i], compare5, (size_t)1)==0)){
		printf("\n");
		if (i>=3) {
			printf("#");
		}
		
		printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=0;
		return(i, f);
	}
	else if ((i==453) && ((strcasecmp(input, code[i])!=0)||(strcmp(input, name[i])!=0))){
		fclose(wrappedlist);
		fclose(namelist);
		fclose(codelist);
		fclose(havelist);
		*hPtr=1;
		return(i, f);
	}
}

	return (0);
}
	
			

void edit (int i){
	char ans[5];
	char ans2[5];
	char yes[] = "yes";
	char no[] = "no";
	char compare1[] = "on bobbin\b\b\b\b";
	char compare2[] = "not on bobbin";
	char compare3[] = "have\b\b\b\b\b\b";
	char compare4[] = "don't have";
	char wrapedit[] = "wrapped";
	char haveedit[] = "have";
	char editing[9];
		
	FILE *wrappedlist = fopen("../../wrapped", "r+");
	FILE *havelist = fopen("../../havelist", "r+");
	
	fseek(wrappedlist, i*14, SEEK_SET);
	fseek(havelist, i*11, SEEK_SET);
		
	fpurge(stdin);
	
	printf("Edit? (\"yes\"/\"no\")\n");
	fgets(ans, 5, stdin);
	len = strlen(ans);
	ans[len - 1] = 0;	
	
	if ((strcmp(ans, yes) == 0) && (strncmp(haveslist[i], compare4, (size_t)1) == 0)) {
		fpurge(stdin);
		
		printf("Switch \"don't have\" to \"have\"? (\"yes\"/\"no\")\n");
		fgets(ans2, 5, stdin);
		len = strlen(ans2);
		ans2[len -1] = 0;
		
		if (strcmp(ans2, yes)==0) {
			printf("Switched \"don't have\" to \"have\".");
			fputs(compare3, havelist);
			fclose(wrappedlist);
			fclose(havelist);
			return;
		}
		else if(strcmp(ans2, no)==0){
			
			printf("Not switching \"don't have\" to \"have\".");
			fclose(wrappedlist);
			fclose(havelist);
			return;
		}

		printf("Invalid entry1.");
			fclose(wrappedlist);
			fclose(havelist);
		return;
	
	}
	
	else if ((strcmp(ans, yes)==0) && (strncmp(haveslist[i], compare3, (size_t)1) == 0)) {
		
		printf("Edit \"have\" or \"wrapped\"?\n");
		fpurge(stdin);
		fgets(editing, 9, stdin);
		len = strlen(editing);
		editing[len - 1] = 0;
		
		if (strcmp(editing, wrapedit)==0) {
		
		if (strncmp(wrapped[i], compare1, (size_t)1)==0) {
			
			printf("Switch \"on bobbin\" to \"not on bobbin\"? (\"yes\"/\"no\")\n");
			fgets(ans2, 5, stdin);
			len = strlen(ans2);
			ans2[len - 1] = 0;
			
			if (strcmp(ans2, yes)==0) {
				printf("Switched \"on bobbin\" to \"not on bobbin\".");
				fputs(compare2, wrappedlist);
				fclose(wrappedlist);
				fclose(havelist);
				return;
			}
			else if(strcmp(ans2, no)==0){
				
				printf("Not switching \"on bobbin\" to \"not on bobbin\".");
				fclose(wrappedlist);
				fclose(havelist);
				return;
			}
			printf("Invalid entry2.");
			fclose(wrappedlist);
			fclose(havelist);
			return;
		}
			else if(strncmp(wrapped[i], compare2, (size_t)1)==0){
				
				
				printf("Switch \"not on bobbin\" to \"on bobbin\"? (\"yes\"/\"no\")\n");
				fgets(ans2, 5, stdin);
				len = strlen(ans2);
				ans2[len - 1] = 0;
				if (strcmp(ans2, yes)==0) {
					printf("Switched \"not on bobbin\" to \"on bobbin\".");
					fwrite(compare1, (size_t)strlen(compare1), 1, wrappedlist);
					fclose(wrappedlist);
					fclose(havelist);
					return;
				}
				else if(strcmp(ans2, no)==0){
					printf("Not switching \"not on bobbin\" to \"on bobbin\".");
					fclose(wrappedlist);
					fclose(havelist);
					return;
		}
				
				printf("Invalid entry.");
				fclose(wrappedlist);
				fclose(havelist);
				return;
		}
			
			printf("You don't want to edit wrapped apparently.");
			fclose(wrappedlist);
			fclose(havelist);
			return;
		}
		else if(strcmp(editing, haveedit)==0){
		
			if (strncmp(haveslist[i], compare3, 1) == 0){
				
				printf("Switch \"have\" to \"don't have\"? (\"yes\"/\"no\")\n");
				fgets(ans2, 5, stdin);
				len = strlen(ans2);
				ans2[len - 1] = 0;
				if (strcmp(ans2, yes)==0) {
					printf("Switched \"have\" to \"don't have\".");
					fputs(compare2, wrappedlist);
					fputs(compare4, havelist);
					fclose(wrappedlist);
					fclose(havelist);
					return;
				}
				else if(strcmp(ans2, no)==0){
					printf("Not switching \"have\" to \"don't have\".");
					fclose(wrappedlist);
					fclose(havelist);
					return;
				}
				printf("Invalid entry.");
				fclose(wrappedlist);
				fclose(havelist);
				return;
			}
			else if(strncmp(haveslist[i], compare4, 1)==0){
				
				printf("Switch \"don't have\" to \"have\"? (\"yes\"/\"no\")\n");
				fgets(ans2, 5, stdin);
				if (strcmp(ans2, yes)==0) {
					printf("Switched \"don't have\" to \"have\".");
					fputs(compare3, havelist);
					fclose(wrappedlist);
					fclose(havelist);
					return;
				}
				else if(strcmp(ans2, no)==0){
					printf("Not switching \"don't have\" to \"have\".");
					fclose(wrappedlist);
					fclose(havelist);
					return;				
			}
		}
			printf("Invalid entry.");
			fclose(wrappedlist);
			fclose(havelist);
			return;
		}
			printf("Invalid Entry.");
		
		fclose(wrappedlist);
		fclose(havelist);
		
		return;
	}
	else if(strcmp(ans, no)==0){
		printf("Not editing.");
		fclose(wrappedlist);
		fclose(havelist);
		return;
	}
	printf("Invalid entry.");
	fclose(havelist);
	fclose(wrappedlist);
	return;
}
(@Johloh: It's still a long way off, but I'll show you when it's done. :grin: )
Eyup

User avatar
FouFou
Rank 3 - Star Mario
Rank 3 - Star Mario
Posts: 51
Joined: Sat May 22, 2010 6:39 pm

Re: Creating KG-Chart for Mac

Post by FouFou »

Could you include the files if they were written as a .txt file? Or if you zipped everything together?

nintandrew
Rank 5 - Frog Mario
Rank 5 - Frog Mario
Posts: 209
Joined: Mon Jun 16, 2008 7:36 pm

Re: Creating KG-Chart for Mac

Post by nintandrew »

Okay, it seems to have worked. You need to place these files in the same folder and remove the .txt extension.
Attachments
namelist.txt
(6.15 KiB) Downloaded 347 times
codelist.txt
(1.92 KiB) Downloaded 302 times
havelist.txt
(4.88 KiB) Downloaded 323 times
wrapped.txt
(6.21 KiB) Downloaded 334 times
Eyup

User avatar
FouFou
Rank 3 - Star Mario
Rank 3 - Star Mario
Posts: 51
Joined: Sat May 22, 2010 6:39 pm

Re: Creating KG-Chart for Mac

Post by FouFou »

Ok, I'm running this from terminal on my mac. Once I compile, the program starts running up until this point:
Enter code, name of color, "on bobbin", "not on bobbin", "have", "don't have" or "all" (q=quit):
I'm attempting to figure out how you want data added here, since pretty much anything I've typed has resulted in a bus error. I haven't looked closely at the code yet, but if you want I can try to run some diagnosis to figure out what is causing the bus error.

Post Reply